1 / 8

CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises

This chapter covers Windows GUI, file and directory classes, LINQ queries, and file processing in C#. Learn about FileStream, StreamReader, StreamWriter, and more. Practice questions included.

ladonnaj
Download Presentation

CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises

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. CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu

  2. 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 FileStream, StreamReader, StreamWriter, FileStream, and BinaryFormatter

  3. 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. StreamReader B. WriteFile C. StreamWriter 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. CreateFileDialog B. OpenFileDialog C. MessageBox D. SaveFileDialog

  4. Multiple Choices (cont'd) • StreamReader method _____ reads a line from a file. • A. ReadLine B. Read C. ReadAll D. ReadToNewline • A _____contains information that is read in the order it was written. • A. sequential-access file B. StreamWriter C. StreamReader D. None of the above • Methods from class _____ can be used to read data from a file. • A. StreamWriter B. FileReader C. StreamReader D. None of the above • 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 BinaryFormatter takes a(n) _______ and a(n) __________ as arguments. • A. object and Stream B. Stream and object C. File and object D. object and File

  5. 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 StreamReader inherits from class Stream. • Any class can be serialized to a file. • Classes StreamReader and StreamWriter are used with sequential-access files. • The class BinaryFormatter is under the namespace System.Runtime.Serialization.Formatters.Binary.

  6. True / False Statement (cont'd) • The ListBox control allows only a single selection (like a RadioButton). • Controls such as form, GroupBox, Panel, and TabControl are all containers. • All mouse events use the same event arguments class. • A ComboBox control typically has a drop-down list. • Deleting a parent node in a TreeView control deletes its child nodes.

  7. 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 StreamWriter • Write a method to read records from a file into a record array, using StreamReader • Use an LINQ query to find those students with the birth year > 1981, and write them into another file using BinaryFormatter

More Related