CSE 11 Spring 2001
Homework #4
Required reading: Savitch text Chapters 9 and Section 10.1 of Chapter 10.
Turn in due date: Monday,
May 7(i.e., 8 am May 8)
Interview due date: Thursday, May 10
DO NOT turnin hw4 before April 28. You can do hw4 before then and even
take an interview, just do not turn it in before April 28.
Note: Material from this assignment will be covered on the midterm.
Note: You can do this and take an interview without turning in the assignment, as long as it is before the turnin deadline (and until the deadline is announced it is definitely before the deadline).
Programming:
You may work in teams of two students, but once you form a team, you cannot
change the team for this assignment. You may work alone if you prefer.
(This is similar but not identical to Programming Project 5 in chapter 10.)
Write a program that reads in a list of PetRecords from a file into a vector, sorts the records in the vector by pet weight, and finally writes the records to another file (sorted by pet weight) followed by the number and percentage of pets under 5 pounds, the number and percentage of pets that are 5 to 10 pounds, and the number and percentage of pets over 10 pounds. The class PetRecord is given in Chapter 5, Display 5.19/page 351. Your program will get the file names from the user and will display screen messages saying what it is doing. Call your program SortPets. The input file will be a binary file of PetRecords. The output file will be a text file.
You will modify the class PetRecords by adding input and output function to send output to a binary file and read input in from a binary file. Name the methods fileInput and fileOutput. You will not add anything else to the class PetRecord. In particular you will not add methods for file I/O to text files. Note that you will need binary file output to create a test file to use as an input file to test your program.
You will not turnin in your
modified file for PetRecord, but keep it in your account and do not touch it
so we can check the date. You only turn in SortPets.java.