Question: C++ OOD Problem: Design a C++ program called studentmain.cpp that uses the class and allows the user to enter and read multiple students
C++ OOD Problem: Design a C++ program called "studentmain.cpp" that uses the class and allows the user to enter and read multiple students names and grades, using the header file StudentTestScores.h
Add the following functions to the class:
1. A copy constructor. Test your program for how the constructor will be used. For example: The statement StudentTestScores stu2 = stu1; Will call the copy constructor that will initialize stu2 with all the member data in stu1 including values in the testScores member array of stu1.
2. Overload the assignment operator so that the statement stu3 = stu4; copies all the values from stu4 into stu3 (you may need to resize testScores array).
3. A member function that returns the average test score of a student. Sample call: cout<
4. A member function that displays the minimum test score along with the test number. Sample output: Test 2 has the minimum score; 73.
5. Overload the > operator. For example: stu6 > stu7 compares the average test scores for both students and returns true if stu6 average is greater than stu7 average, false otherwise.
Additionally, be sure to include a simple makefile to use with the two files.
Notes:
- DO NOT make any changes in StudentTestScores class other than adding the listed functions.
- DO NOT add a default constructor
- You do not have to use vectors
- Design the output in any way you want so that you fully demonstrate the class, all its member functions, and the copy constructor for multiple of students
- Hint: check how to define an array of pointers
Sample Output (as a guide)
Enter number of students: 3
Enter name of student 1:
John Doe
Enter number of test scores for John Doe: 4
Test Score 1: 70
Test Score 2: 90
Test Score 3: 80
Test Score 4: 98
Enter name of student 2:
Allan Smith
Enter number of test scores for Allan Smith: 3
Test Score 1: 90
Test Score 2: 83
Test Score 3: 72
Enter name of student 3:
Tom Allen
Enter number of test scores for Tom Allen: 5
Test Score 1: 81
Test Score 2: 74
Test Score 3: 61
Test Score 4: 90
Test Score 5: 56
The above is not the full output. You should demonstrate the
operations of other member functions and the copy constructor in the
class. You may define individual objects for testing the operations.
//StudentTestScores.h:
#ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string name, int numScores) { studentName = name; createTestScoresArray(numScores); } // Destructor ~StudentTestScores() { delete [] testScores; } // The setTestScore function sets a specific // test score's value. void setTestScore(double score, int index) { testScores[index] = score; } // Set the student's name. void setStudentName(string name) { studentName = name; } // Get the student's name. string getStudentName() const { return studentName; } // Get the number of test scores. int getNumTestScores() { return numTestScores; } // Get a specific test score. double getTestScore(int index) const { return testScores[index]; } }; #endif Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
