ECE 1574: Project 2

---This is a draft and might change slightly. Any changes will be noted---

Requirements

  1. Arrays
  2. Structs
  3. File I/O

Background

For this project we are going to be making a basic gradebook application. Our application will read a set of data from a file, store the data in array. It will then follow a series of commands for sorting and displaying.

Details

This is the set of commands:

Load <filename>  
Display <filename> 
Sort <sortkey>

Each of these commands is describe in more detail here:

Load or load or l:

this command will read the filename that follows and load in the students and grades. The format of the file will be in the following form:

New: Added 2/24: When this command is done, it needs to write the following output on the ostream: Loaded: <filename> # Students: <number of students loaded> Where <filename> is the name of the file it was asked to load and <number of students> was how many students it read from the input file.

If there has been a set of grades already loaded in, they will be "erased".

Display or display or d:

this command will display the filename that is given. It will display the gradebook as a table. More information on this display is coming.

New: Added 2/24: When this command is done, it needs to write the following output on the ostream: Displayed: <filename> # Students: <number of students displayed> Where <filename> is the name of the file it was asked to display to and <number of students> was how many students it wrote to the output file.

Sort or sort or s:

this command will read the sort key and sort the data on the given key. The keys will be one of the following words, name or average or dname or daverage. If name or average is given, then sort the data using either the name or average in an ascending order. Make sure that when you sort you use either an all upper or lowercase version of their name. If the key is dname or daverage, then sort the data in descending order. Still use the all upper or all lowercase version of their last name.

New: Added 2/24: After this command is given. It will display the following output on the ostream: Sorted: <sortkey> Where <sortkey> is how the grades where asked to be sorted.

This output will allow us to ensure that you are reading the commands correctly and can be used by you to make sure that the files are being read correctly.

The way we are going to store all this data is using a structure and an array. The array should be of size 100 and should be typed to be the struct. I suggest that the struct store the first and last names, the grades for the student and their average. I'll include a possible structure below. You may use this one or modify it to suit your needs.

Sorting

Ok, so for sorting, let's just use good ole bubble sort. Why? Because it's a stable sort. A stable sort is one that keeps the relative ordering between elements the same. So if two people have the same last name, then the one that comes first, will always come first. So here is some bubble sort code you can use/modify. Remember, free code is like a free puppy, lot's of fun, but you have to do the work to make it useful.

void sort( Student students[], int numStudents )
{
    for ( int i=1; i<numStudents; i++ )
    {
        for ( int j=0; j < numStudents-1; j++ )
        {
            if ( students[j].average > students[j+1].average )
            {
                Student temp = students[j];
                students[j] = students[j+1];
                students[j+1] = temp;
            }
        }
    }
}

Requirements

For this project there will be 1 core function that you need to write:

void gradebook( istream& in, ostream& out );

This function will start the program and wait for commands. This function must be declared in a file named:

gradebook.h

In addition to this 1 core function, you are required to write at least 2 other functions. One of the functions must return a value and one of the functions must use pass-by-reference. Some suggestions for functions are:

Additionally, you must follow these requirements as well:

  1. You must use an array of structures.
  2. You must comment your code, a header comment for all function and comment throughout the code as needed to explain your code
  3. Your structure must store the grades for the students in arrays.
  4. You may not use the STL for vectors, the algorithm library, or other parts not discussed. If in doubt ask.

Sample Files

Due Date

This is due March 7th by 11:55 PM.

Grading

Zip up your gradebook.h file and any implementation files and submit them to Web-CAT by the due date. There is an early bonus. You may submit late for a 10 point per day deduction.