I need help in writing a C++ class definition called SIMPLEST_GRADES which will evaluate the students performance. It will take the three exams of four students and takes its average of those three exams. Can you tell me what I can do to fix this program or do I have to make any changes.

This is my program:

// skel_p0.h
// This means that this is a skeleton file for the program

#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>

// declare the input file
   ifstream input_file("in.0",ios::in);
// declare the output file
   ofstream output_file("out.0",ios::out);

  class SIMPLEST_GRADES{

  public:      // public interfaces for this class

        SIMPLEST_GRADES(void);	// example: g.SIMPLEST_GRADES();
				       // constructor;
                                  // returns nothing (void) 

        void SIMPLEST_READ(void); // example: g.SIMPLEST_READ();
				  // interface to read student grades
                                  // returns no values;

        void SIMPLEST_AVE(int);  // example: e.SIMPLEST_AVE(2);
				 // interface to find the average grade
				 // for exam 2;
                                 // returns no values;

   private: // private var to be used by this class only (not from main)

        int n;  // no of students
        int id[20]; // the integer arry to hold the ids
        int e1_grades[20];  	// the array to hold student grades for e1
        int e2_grades[20];  	// the array to hold student grades for e2
        int e3_grades[20];  	// the array to hold student grades for e3
        float average; 		// variable to hold the average for an exam
   };

SIMPLEST_GRADES::SIMPLEST_GRADES(void)
{
	// initialize the elements of arrays to 0;
	int i;
	n = 0;
	for(i = 0; i < 20; i++)
	{
		e1_grades[i] = 0;
		e2_grades[i] = 0;
		e3_grades[i] = 0;
		id[i] = 0;
	}
	average = 0;
	output_file << "CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT." << endl;
}
		
void SIMPLEST_GRADES::SIMPLEST_READ(void)
{
	int i;
	input_file >> n; // n = 4
	for(i = 0; i < n; i++)
	{
		input_file >> id[i] >> e1_grades[i] >> e2_grades[i] >> e3_grades[i];
	}
	output_file << "THERE ARE "<< n << " STUDENTS IN THIS SYSTEM." << endl;
}

void SIMPLEST_GRADES::SIMPLEST_AVE(int x)
{
	int i;
	int sum = 0;
	for(i = 0; i < n; i++)
	{
		if (x == 1)
		{
			sum = sum + e1_grades[i];
			average = sum/n;
		}
		else if (x == 2)
		{
			sum = sum + e2_grades[i];
			average = sum/n;
		}
		else if (x == 3)
		{
			sum = sum + e3_grades[i];
			average = sum/n;
 		}
	}
	if (x >= n)
	{
		output_file << "OUTPUT FROM SIMPLEST_AVE INTERFACE:" <<endl;
		output_file << "INPUT ERROR" <<endl;
	}
	
	output_file << "OUTPUT FROM SIMPLEST_AVE INTERFACE:" << endl;
	output_file << "THE AVERAGE FOR " << n << " STUDENTS IN EXAM " << x << " IS " << setprecision(4) << showpoint << average << "." << endl;
}

Recommended Answers

All 3 Replies

What do you see as the problem?

Does it compile? If not, what error messages do you get, where do they point you? Can you fix them?

If it does compile, what behavior do you see when you run it? How does that compare to the behavior you expect to see?

My program does compile successfully for the two tests but, I'm receiving an error in the compilation somewhere. When I grade myprogram using the code /usr/tools/EE259/IO/grademe_lp0 for Linux Machines I'm getting only 60 points for the partial grade. Let me post up the error message.

This is the Testing Report that test my program if it is a wroking program or not:
THE TESTING REPORT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test report for EXAMPLE 1
compilation succeeded
INPUT FILE :
---------------------------------------
4
1111 90 90 80
3333 80 70 60
2222 20 30 70
4444 60 50 70
---------------------------------------
test_1 succeeded
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test report for EXAMPLE 2
INPUT FILE :
---------------------------------------
4
1111 90 90 80
3333 80 70 60
2222 20 30 70
4444 60 50 70
---------------------------------------
test_2 succeeded

This testing report tells me that the two input files has compiled successfully and the two tests have failed:

THE TESTING REPORT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test report for EXAMPLE 1
compilation succeeded
INPUT FILE :
---------------------------------------
4
1111 90 90 80
3333 80 70 60
2222 20 30 70
4444 60 50 70
---------------------------------------
test_1 FAILED:

================== YOUR ANSWER: ==================
CONSTRUCTOR SUCESSFULLY INITIATED AN OBJECT.
THERE ARE 4 STUDENTS IN THIS SYSTEM.

================== EXPECTED ANSWER: ==================
CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT.
THERE ARE 4 STUDENTS IN THIS SYSTEM.

================== THE DIFFERENCE: ===================
1c1
< CONSTRUCTOR SUCESSFULLY INITIATED AN OBJECT.
---
> CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test report for EXAMPLE 2
INPUT FILE :
---------------------------------------
4
1111 90 90 80
3333 80 70 60
2222 20 30 70
4444 60 50 70
---------------------------------------
test_2 FAILED:

================== YOUR ANSWER: ==================
CONSTRUCTOR SUCESSFULLY INITIATED AN OBJECT.
THERE ARE 4 STUDENTS IN THIS SYSTEM.

================== EXPECTED ANSWER: ==================
CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT.
THERE ARE 4 STUDENTS IN THIS SYSTEM.
OUTPUT FROM SIMPLEST_AVE INTERFACE:
THE AVERAGE FOR 4 STUDENTS IN EXAM 2 IS 60.00.

================== THE DIFFERENCE: ===================
1c1
< CONSTRUCTOR SUCESSFULLY INITIATED AN OBJECT.
---
> CONTSTRUCTOR SUCCESSFULLY INITIATED AN OBJECT.
2a3,4
> OUTPUT FROM SIMPLEST_AVE INTERFACE:
> THE AVERAGE FOR 4 STUDENTS IN EXAM 2 IS 60.00.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
partial grade = 20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have already posted my program. The error that I'm receiving is in the second testing report. The first testing report tells me that the compilation of the two input files have succeeded. The two tests has failed.

Not seeing your main( ) implementation, and not knowing how that grading program works, all I can see is that you misspelled "successfully" and that you likely did not call the average computation function when you should have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.