The purpose of this lab design and implement a grading program, using an existing student grade class library, and also using the Standard Template Library (STL). Two lab periods are allocated for this project; a report (see below) is due each week. In the first week, a partial implementation will be done; in the second week, the program will be completed.
In this lab, you will:
You have been asked to design and implement a computer program to implement a student grade program. You have been given only a class library, and you must complete the application to the following specifications.
First, let us look at the student grade class library-- what can it do? The interface of the class library (from grades.h) is as follows:
// grades.h: Interface for student grades class library.
typedef double Grade;
class StudentGrade
{
public:
// Interface member functions
string GetName() const; // Get student name.
Grade GetGrade() const; // Get student grade.
bool Read(istream& stream); // Read name and grade from a stream.
void Write(ostream& stream) const; // Write name and grade to a stream.
|
Each StudentGrade object contains the name of a student and that student's grade. The numeric grade is of type Grade, a typedef for double. The GetName() member function returns a string object containing the student's name; GetGrade() returns the actual numeric grade.
The member functions Read() and Write() allow the you to read the data for a StudentGrade object from an input stream or to write that data to an output stream. These functions are meant for reading and writing data files only, not for reading data from the keyboard or writing it to the screen.
Now that you know a little about the StudentGrade class, take a look at the functions available in the Standard Template Library (STL). (For more detailed information, click the STL hyperlink.) One STL component you will need is the vector container. It is similar to an array in C++, but is easier to use and gets around some of the limitations of C++ arrays. An example of a vector of StudentGrade objects would be:
| vector<StudentGrade> grades; |
You can enter StudentGrade objects into the grades vector object by calling the push_back() member function, get the size of the vector with size(), remove elements from the vector with erase() or clear(), and sort the vector's contents with sort().
Your program will be a console-mode program (text screen) that is menu driven. In the menu, the user should be offered the following choices:
The user will choose an option by typing its number; you can choose to assign different numbers to the options if you wish. Whenever there is no grade data to manipulate (before any grades are read, or when no grades remain after a "select" operation), this menu should present only the "read" and "exit" options. You will probably find that the easiest way to do this is to have a single function to display the menu and to accept the option number from the user; this function can use selection statements to control whether all the menu options are offered to the user. If the user enters an invalid option number, your program should print a message and then ask for another choice.
Normally, in a menu like this, the user's option number controls a switch statement, with a set of cases that call functions corresponding to each choice. The assignment for the first week of the lab is to design the program and to implement the menu with program stubs for the functions called. A program stub is a piece of "dummy" code in what will later be the complete function. The stub code usually just prints a message (e.g., "Displaying the grades now") to indicate that the function was called. The actual function code can then be filled in later.
Here is some more detailed information on each of the functions the user may request:
Read Grades
This function should prompt the user for the name of a file to read. A sample data file (grades.txt) is in the .zip file you will download. The "read" function loads the file data into the current list of grades, replacing any grades that may already be in the list.
Although you will not read or write the file directly (since the Read and Write member functions of the StudentGrade class do this for you), you may be interested to know that the grade file has one line for each student; the quote-delimited string "last name, first name" is followed by a space and then the numeric grade. The file can be any length. A typical grade file looks like:
"Einstein, Albert" 82 "Curie, Marie" 95 "Newton, Isaac" 90 "Simpson, Bart" 100 "Lovelace, Ada" 91Write Grades
This function should prompt the user for the name of a file to write, and then write the data for all current students to the file. The Write member of the StudentGrade class should be used to write each grade to the file. The current student grade data is not affected by this operation.
Sort grades by student name
This function should sort the current list of grades by student name. The easiest way to do this is by applying the sort() function to your vector of StudentGrade objects. (The StudentGrade class is designed to order by student name when you apply the sort function to a vector of StudentGrade objects.) Note that this function only sorts, and does not display the sorted data.
Select grades above a certain score
This function should prompt the user for a minimum grade value, and keeps all the grades equal to or greater than that minimum value, throwing away any grades less than the minimum. Doing this creates a new grade list that is a subset of the original; note that the new list may possibly be empty (if all grades were below the minimum). Note that this function does not display the grades (the next function does that), but does modify the current grade list.
Display the grades
This function should display the current grade list to the screen, in whatever order (sorted or unsorted) that it happens to be. Note that you should not use the Write member function; this function is intended only for storing data in a file.
Display the grade statistics
This function should display the minimum, maximum, and average of the grades. It only calculates and displays the statistics, and does not change the grades in any way.
It is suggested that you have, as a minimum, one function for each of the above program choices. You may add other functions if you wish. Your program should have no data objects at file scope ("global data objects"); this will likely mean that some data objects will have to be passed as arguments from one function to another.
If you have difficulties with any part of the lab, consult the instructor for assistance. The basic sequence is:
Each (interim and final) lab report should contain:
You may submit these reports in hard-copy form, or email them to the instructor. If you choose email, it may be convenient to put the textual portion of the report directly in the message, and to attach the source file. Be sure to keep copies of all your files, in case something gets lost; it may be wise to keep a diskette backup as well.
Each lab report is due by the beginning of the following lab period, though you are encouraged to submit them sooner if you can. Your grade will depend on quality of design and clarity of the code and documentation. If you have any questions, consult the instructor.
In addition to the lab report, please demonstrate your final program to the instructor. This may be done during the lab period, or at another mutually agreed time. The demonstration should be done no later than the first hour of the following lab period.
This lab was originally developed in cooperation with Dr. Steve Barnicki, who prepared much of this assignment write-up.
This page was last updated on November 16, 1997; send comments to Mark Sebern.