Top Banner
CIS-166 Final CIS-166 Final Open book, open notes, open computer Open book, open notes, open computer 100 points 100 points True/false, multiple choice, fill- True/false, multiple choice, fill- in, short answer in, short answer Emphasis on material since midterm Emphasis on material since midterm
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cis166 final review c#

CIS-166 FinalCIS-166 Final

Open book, open notes, open computerOpen book, open notes, open computer 100 points100 points True/false, multiple choice, fill-in, short answerTrue/false, multiple choice, fill-in, short answer Emphasis on material since midtermEmphasis on material since midterm

Page 2: Cis166 final review c#

ArraysArrays

List or series of values all referenced by the List or series of values all referenced by the same namesame name

Use an array to keep a series of variables for Use an array to keep a series of variables for later processing such as later processing such as – ReorderingReordering– CalculatingCalculating– PrintingPrinting

Page 3: Cis166 final review c#

Array TermsArray Terms

ElementElement– Individual item in the arrayIndividual item in the array

Index (or subscript)Index (or subscript)– Zero based Zero based number used to reference the number used to reference the

specific elements in the arrayspecific elements in the array– Must be an integerMust be an integer

BoundariesBoundaries– Lower Subscript, 0 by defaultLower Subscript, 0 by default– Upper SubscriptUpper Subscript

Page 4: Cis166 final review c#

Simple Array ExampleSimple Array Example

studentNames Array(0)(1)(2)(3)(4)(5)(6)(7)(8)(9)

Janet BakerGeorge LeeSue LiSamuel HoosierSandra WeeksWilliam MacyAndy HarrisonKen FordDenny FranksShawn James

Page 5: Cis166 final review c#

Dim Statement for ArraysDim Statement for ArraysDefault ValuesDefault Values

string[] string[] strNamestrName = string[4] = string[4]Results in an array of 4 elements:Results in an array of 4 elements:

strName(0), strName(1), strName(0), strName(1),

strName(2), strName(3)strName(2), strName(3)

decimal[] decimal[] decBalancedecBalance= new decimal[100]= new decimal[100]Results in an array of 100 elements:Results in an array of 100 elements:

decBalance(0), . . . , decBalance(99)decBalance(0), . . . , decBalance(99)

Page 6: Cis166 final review c#

Dim Statement for ArraysDim Statement for ArraysAssigned ValuesAssigned Values

string[] string[] departmentsdepartments = {"ACT", "MKT", "HR"} = {"ACT", "MKT", "HR"}

Results in an array with 3 elements, each with a value, Results in an array with 3 elements, each with a value, departments[0] is “ACT”departments[0] is “ACT”

Integer[]Integer[] intActCodeintActCode = {10, 20, 30, 40} = {10, 20, 30, 40}

Results in an array with 4 elements, each with a number Results in an array with 4 elements, each with a number storedstored

Page 7: Cis166 final review c#

Referencing Array ElementsReferencing Array Elements

Use the Index(es) of the ElementUse the Index(es) of the Element

strName(row)(0)(1)(2)(3)

Sam SmithJill CreechPaul FryRich Wells

strName[0] : "Sam Smith"strName[1] : "Jill Creech"strName[2] : "Paul Fry"strName[3] : "Rich Wells"

Page 8: Cis166 final review c#

Working with ArraysWorking with Arrays

Use Loops to reference each element in the Use Loops to reference each element in the arrayarray– For / Next For / Next – For Each / NextFor Each / Next

Page 9: Cis166 final review c#

For Next LoopFor Next Loop

Assume strNames[10] already declaredAssume strNames[10] already declared

integer intCounter, intEndinteger intCounter, intEnd

intEnd = strNames.GetUpperBound(0)intEnd = strNames.GetUpperBound(0)

For (intCounter = 0; intcounter<=intEnd; intCounter++)For (intCounter = 0; intcounter<=intEnd; intCounter++)

{Console.Writeline(strNames[intCounter])}{Console.Writeline(strNames[intCounter])}

Page 10: Cis166 final review c#

For Each LoopFor Each Loop

Assume strNames[10] already declaredAssume strNames[10] already declared

foreach (string Item in strNames)foreach (string Item in strNames)

{Console.Writeline(Item)]{Console.Writeline(Item)]

Page 11: Cis166 final review c#

Object Terminology ReviewObject Terminology Review

Object - like a noun, a thingObject - like a noun, a thing– An object is based on a An object is based on a classclass

Properties - like an adjective, characteristics Properties - like an adjective, characteristics of objectof object

Methods - like a verb, an action or behavior, Methods - like a verb, an action or behavior, something the object can dosomething the object can do

Events - object response to user action or Events - object response to user action or other eventsother events

Page 12: Cis166 final review c#

PolymorphismPolymorphism

Overloading: Argument type determines which Overloading: Argument type determines which version of a method is usedversion of a method is used– Example: MessageBox.Show methodExample: MessageBox.Show method

