Grader Class - best and worst scores

Hi,
I am new to array and classes,
I am working on a homework assignment and have come to a bit of a stand still

We are to add scores through an addScore object and then have the program sort the biggest and smallest scores. MAX_SIZE constant is to be 100. The professor gave us the numbers to put in our arrays and what number we should get once the arrays have been passed through the find biggest and smallest functions

I was able to find some examples in the book and build a good start of the coding for the grader.h and grader driver.cpp

but I am having trouble figuring out what to program into the grader.cpp-- specifically where to start with the addScores objects


below is the code I have so far

grader.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef GRADER_H
#define GRADER_H
#include <iostream>
#include <cstdlib>
using namespace std;


Grader( );

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

int findBiggest( ) const;
int findSmallest( ) const;
int my_Values[ MAXSIZE ];
int my_valuesSeenSoFar;


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
#include <iostream.h>
#include <stdlib.h>

#include "grade.h"

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 could use some help with programing the grader.cpp file.

Thank you

Best,
Cam
In the first snippet it looks like you wanted to write a class def, but you didn't write it out correctly.

In the second snippet you write expressions outside of a function, this is not allowed in C++. You must write that code (except for the #includes, probably) inside a function, such as main.
Hi,
Thank you for that
I was able to sketch out a grader.cpp

so far the full code is as such

grader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef GRADER_H
#define GRADER_H
#include <iostream>
#include <cstdlib>
using namespace std;


Grader( );

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

int findBiggest( ) const;
int findSmallest( ) const;
int my_Values[ MAXSIZE ];
int my_valuesSeenSoFar;


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
24
25
26
27
28
29
30
31
#include "grade.h"
#include <iostream>
#include <cstdlib>
using namespace std;

int main {
Grader( );

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

int findBiggest( ) const;
int biggest;
   if (scores > 0) {
	  biggest = scores[0];

	  for (int i = 1; i < scores; i++)
		 if (scores[i] > biggest)
			biggest = scores[i];
   }

   return biggest;
}
int findSmallest( ) const;
int my_Values[ MAXSIZE ];
int my_valuesSeenSoFar;

}


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
29
30
#include <iostream.h>
#include <stdlib.h>

#include "grade.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'm still trying to figure out how to build the AddScores functions, to add numbers to the array

and I am a little confused on how to obtain findSmallest

thank you
Grader.h still fails to correctly define a class.

http://www.cplusplus.com/doc/tutorial/classes/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef GRADER_H
#define GRADER_H
#include <iostream>
#include <cstdlib>

class Grader {

Grader( );

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

int findBiggest( ) const;
int findSmallest( ) const;
int my_Values[ MAXSIZE ];
int my_valuesSeenSoFar;

};
#endif 
Last edited on
I am still stuck on how to set up my addscores in adding scores to an array
Topic archived. No new replies allowed.