To gain experience with base and derived classes, virtual functions, and using applications of polymorphism. Also, to gain further practice with file I/O, as well as dynamic allocation.
You will design a set of classes for storing student information, along with a class that will manage a list of students. Data can be imported from files for storage in the list, and summary reports with computed final grades will be printed to output files.
1. Design a set of classes that store student grade information. There should be one base class to store common data, and three derived classes that divide the set of students into three categories: Biology students, Theater students, and Computer Science students. All data stored in these classes should be private or protected. Any access to class data from outside should be done through public member functions. The base class should allocate storage for the following data (and only this data):
2. Each class must have a function that will compute and return the student's final average, based on the stored grades. All grades are based on a 100 point scale. Here are the grades that need storing for each subject, along with the breakdown for computing each final grade:
Biology -- Lab Grade = 30%, Three term tests = 15 % each, Final Exam = 25%
Theater -- Participation (scene studies) = 40 %, Midterm = 25%, Final Exam = 35%
Computer Science -- There are 6 programming assignments, to be averaged into one Program Average (which can be a decimal number). Final grade computed as follows:
* Program Average = 30%, Test 1 = 20%, Test 2 = 20%, Final Exam = 30%
3. Write a class called StudentList, which will be used to store the list of various students, using a single array of flexible size. Note that this array will act as a heterogeneous list, and it will need to be dynamically managed. Each item in the array should be a Student pointer, which should point to the appropriate type of object. Your list should only be big enough to store the students currently in it. Note that the StudentList class is NOT part of the inheritance hierarchy described in the first two items above. This class is used to store and manage a LIST of individual students.
Your StudentList class needs to have these public functions available:
Note that while this class will need to do dynamic memory management, you do not need to create a copy constructor or assignment operator overload (for deep copy) for this class. (Ideally we would, but in this case, we will not be using a StudentList object in a context where copies of such a list will be made)
Here is a starter file: studentlist.h with the appropriate prototypes
#ifndef student_h
#define student_h
#include < string >
using namespace std;
// An abstract class that store student information
class Student
{
public:
// Initialize a student
Student(const string &firstName, const string &lastName, const string &course);
// Destructor
virtual ~Student();
// Access to the first name property
string getFirstName() const;
// Access to the last name property
string getLastName() const;
// Access to the course property
string getCourse() const;
// Find out the letter grade based on final average
char getLetterGrade() const;
// Calculate the final average grade of a student
virtual double calculateFinalAverage() const = 0;
// Return the final exam score
virtual int getFinalExamScore() const = 0;
private:
string firstName;
string lastName;
string course;
};
#endif
4. Write a main program (in a separate file) that creates a single StudentList object and then implements a menu interface to allow interaction with the object. Your main program should implement the following menu loop (any single letter options should work on both lower and upper case inputs):
*** Student List menu ***
I Import students from a file
S Show student list (brief)
E Export a grade report (to file)
M Show this Menu
Q Quit Program
The import and export options should start by asking for user input of a filename (you may assume it will be 30 chars or less, no spaces), then call the appropriate class function for importing a file or printing the grade report to file, respectively. (If the inport/export fails due to bad file, print a message indicating that the job was not successfully completed).
The "Show student list" option should call the class function that prints the brief student list to screen (names and course info only).
The Show this Menu option should re-display the menu.
Quit should end the menu program. (Until this option is selected, keep looping back for menu selections).
5. File formats
nput File -- The first line of the input file will contain the number of students listed in the file. This will tell you how many student records are being imported from this file. After the first lines, every set of two lines constitutes a student entry. The first line of a student entry is the name, in the format lastName, firstName. Note that a name could include spaces -- the comma will delineate last name from first name. The second line will contain the subject ("Biology", "Theater", or "Computer Science"), followed by a list of grades (all integers), all separated by spaces. There will be no extra spaces at the ends of lines in the file. The order of the grades for each class type is as follows:
Biology -- Lab Grade, three term tests, Final Exam
Theater -- Participation, Midterm, Final Exam
Computer Science -- six Program grades, Test 1, Test 2, Final Exam
Output File -- The output file that you print should list each student's name (firstName lastName - no extra punctuation between), Final Exam grade, final average (printed to 2 decimal places), and letter grade (based on 10 point scale, i.e. 90-100 A, 80-89 B, etc). Output should be separated by subject, with an appropriate heading before each section, and each student's information listed on a separate line, in an organized fashion. (See example below). The order of the students within any given category should be the same as they appear in the student list. Data must line up appropriately in columns when multiple lines are printed in the file. At the bottom of the output file, print a grade distribution of ALL students -- how many As, Bs, Cs, etc.
6. General Requirements
Add an extra menu option to the menu program:
The letter 'O' option should cause the student list to be sorted alphabetically by name -- by last name, and if needed by first name (when the last names are the same). Do not change any of the stored data in the student records (i.e. don't change the stored case -- upper/lower case -- of the names in the objects). Just re-order the array in the StudentList object so that it is now alphabetized by name. The sort needs to be true alphabetical (not just the "lexicographical" default for strings).
test1.txt
4
Squarepants, Spongebob
Computer Science 90 82 85 96 100 88 85 91 97
Finklebottom, Joe
Biology 85 90 78 85 89
Dipwart, Marvin
Theater 85 72 95
van Houten, Milhouse
Computer Science 45 80 76 79 54 72 73 81 79
test2.txt
2
Simpson, Homer J.
Theater 82 76 74
Cyrus, Miley
Biology 74 65 58 62 71
Screen input and output: (keyboard input is underlined here to differentiate output from input)
*** Student List menu ***
I Import students from a file
S Show student list (brief)
E Export a grade report (to file)
M Show this Menu
Q Quit Program
> i
Enter filename: test1.txt
> s
Last First Course
Squarepants Spongebob Computer Science
Finklebottom Joe Biology
Dipwart Marvin Theater
van Houten Milhouse Computer Science
> i
Enter filename: blah
Invalid file. No data imported
> i
Enter filename: test2.txt
> s
Last First Course
Squarepants Spongebob Computer Science
Finklebottom Joe Biology
Dipwart Marvin Theater
van Houten Milhouse Computer Science
Simpson Homer J. Theater
Cyrus Miley Biology
> e
Enter filename: outfile1.txt
> q
Goodbye!
Corresponding output file (outfile1.txt):
Student Grade Summary
---------------------
BIOLOGY CLASS
Student Final Final Letter
Name Exam Avg Grade
----------------------------------------------------------------------
Joe Finklebottom 89 85.70 B
Miley Cyrus 71 67.70 D
THEATER CLASS
Student Final Final Letter
Name Exam Avg Grade
----------------------------------------------------------------------
Marvin Dipwart 95 85.25 B
Homer J. Simpson 74 77.70 C
COMPSCI CLASS
Student Final Final Letter
Name Exam Avg Grade
----------------------------------------------------------------------
Spongebob Squarepants 97 91.35 A
Milhouse van Houten 79 74.80 C
OVERALL GRADE DISTRIBUTION
A: 1
B: 2
C: 2
D: 1
F: 0