CSCI 3328 Object Oriented Programming in C Chapter

  • Slides: 9
Download presentation
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -Exercises UTPA

CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -Exercises UTPA – Fall 2012 1

Objectives • In this chapter, you will do some exercises about: – Windows GUI

Objectives • In this chapter, you will do some exercises about: – Windows GUI – Classes File and Directory – LINQ queries to search through directories – sequential-access file processing – Classes File. Stream, Stream. Reader, Stream. Writer, File. Stream, and Binary. Formatter 2

Multiple Choices • The smallest data item a computer can process is called a

Multiple Choices • The smallest data item a computer can process is called a ____. – A. database B. byte C. file D. bit • A group of related records is stored in a ____. – A. file B. field C. bit D. byte • Data maintained in a file is called _____. – A. persistent data B. bits C. secondary data D. databases • Methods from the ____ class can be used to write data to a file. – A. Stream. Reader B. Write. File C. Stream. Writer D. None of the above • Namespace ____ provides the classes and methods you need to perform file processing. – A. System. IO B. System. Files C. System. Stream D. System. Windows. Forms • A(n) ____ allows the user to select a file to open. – A. Create. File. Dialog B. Open. File. Dialog C. Message. Box D. Save. File. Dialog 3

Multiple Choices (cont'd) • Stream. Reader method _____ reads a line from a file.

Multiple Choices (cont'd) • Stream. Reader method _____ reads a line from a file. – A. Read. Line B. Read C. Read. All D. Read. To. Newline • A _____contains information that is read in the order it was written. – A. sequential-access file B. Stream. Writer C. Stream. Reader D. None of the above • Methods from class _____ can be used to read data from a file. – A. Stream. Writer above B. File. Reader C. Stream. Reader D. None of the • Ultimately, all data items processed by a computer are reduced to combinations of _____. – A. 0 -9 B. 'a'-'z' C. 'A'-'Z' D. 0's and 1's • Method Serialize of class Binary. Formatter takes a(n) _______ and a(n) _____ as arguments. – A. object and Stream B. Stream and object C. File and object D. object and File 4

True / False Statement • Creating instances of classes File and Directory is impossible.

True / False Statement • Creating instances of classes File and Directory is impossible. • Typically, a sequential file stores records in order by the record-key fields. • Class Stream. Reader inherits from class Stream. • Any class can be serialized to a file. • Classes Stream. Reader and Stream. Writer are used with sequential-access files. • The class Binary. Formatter is under the namespace System. Runtime. Serialization. Formatters. Binary. 5

True / False Statement (cont'd) • The List. Box control allows only a single

True / False Statement (cont'd) • The List. Box control allows only a single selection (like a Radio. Button). • Controls such as form, Group. Box, Panel, and Tab. Control are all containers. • All mouse events use the same event arguments class. • A Combo. Box control typically has a drop-down list. • Deleting a parent node in a Tree. View control deletes its child nodes. 6

Writing the C# Code • A student record has information such as student ID,

Writing the C# Code • A student record has information such as student ID, last name, first name, birth year, and so on. – Declare a class for a student record – Write a method to write records into a file, using Stream. Writer – Write a method to read records from a file into a record array, using Stream. Reader – Use an LINQ query to find those students with the birth year > 1981, and write them into another file using Binary. Formatter 7

! y a D g n i v i g s k n a

! y a D g n i v i g s k n a h T y p p Ha 8

9

9