CMPU-203: Introduction to Computer Science III

Project #2
Due: Friday, Feb. 22

The main goal of this project will be to experiment with persistence of objects, and the ability to populate containers from a persistent object store (POS).

Part 1

Modify the Person class to use STL strings instead of character arrays for all the relevant data members.

Part 2

Extend the Person class to handle persistence. Add methods to the class for file input and file output. These methods should have the following signatures:

ifstream& operator>> (ifstream&, Person&);
ofstream& operator<< (ofstream&, const Person&);
Each method should assume it is passed a valid file stream parameter that is open and ready for reading or writing, and a valid Person object that has been allocated. The ifstream operator should allow for the EOF to be reached at any point in the input of the new object, without crashing (ie don't read after the EOF). The idea of these methods is that the output method should write data to the file in a format that the input method can read. The format is up to you.

Part 3

Create a new class, Student, which is a subclass of Person and has an additional data member for storing the student id. Implement the istream, ostream, ifstream, and ofstream methods for the Student class.

Part 4

Test your class implementations by creating a program called proj2. This program will take two command line arguments. The first argument will be a flag indicating whether to create a new collection of students, or to output an existing one. The second argument will be the name of a file that will serve as the POS. The command line format is:

proj2 -io filename
The -o flag indicates that a new collection of students will be entered via the keyboard and stored in the named file. The -i flag indicates that an existing collection of students will be read from the named file and printed out.

In other words,

proj2 -o students.dat
will read in data from the keyboard and store it to the file students.dat.

There are at least two ways to implement this program: using a container or not. Consider carefully these two alternatives. If you choose to use a container, use the STL vector class. Whichever alternative you use, put a comment at the beginning of your main program discussing your choice. This comment should be roughly a paragraph of dicussion in which you rationalize why you chose the alternative you did. Consider issues of time and space efficiency (to the degree you know it), ease of modification, future expandability, and anything else you think is relevant.

Submit a directory containing the following files:

person.h     Your extended Person class
student.h    Your Student class
main.C       Your test program and rationale