Class Array


Really stuck on this practice assignment..


The Grader class is keeping track of a set of exam 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.


So far this is the code I have

Grader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef GRADER_H
#define GRADER_H
#define MAXSIZE 100
#include <iostream>
#include <cstdlib>

class Grader {

public:
Grader( );

void addScore( int score );
void addScores( int scores[], 
				int size );
void clear(); 


int findBiggest( ) const;
int findSmallest( ) const;

private:
int my_Values[ MAXSIZE ];
int my_valuesSeenSoFar;

};
#endif 


Grader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#define MAXSIZE 100
#include "Grader.h"

Grader::Grader( ){
}

void Grader::addScore( int score ){
	score = my_Values[MAXSIZE];
}
void Grader::addScores( int scores[], int size ){
	scores[size] = my_Values[MAXSIZE];
}
void Grader::clear(){
}

int Grader::findBiggest( ) const{
	for (int i = 0; i < MAXSIZE; i++);
}
int Grader::findSmallest( ) const{
}



Driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include "Grader.h"

int main( )
{
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 
}



I suppose what's causing me the most confusion is how to go about programming the addScores constructor and how to call back those array numbers into findBiggest and findSmallest
Last edited on
Duplicate:
http://www.cplusplus.com/forum/beginner/107511/
http://www.cplusplus.com/forum/beginner/107496/

Please stop posting the same questions over and over.
Topic archived. No new replies allowed.