I need to make a program that calculates the students average test scores and th
ID: 3621273 • Letter: I
Question
I need to make a program that calculates the students average test scores and their grades.
I need to use three arrays: a one dimensional array to store the student's names, a parallel two dimensional array to store test scores, and a parallel one dimensional array to store the grades.
My program needs to have these functions: a function to read and store data into two arrays, a function to calculate the average test score and grade, and a function to output the results along with the class average.
Explanation / Answer
please rate - thanks
#include
#include
using namespace std;
void getdata(string[],int[][5]);
void getaverage(int[][5],double[]);
void print(string[],int[][5],double[]);
int main()
{double avg;
int grades[10][5];
string names[10];
double average[10];
int tot;
getdata(names,grades);
getaverage(grades,average);
print (names,grades,average);
system("pause");
return 0;
}
void print(string names[],int grades[][5],double avg[])
{int i,j;
cout<<"name test grades average grade ";
for(i=0;i<10;i++)
{cout<<<" ";
for(j=0;j<5;j++)
cout<<<" ";
cout<<" "<<<" ";
if(avg[i]>=90)
cout<<"A"<
else if(avg[i]>=80)
cout<<"B"<
else if(avg[i]>=70)
cout<<"C ";
else if(avg[i]>=60)
cout<<"D ";
else
cout<<"F ";
}
}
void getaverage(int grades[][5],double avg[])
{int i,j,tot;
for(i=0;i<10;i++)
{tot=0;
for(j=0;j<5;j++)
tot+=grades[i][j];
avg[i]=tot/5.;
}
}
void getdata(string names[],int grades[][5])
{ifstream in;
int i,j;
in.open("input.txt"); //open file
if(in.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
exit ( 1);
}
for(i=0;i<10;i++)
{in>>names[i];
for(j=0;j<5;j++)
in>>grades[i][j];
in.ignore(' ',10);
}
}