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;
}