Overriding: Refers to a class that has the same Overriding: Refers to a class that has the same method name as its base classmethod name as its base class– Method in subclass takes precedenceMethod in subclass takes precedence

Page 13: Cis166 final review c#

Specifying a NamespaceSpecifying a Namespace

Namespaces are used in .Net to organize Namespaces are used in .Net to organize classes and source filesclasses and source files

When referring to classes in a different When referring to classes in a different namespacenamespace– Write out the entire namespaceWrite out the entire namespace– Add an Imports Statement to include the namespaceAdd an Imports Statement to include the namespace

Using System.Windows.Forms.Form

Name of the ClassNamespace

Page 14: Cis166 final review c#

Instance versus Static Instance versus Static VariablesVariables

Instance variables or properties use a Instance variables or properties use a separate memory location for each instance separate memory location for each instance of the objectof the object

Static variables or properties use a single Static variables or properties use a single memory location that is available for ALL memory location that is available for ALL objects of a classobjects of a class– Can be accessed without instantiating an Can be accessed without instantiating an

object of the classobject of the class– Use the Use the StaticStatic keyword to create keyword to create

Static Methods can also be created

Page 15: Cis166 final review c#

Constructors and DestructorsConstructors and Destructors

Constructor: Method that automatically Constructor: Method that automatically executes when an object is instantiatedexecutes when an object is instantiated– Create by writing a procedure using the Create by writing a procedure using the

Class Name, followed by any argumentsClass Name, followed by any arguments Destructor: Method that automatically Destructor: Method that automatically

executes when an object is destroyedexecutes when an object is destroyed– Microsoft discourages use of in .NetMicrosoft discourages use of in .Net

Page 16: Cis166 final review c#

CollectionsCollections

Group of objectsGroup of objects– Can be strongly typed: all objects based on Can be strongly typed: all objects based on

the same classthe same class Similar to an arraySimilar to an array

– Collection expands and contracts Collection expands and contracts automaticallyautomatically

Have common properties and methodsHave common properties and methods– Add, Remove, Count, Item (Indexer)Add, Remove, Count, Item (Indexer)

Page 17: Cis166 final review c#

Item PropertyItem Property

Typically default property for a collectionTypically default property for a collection– Refer to collection object, followed by location Refer to collection object, followed by location

(in [])(in []) Returns a member of the groupReturns a member of the group

– Typically based on location, but can use other Typically based on location, but can use other valuesvalues

– Data type depends on the type of objects the Data type depends on the type of objects the collection managescollection manages

Page 18: Cis166 final review c#

Text Data FilesText Data Files

Actual data stored in files on disk deviceActual data stored in files on disk device FileFile ==>==> Entire collection of data ofEntire collection of data of

datadata RecordsRecords ==>==> Rows or lines, one per Rows or lines, one per

entityentity FieldsFields ==>==> Data elements within rowData elements within row

Page 19: Cis166 final review c#

Text File HandlingText File Handling

A A StreamStream is designed to transfer a series is designed to transfer a seriesof bytes from one location to anotherof bytes from one location to another

Streams are objects that have properties Streams are objects that have properties and methodsand methods

Found in the System.IO namespaceFound in the System.IO namespace File handling projects usually contain an File handling projects usually contain an

Imports statement before the statement Imports statement before the statement declaring the form's classdeclaring the form's class

Page 20: Cis166 final review c#

Writing Data FilesWriting Data Files

Declare a new Declare a new StreamWriterStreamWriter object object Use StreamWriter's Use StreamWriter's WriteLineWriteLine methodmethod Call StreamWriter's Call StreamWriter's Close methodClose method

Page 21: Cis166 final review c#

Write and WriteLine MethodsWrite and WriteLine Methods

Write Method: Places items consecutively in the Write Method: Places items consecutively in the file with no separatorfile with no separator

WriteLine Method: Places an Enter (carriage WriteLine Method: Places an Enter (carriage return) between recordsreturn) between records

Page 22: Cis166 final review c#

Reading FilesReading Files

Declare a new Declare a new StreamReaderStreamReader object object– File must exist!File must exist!

Use StreamReader's Use StreamReader's ReadLineReadLine methodmethod– Loop to retrieve multiple recordsLoop to retrieve multiple records

Call StreamReader's Call StreamReader's Close methodClose method

Page 23: Cis166 final review c#

ReadLine MethodReadLine Method

Use to read previously saved dataUse to read previously saved data Each time it executes, it reads the Each time it executes, it reads the nextnext line of data line of data Always assign the value from the read to a location, Always assign the value from the read to a location,

such as a label, text box, or string variablesuch as a label, text box, or string variable

Page 24: Cis166 final review c#

Checking for End of FileChecking for End of File

Use Use StreamReader's Peek MethodStreamReader's Peek Method Peek looks at the next element Peek looks at the next element withoutwithout actually actually

reading itreading it If you Peek beyond the last element the value If you Peek beyond the last element the value

returned is -1returned is -1