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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
const int classMax=20;
const int N=3;
int input(int[][N], string[], float&);
int calculateGrades(int, int[][N], int[], char[], int[]);
int main()
{
string names[classMax];
int marks[classMax][N], gradesFreq[5]= {0};
char grades[classMax];
int total[classMax];
int maxindex, classSize;
float avg;
classSize=input(marks, names, avg);
cout<<"The average mark of all students is: "<<avg<<endl<<endl;
//maxindex=claculateGrades(classSize, marks, total, grades, gradedFreq);
//output(classSize, names, marks, total, grades, gradesFreq);
//cout<<"\nThe student that has the largest total is"<<names[maxindex]<<" with total equal to "<<total[maxindex]<<endl;
return 0;
}
int input(int marks[][N], string names[], float& avg)
{
ifstream inFile;
int classSize, midterm[classMax], work[classMax], Final[classMax];
int sum=0;
inFile.open("marks.txt");
inFile>>classSize;
for(int i=0; i<classSize; i++)
{
inFile>>midterm[i]>>work[i]>>Final[i];
getline(inFile, names[i]);
}
for(int i=0 ; i<classSize; i++)
{
sum+=midterm[i]+work[i]+Final[i];
}
avg=(sum/(classSize*N));
for(int i=0; i<classSize; i++)
{
for (int j=0; j<N; j++)
{
inFile>>marks[i][j];
}
}
inFile.close();
return classSize;
}
|