Write a program to calculate students average test scores and their grades. You
ID: 3761060 • Letter: W
Question
Write a program to calculate students average test scores and their grades. You may assume the following data: Use three arrays: a dimensional array to store the test score, and a parallel one-dimensional array to store grades. Your program must contain at least the following methods: a method to read and store data into two arrays, a method to calculate the average test score and grade and a method to output the results. Have your program also output the class average. Grade calculation to be computed as follows:Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
/* Function Declarations */
char calculate_Grade(double);
void calcAverage(ifstream &, int [], int, double &);
void calclasseAverage(ifstream &, int [],double &,double &);
intSum = 0;
int main(void)
{
string name;
int i,numgrades=5,grade[5];
double average;
double classAvg = 0;
intSum=0;
double classAvg2 = 0;
int numStudents=0;
char letter;
ifstream inputfile;
inputfile.open("text1.txt");
if(inputfile.fail())
{
cout<<"input file did not open please check it ";
return 1;
}
inputfile>>name;
while(inputfile)
{
calcAverage(inputfile,grade,numgrades,average);
letter = calculate_Grade(average);
numStudents++;
cout<<name<<" ";
for(i=0;i<numgrades;i++)
{
cout<<grade[i]<<" ";
Sum=(SumCount+grade[i]);
}
classAvg2=classAvg2+average;
cout<<average<<" "<<letter<<" ";
inputfile>>name;
|
cout << endl << " # students: " << numStudents << " Class Average: " << classAvg2/numStudents << endl;
inputfile.close();
return 0;
}
/* Function to retrieve the letter grade. */
char calculate_Grade(double average)
{
if(average >=90)
return 'A';
else if(average >=80)
return 'B';
else if(average >=70)
return 'C';
else if(average>=60)
return 'D';
else
return 'F';
}
/* Function to read an entry and calculate the average. */
void calcAverage(ifstream &in, int grade[], int max, double &average) //
{
int i=0,sum=0;
for(i=0; i < max ;i++)
{
in>>grade[i];
sum+=grade[i];
}
average=(double)sum/max;
}
Function to calculat the class average.
void calclasseAverage(ifstream &in, int grade[], double &average,double &classAvg)
{
classAvg = 0;
for(int i = 7 ;i < 8;i++)
{for(int j = 1; j < 22 ;j++)
{
in>>average;
classAvg = classAvg + average;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.