1 / 62

CIS 199 Final Review

CIS 199 Final Review. Classes. Reference type NOT a value type! Can only inherit from ONE base class. Properties. Class member Holds a piece of data, information within an object Accessors: get, set Can use auto-implemented when validation is not required

twitty
Download Presentation

CIS 199 Final Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 199 Final Review

  2. Classes • Reference type • NOT a value type! • Can only inherit from ONE base class

  3. Properties • Class member • Holds a piece of data, information within an object • Accessors: get, set • Can use auto-implemented when validation is not required • If need validation, must create own backing field (instance variable) and write own get and set accessors • Read-only property – only has get, no set (no public set, at least) • Controllable scope

  4. readonly • Can make an instance variable readonly • Initial value will be established in constructor • After value is set, it may not change again

  5. Inheritance • Extend, Expand an existing class • Specialization • Generalization • “All students are a person, but not all persons are a student” • Derived class “IS-A” base class • Student IS-A Person • Even if no base class is specified, one will be provided • Object • This is where method ToString was originally defined

  6. Protected vs Private What is the difference between Protected vs Private?

  7. Protected vs Private • Private-The type or member can be accessed only by code in the same class • Protected -The type or member can be accessed only by code in the same class, or in a class that is derived from that class.

  8. Polymorphism • Complicated Concept • An object’s ability to take on, become different forms • Child classes take on properties of parent • Objects may be treated as base class • Students can be treated as a person • Keywords of note: • “override” – New implementation of a member in a child class that is inherited from base class • “virtual” – Class member that may be overridden in a child class • “abstract” – Missing or incomplete member implementation. MUST be implemented by child classes // More a 200 concept

  9. Abstract Classes • Generic class • Provides some members, some information • CAN NOT be created directly • Meaning direct instantiation is illegal • Serves as a common “base” for related objects

  10. Test 01 Material

  11. Computer Hardware • Central Processing Unit (CPU) • Brains • Operations performed here • Main Memory (RAM) • Scratchpad • Work area for programs, process, temporary data • Secondary Storage • Hard drive • Flash drive • CD, DVD

  12. Input, Output Devices • Input • Takes data IN • Keyboard, Mouse, Game Controller, Microphone • Output • Pushes, places data OUT • Display, Speakers, Printers

  13. Programs and Digital Data • Programs • Operating Systems. Microsoft Office, Web browsers • Instructions read by CPU and processed • Digital Data • 1’s • 0’s • …forms binary (base 2)

  14. Built-In Types

  15. Formatted Output • Placeholders • Letter codes – C, D, F, P • Precision • Field width Console.WriteLine(“x = {0,-10:F2}”, x);

  16. Operators • ++, -- • Postfix vs Prefix int x = 5; int y; y = x++; vs y = ++x; • Shorthand operators • +=, -= • Integer division 1/2 == 0 1.0 / 2.0 == 0.5 10 / 3 == 3, 10 % 3 == 1 • = vs ==

  17. Properties • Exposed “Variables” or accessible values of an object • Can have access controlled via scope modifiers • When thinking of properties: Values and definitions • “get” – Code to run before returning a value • “set” – Code to run before updating a value • Can be used for validation and other processing actions • “value” is a keyword in “set”

  18. Methods • Actions, code to be executed • May return a value, may take value (not required) • Can be controlled via scope keywords • Can be static • // Different example

  19. Scope • “private” – Can only be accessed by the class, object itself • “protected” – Can only be accessed by the class, object, or any child classes, objects • “public” – Available access for all

  20. Named Constants • AVOID MAGIC NUMBERS! • Allows for reference across similar scope • Change once, changes everywhere • // ALL CAPS

  21. Conditional Logic • if(expression) • If ‘expression’ is true • If not true, skipped • else if(expression) • Can be used to ‘chain’ conditions • Code runs if ‘expression’ is true • else • Code to execute if ‘expression’ false • Statements can be nested

  22. Relational Operators • >Greater than • <Less than • >=Greater than OR equal to • <=Less than OR equal to • ==Equal to • !=NOT equal to • X > Y • X >= Y • X < Y • X <= Y • X == Y • X != Y

  23. Operator Precedence • (Highest) • ++, --, ! • * / % • + - • < > <= >= • == != • && • || • = *= /= %= += -= • (Lowest)

  24. Comparing Strings, Chars • You can use • ==, != • You cannot use • >, >=, <, <= • You SHOULD use: • String.Compare(s1, s2) • s1 > s2 • Returns positive Number • s1 = s2 • Returns zero • s1 < s2 • Returns negative number • Compares the unicode value of EACH character

  25. Test 02 Material

  26. Basic GUI Example • Textboxes, labels, buttons, checkboxes, radiobuttons, panels, groupbox • Event handler

  27. Loops • for • “For a given value X, while X is true, modify X…” • while • “While X is true…” • do – while • “Do these tasks, while X is true…” • foreach • “For every X in this set of Y do the following…”

  28. for Example

  29. while Example

  30. do while Example

  31. foreach Example

  32. Key Loop Details • Loops are NOT guaranteed to execute at least once! • …only exception is ‘do while’ • Pretest vs posttest, or entry vs exit test • ‘for’ loops require a variable, condition, and ‘step’ instruction • ‘while’, ‘do while’ loops require a boolean expression • ‘foreach’ loops require a collection of items • Arrays • Indefinite repetition – sequential search, sentinel control, validation loop

  33. Nested loops Output

  34. Methods • Actions, code to be executed • May return a value, may take value (not required) • Can be controlled via scope keywords • Can be static

  35. Methods & Modularizing Your Code • Methods • Break out ‘steps’ • Easier to test • Easier to visualize • Top Down Design

  36. Arrays

  37. Arrays

  38. Sample Questions onBlackboard Wiki

  39. What does ‘WYSIWYG’ stand for? • What • You • See • Is • What • You • Get

  40. What is the difference between a high-level and a low-level language? • Low-Level • Little to no ‘abstraction’ from the hardware or computer • “Close to the hardware” • Simple, but Difficult to use • Machine code, assembly, C (in some cases) • High-Level • Very strong ‘abstraction’ from the hardware or computer • “Far from the hardware” • Easier to use, abstraction adds complexity • C++, Java, C#, Python

  41. How is the lifetime of a FIELD different from a lifetime of LOCAL variable? • Fields are members of their containing type • Fields can be used everywhere with appropriate scope • Local variables can be used only in their “local” environment

  42. What two things does a variable declaration specify about a variable? • Type • Identifier TYPE IDENTIFIER

  43. Describe ‘&&’ and ‘||’ and how they work. • && (AND) • Returns true if conditions are ALL true • “If you do well on the test AND the quiz, you will earn a great grade!” • || (OR) • Returns true if ANY conditions are true • “You can run a mile OR walk two miles (possible do both!)” • Both short circuit

  44. Why is ‘TryParse’ more effective than ‘Parse’? • Less code • No try / catch required

  45. What is the difference between a SIGNED an UNSIGNED int?

More Related