IUP Computer Science
CO 310 Fall 2002

Project 1
(Due   11 Sep 2002)

A small student-information database is being formed. Currently, a few students are represented in the database. However, more are expected to be added in the future (perhaps many); a few may be removed, as well. Your task is to write an interactive, command-driven program to handle the actions that need to be performed on this data base and to maintain the student records in alphabetical order, by name. Among the actions to be allowed are the following.
  1. ADD - add a new student record.
  2. DELETE - remove a record currently in the database.
  3. NAME FIND - show all the information about one student with a specified name (or display an error message if there is no such student).
  4. ID FIND - show all the information about one student with a specified ID (or display an error message if there is no such student).
  5. LIST - show all information about all students (listing them in alphabetical order).
  6. RANK - based on the GPAs, display the student's names and GPAs in the order of their rank (highest to lowest).
The file p1classes.h in the read-only folder for your section of COSC 310 on the P: drive contains the complete definition of two classes (InfoRecord and DataBase) that you are expected to use in writing your program.  Your program should include p1classes.h to gain access to the classes.  The overall structure of your program is relatively simple: It should begin by reading in information about all the students from a file into a DataBase object. You are given this data file in the read-only folder on the P: drive; it is named thestudents.dat  The records in the file are already in alphabetical order based on the student name. Then, the program should repeatedly prompt for and accept single-character commands from the keyboard and, using the member functions of InfoRecord and DataBase, perform the task associated with that command. The commands and their tasks are A - ADD, D - DELETE, I - ID FIND, L - LIST, N - NAME FIND, R - RANK and Q - QUIT. For this last command, the program should close the database (this permits updating to a file) and terminate the program.

An InfoRecord object is meant to contain the information about one student.  The data elements for a student consist of:
     string      name;          // Students name in the form:  last, first
     int         id;            // A 4-digit ID number
     float       gpa;           // Grade Point Average
     int         level;         // A class level number (1 - 4)
     string      major;         // Student's course of study
The member functions of InfoRecord allow a client programmer (you) to read an entire InfoRecord from a file or from the keyboard, display an InfoRecord on the screen in a standard form, write an InfoRecord to a file in the same form as it was in the input file, compare one InfoRecord to another (based on the name), and test for validity of an InfoRecord (valid if ID >= 0).  Each line of thestudents.dat contains a name (form shown above), an ID number, a GPA in the form x.xx, a class level number (1 for Fr. . . 4 for Sr), a major, and a newline character.

A DataBase object is essentially a flexible size collection of InfoRecords with associated data to keep track of the allocation and usage of the array.  The client programmer has access to member functions to do associative accesses of a specific InfoRecord in the collection based on either an ID number or a name (or partial name), to add an InfoRecord to the collection, to delete an InfoRecord from the collection (by specifying an ID number or a name), to display on the screen the entire collection of InfoRecords, to display on the screen the names and GPAs of students in rank order, to open the data file and read all InfoRecords into the collection, and to close the database (after possibly writing the updated collection to a file).

Your program should allow all single-letter commands to be entered in either uppercase or lowercase.  The response to the commands must be reasonable even if something is done wrong by the user of your program.  For example, if an ID FIND or a NAME FIND fails, an error message should be the result; if, when doing an ADD, invalid data is entered, the program must be forgiving; if an invalid letter is entered for a command, the program must be forgiving.  You will find that the way in which the member functions are written will make most such situations easy to deal with.  You should study the implementations of InfoRecord and DataBase before beginning your program to find out just how much these objects can do for you.

Demonstrate that the program works by running it and entering the following commands.

     L
     i         { find 3007 }
     D         { delete Bailey }
     n         { find  Oop }
     d         { delete 2100 }
     N         { find Smith, T }
     i         { find 3861 }
     d         { delete 8023 }
     D         { delete 8099 }
     n         { find Peach, Miss }
     I         { find 1806 }
     L
     R
     A        { add  Capp, Andy  ID=4117         you make up the rest }
     a        { add  Abner, Daisy Mae  ID=1426    you make up the rest }
     N        { find  Dallas, Steve }
     d        { delete 3861 }
     i        { find  4117 }
     A        { add  Palooka, Joe  ID=7633       you make up the rest }
     i        { find  6225 }
     A        { add Smith, Tina  ID=3008 }
     N        { find Abner }
     r
     l
     Q
Hand in a printout of your .cpp file containing the source program and a printout showing the results of performing the above sequence of commands.   Also, rename your .cpp file to be yourlastname-p1.cpp and copy it to the hand-in folder for your section of COSC 310 on the P: drive.