Need code in c for the following question Add a method adjus
Need code in c++ for the following question:
Add a method adjustScore to the student class to allow for a single score to be changed by the user. The prototype for the method is as follows:
void adjustScore (int examNumber, int newScore);
Note that examNumber will be a value between one and three, as might be entered by a user of the program; do not confuse this with the notion of an exam array index, which would have a value between zero and two. It should be pointed out here that it is the obligation of any method to maintain the integrity of its object. Does changing a score logically affect any of the other class member data? The answer in this case is yes. Changing a score will definitely change the student\'s average and it could change the letter grade; conversely, there is no interaction between the score and the student\'s name or identification number. The constructor already contains program instructions to determine the average and grade from the scores. Move these instructions to a new method calculateAverageAndGrade which can then be called by both the constructor and by adjustScore.
void calculateAverageAndGrade (void);
Observe that nothing is accomplished by the user invoking this method on its own; since the integrity of the object data is maintained by every method, the average and score are already always consistent with the scores. For this reason, this method should be made private; to leave it public suggests a reason for doing so, and there simply is none. Test the program thoroughly to verify that it will work correctly for any input data.
Solution
So, if you are storing the marks in an array of size three,
Where X,Y,Z are the marks in respective subjects.
void adjustScore (int examNumber, int newScore)
{
marks[examNumber-1] = newScore;
calculateAverageAndGrade();
}
So, in the above scenario you\'ll need an N size array for storing marks of N subjects and this is initialised and the time of calling the constructor as well as the marks can be updated using the above function.
Since, change in marks will also change the average we\'ll call the calculateAverageAndGrade() to update the average marks.
| X | Y | Z |
