CIS 199 Final Review. New Material Structures Value type NOT a reference type! Used to...

70
CIS 199 Final Review

Transcript of CIS 199 Final Review. New Material Structures Value type NOT a reference type! Used to...

Page 1: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

CIS 199 Final Review

Page 2: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

New Material

Page 3: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Structures Value type

NOT a reference type!

Used to encapsulate small groups of related variables

Page 4: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Classes Reference type

NOT a value type!

Like a structure, but far more sophisticated, modern Can only inherit from ONE base class Can inherit from MANY interfaces

Page 5: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 6: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Properties Class member Holds a piece of data, information within an object Accessors: get, set, Controllable scope

Page 7: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 8: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Inheritance Extend, Expand an existing class Specialization Generalization “All students are a person, but not all persons are a student”

Page 9: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 10: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 11: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 12: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 13: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 14: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Test 01 Material

Page 15: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 16: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Input, Output Devices Input

Takes data IN Keyboard, Mouse, Game Controller, Microphone

Output Pushes, places data OUT Display, Speakers, Printers

Page 17: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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)

Page 18: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Built-In Types

Page 19: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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”

Page 20: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 21: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 22: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 23: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Named Constants AVOID MAGIC NUMBERS! Allows for reference across similar scope Change once, changes everywhere

Page 24: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 25: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 26: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Detailed from:http://msdn.microsoft.com/en-us/library/2bxt6kc4%28v=vs.100%29.aspx

Page 27: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Comparing Strings 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

Page 28: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Exceptions andException Handling Exceptions are…

“Exceptional” events Unexpected events, errors during runtime Unhandled exceptions? Stack trace and application death

Handled with try/catch/finally blocks Try block “attempts” to run the code in question Catch block handles the exception(s) that may occur Finally block, optional, always executes

Page 29: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 30: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.
Page 31: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Test 02 Material

Page 32: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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…”

Page 33: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

for Example

Page 34: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

while Example

Page 35: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

do while Example

Page 36: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

foreach Example

Page 37: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Key Loop Details Loops are NOT guaranteed to execute at least once!

…only exception is ‘do while’

‘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 Lists Generic Collections

Page 38: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Files OpenFileDialog

Used to load file from location

SaveFileDialog Used to select file save location

BOTH very User friendly!

Page 39: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

OpenFileDialog

Page 40: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

OpenFileDialog

Page 41: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

SaveFileDialog

Page 42: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

SaveFileDialog

Page 43: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Random Numbers in C# Provided from: System.Random Is ONLY pseudo-random

Produces a finite set of values with equal probability Not truly random, follows a mathematical algorithm

Created with OR without seed value Common methods used:

Next() Next(int) Next(int, int) NextDouble()

Page 44: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Creating and using aRandom Object

Page 45: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Usage & Expected Resultsof Random Methods

Page 46: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 47: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Methods &Modularizing Your Code Methods

Break out ‘steps’ Easier to test Easier to visualize

Page 48: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Methods &Modularizing Your CodeExample

Page 49: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Arrays

Page 50: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Arrays

Page 51: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Sample Questions fromBlackboard Wiki

Page 52: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 53: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 54: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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

Page 55: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What two things does a variable declaration specify about a variable? Type Identifier

TYPE IDENTIFIER

Page 56: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

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!)”

Page 57: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Why is ‘TryParse’ more effective than ‘Parse’?

Less code No try / catch required

Page 58: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What is the difference between a SIGNED an UNSIGNED int?

Page 59: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What is the difference between syntax errors and logic errors? Syntax Errors – Errors that prevent compilation or other

factors that prevent successful compilation striing myString = string.Empty; // Won’t compile, syntax error

Logic Errors – Errors that occur during runtime, such as incorrect comparison or other unexpected behavior If(grade > 60) { Code if grade is F } // Incorrect operator used

Page 60: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What are the “Five logical units”? CPU – Processing, instructions Memory – Scratch pad, working space (Temporary) Secondary Storage – Hard drives, storage (Long term) Input – Keyboards, Mice, Controllers Output – Monitors, Speakers, Printers

Page 61: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Explicit type conversion? Why and how? Variables must be used for a single type never change Move from one type to another, must cast EXPLICIT cast / type conversion

Aware of information loss

Page 62: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Write a code fragment that will display “Good Job” when int variable score is 80 or more, “OK” when score is 70 – 79, and “Needs Work” for any score under 70.

Page 63: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Write a code fragment that will apply a 10% discount to the value in double variable total when int variable numItems is 5 or more and int variable zone is 1, 3 or 5.

Page 64: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

The ‘switch’ statement can replace nested if/else. But under what conditions? When matching on a specific…

Value Type Enumeration …other data

Page 65: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What does a ‘break’ statement do in a loop? It stops (BREAKS) loop execution Code continues, no further loop iterations

Page 66: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What does a ‘continue’ statement do in a loop? Goes to the next iteration CONTINUES loop execution, by skipping current iteration

Page 67: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What are preconditions and postconditions for a method? PRECONDITIONS

Conditions that MUST be TRUE before method execution

POSTCONDITIONS Conditions that WILL be TRUE after method execution

Page 68: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

What is the difference between a void method and a value-returning method? VOID Method

Returns nothing! …a void return.

Value-Returning Returns a value! …that’s not a void return.

Page 69: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

Compare and contrast the use of pass by value against pass by reference, using key word ref versus pass by reference using keyword out. Pass by Value

Passes a copy of the value Not the object itself

Pass by Reference Passes the actual object itself

‘ref’ Causes a pass by reference on a variable

‘out’ Is used to reference a variable that the method will update

Page 70: CIS 199 Final Review. New Material Structures  Value type  NOT a reference type!  Used to encapsulate small groups of related variables.

How can REACH further help you today? Ask Questions Now!

Need to see an Example? Need to see a concept again?