Exercises

  1. 17.3 (File of Student Grades) Create a program that stores student grades in a text file. The file should contain the name, ID number, class taken and grade of every student. Allow the user to load a grade file and display its contents in a read-only TextBox. The entries should be displayed in the following format:

    
    LastName, FirstName: ID# Class Grade
    

    We list some sample data below:

    
    Jones, Bob: 1 "Introduction to Computer Science" "A-"
    Johnson, Sarah: 2 "Data Structures" "B+"
    Smith, Sam: 3 "Data Structures" "C"
    
  2. 17.4 (Serializing and Deserializing) Modify the previous program to use objects of a class that can be serialized to and deserialized from a file.

  3. 17.5 (Extending StreamReader and StreamWriter ) Extend classes StreamReader and Stream-Writer. Make the class that derives from StreamReader have methods ReadInteger, ReadBoolean and ReadString. Make the class that derives from StreamWriter have methods WriteInteger, WriteBoolean and WriteString. Think about how to design the writing methods so that the reading methods will be able to read what was written. Design WriteInteger and WriteBoolean to write strings of uniform size so that ReadInteger and ReadBoolean can read those values accurately. Make sure ReadString and WriteString use the same character(s) to separate strings.

  4. 17.6 (Reading and Writing Account Information) Create a program that combines the ideas of Fig. 17.4 and Fig. 17.6 to allow a user to write records to and read records from a file. Add an extra field of type bool to the record to indicate whether the account has overdraft protection.

  5. 17.7 (Telephone-Number Word Generator) Standard telephone keypads contain the digits zero through nine. The numbers two through nine each have three letters associated with them (Fig. 17.15). Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in Fig. 17.15 to develop the seven-letter word “NUMBERS.” Every seven-letter word corresponds to exactly one seven-digit telephone number. A restaurant wishing to increase its takeout business could surely do so with the number 825-3688 (i.e., “TAKEOUT”).

    Every seven-letter phone number corresponds to many different seven-letter words. Unfortunately, most of these words represent unrecognizable juxtapositions of letters. It’s possible, however, that the owner of a barbershop would be pleased to know that the shop’s telephone number, 424-7288, corresponds to “HAIRCUT.” The owner of a liquor store would no doubt be delighted to find that the store’s number, 233-7226, corresponds to “BEERCAN.” A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters “PETCARE.” An automotive dealership would be pleased to know that its phone number, 639-2277, corresponds to “NEWCARS.”

    Fig. 17.15 Letters that correspond to the numbers on a telephone keypad.

    Digit Letter
    2 A B C
    3 D E F
    4 G H I
    5 J K L
    6 M N O
    7 P R S
    8 T U V
    9 W X Y Z

    Write a GUI program that, given a seven-digit number, uses a StreamWriter object to write to a file every possible seven-letter word combination corresponding to that number. There are 2,187 (37) such combinations. Avoid phone numbers with the digits 0 and 1.

  6. 17.8 (Student Poll) Figure 8.9 contains an array of survey responses that’s hard-coded into the program. Suppose we wish to process survey results that are stored in a file. First, create a Windows Form that prompts the user for survey responses and outputs each response to a file. Use Stream-Writer to create a file called numbers.txt. Each integer should be written using method Write. Then add a TextBox that will output the frequency of survey responses. You should modify the code in Fig. 8.9 to read the survey responses from numbers.txt. The responses should be read from the file by using a StreamReader. Class string’s Split method should be used to split the input string into separate responses, then each response should be converted to an integer. The program should continue to read responses until it reaches the end of file. The results should be output to the TextBox.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset