Project 12: Grader The Grader class is keeping track of a set of test scores. Sc
ID: 3833802 • Letter: P
Question
Project 12: Grader
The Grader class is keeping track of a set of test scores. Scores can be added one at a time thru calls to addScore( ... ) or it can add a set of scores thru calls to addScores( ... ). Once scores have been collected, the Grader class can find the best and worst scores it has seen so far thru calls to findBiggest( ) and findSmallest( ). Both of these methods are read-only operations, so you won't be able to change or update anything inside the Grader instance object. Processing arrays lead to lots of loops and that is what will be necessary in these methods. As for the MAX_SIZE constant, I would recommend you just set it to a very large number (say 100...) and move on.
You will notice also that the class Grader has an integer counter named valuesSeenSoFar. This counter is meant to tell you how full the array actually is. Since an array is not a class, you can't ask the my_Values array any questions. This counter needs to be maintained (incremented and decremented) by your Grader class code, as driver code fills and empties the array.
Following the class diagrams shown below, implement the Grader class. Embed your class in a suitable test program that proves your calculations are correct. You may choose to create any number of additional methods, but you are required to implement all of the public methods shown below. You are free to ignore the private parts of the class I suggest below.
Grader Class
Sample Driver Code
Grader
Grader( );
void addScore( int score );
void addScores( int scores[ ],
int size );
void clear( );
int findBiggest() const;
int findSmallest() const;
int myValues[ MAXSIZE ];
int myValuesSeenSoFar;
Grader g;
double d[5]= {99,70,85,93,84};
double e[4]= {100,81,60,91};
g.addScore( 75 );
g.addScore( 82);
g.addScores( d, 5 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 99
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 70
g.clear( );
g.addScore( 50 );
g.addScore( 74 );
g.addScores( e, 4 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 100
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 50
Need help on this c++ assignment
Grader Class
Sample Driver Code
Grader
Grader( );
void addScore( int score );
void addScores( int scores[ ],
int size );
void clear( );
int findBiggest() const;
int findSmallest() const;
int myValues[ MAXSIZE ];
int myValuesSeenSoFar;
Grader g;
double d[5]= {99,70,85,93,84};
double e[4]= {100,81,60,91};
g.addScore( 75 );
g.addScore( 82);
g.addScores( d, 5 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 99
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 70
g.clear( );
g.addScore( 50 );
g.addScore( 74 );
g.addScores( e, 4 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 100
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 50
Explanation / Answer
#include <iostream>
#define MAXSIZE 100
using namespace std;
class Grader
{
public:
Grader( )
{
myValuesSeenSoFar = 0;
}
void addScore( int score )
{
myValues[myValuesSeenSoFar++] = score;
}
void addScores( int scores[ ],
int size )
{
for(int i = 0; i < size; i++)
myValues[myValuesSeenSoFar++] = scores[i];
}
void clear( )
{
myValuesSeenSoFar = 0;
}
int findBiggest() const
{
int largest = myValues[0];
for(int i = 1; i < myValuesSeenSoFar; i++)
{
if(largest < myValues[i])
largest = myValues[i];
}
return largest;
}
int findSmallest() const
{
int smallest = myValues[0];
for(int i = 1; i < myValuesSeenSoFar; i++)
{
if(smallest > myValues[i])
smallest = myValues[i];
}
return smallest;
}
private:
int myValues[ MAXSIZE ];
int myValuesSeenSoFar;
};
int main()
{
Grader g;
int d[5]= {99,70,85,93,84};
int e[4]= {100,81,60,91};
g.addScore( 75 );
g.addScore( 82);
g.addScores( d, 5 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 99
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 70
g.clear( );
g.addScore( 50 );
g.addScore( 74 );
g.addScores( e, 4 );
cout << "Best Score = " << g.findBiggest( ) << endl;
/// should give value 100
cout << "Worst Score = " << g.findSmallest( ) << endl;
/// should give value 50
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.