The assignment is to read and keep records and perform statistical analysis for a class of students.
This is what I have done so far,then the codes can show the information(Id,4quizes,exam) of each students on screen. But I need to show 3 more things (The Highest ,The Lowest,The Average of each quiz and exam ).
How can I get those ? I can't go ahead. Could anyone have an idea?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Student.h"
int main()
{
Student stuArray[50];
int stuQuiz[4];
int i;
int numStudents = 0;
int idIn;
int quizIn[4];
int examIn;
ifstream inFile("page595data.txt");
if(!inFile.is_open())
{
cerr << "Could not open input file. Terminating program." << endl;
system("pause");
exit(100);
}
while(!inFile.eof())
{
inFile >> idIn;
for( i = 0; i < 4; i++)
inFile >> quizIn[i];
inFile >> examIn;
if(!inFile.eof())
{
stuArray[numStudents] = Student(idIn, quizIn, examIn);
numStudents++ ;
}
} // while
cout << setw(8) << "ID" << setw(8) << "Quiz 1" << setw(8) << "Quiz 2" ;
cout << setw(8) << "Quiz 3" << setw(8) << "Quiz 4" <<setw(8)<< "Exam" << endl ;
for(i=0; i < numStudents; i++)
stuArray[i].printStudent();
cout << setw(8) << "High" << endl;
cout << setw(8) << "Low" << endl;
cout << setw(8) << "Average" << endl;;
system("pause");
return 0;
} // main
--------------------------------------------------
class Student
{
private:
int id;
int quiz[4];
int exam;
public:
Student();
Student(int idIn,int quizIn[],int examIn);
void getStudent(int& idOut, int quizOut[], int& examOut);
void printStudent();
}; // Student
-----------------------------------------
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
#include "Student.h"
Student :: Student ()
{
}
Student :: Student(int idIn,int quizIn[],int examIn)
{
id = idIn ;
quiz[0] = quizIn [0];
quiz[1] = quizIn [1];
quiz[2] = quizIn [2];
quiz[3] = quizIn [3];
exam = examIn ;
}
void Student :: printStudent()
{
cout << setw(8) << id << setw(8) << quiz[3] << setw(8) << quiz[1] ;
cout << setw(8) << quiz[2] << setw(8) << quiz [3] << setw(8) << exam << endl;
}
It looks weird , but it worked so far.