This is for C++. Please do it in same way as mentioned in the programe Grading S
ID: 664296 • Letter: T
Question
This is for C++. Please do it in same way as mentioned in the programe
Grading Schema: In a separate function you will implement a grading schema. Write a program that reads a student’s name together with his or her test score from a file given by the user. The first two values in the file will represent the number of students followed by the number of tests. The program should then compute the average test score for each student and assign the appropriate grade (A, B, C, D, E or F) as well as the average of each test. Your program must perform the following functions.
a) A void function calculateAverage, to determine the average of the test scores for each student.
b) A value-returning function, calculateGrade, to determine and return each student’s grade letter.
c) A void function calculateTestAvg that calculates the average of all tests and overall average of students.
d) A void function printGrades that prints the grades values, average marks and grade letter followed by the average of all tests and students.
The link for file(grades.txt) is
https://gc.blackboard.com/bbcswebdav/pid-2816130-dt-content-rid-3744009_1/courses/COMP2006-15S-30478/grades.txt
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
/* Function Declarations */
char calculateGrade(double);
void calcAverage(ifstream &, int [], int, double &);
void calTestAverage(ifstream &, int [],double &,double &);
int SumCount = 0; // Test
/* Entry-Point */
int main(void)
{
string name;
int i,numgrades=5,grade[5];
double average;
double classAvg = 0;
int SumCount=0; // Test
double classAvg2 = 0; // Test
int numStudents=0;
char letter;ifstream inputfile;
inputfile.open("https://drive.google.com/file/d/0B6lrduDwO1QvVEdLbWEtZW5lalk/view?usp=");
if(inputfile.fail())
{
cout<<"input file did not open please check it ";
return 1;
}
cout << "Names Test1 Test2 Test3 Test4 Test5 Average Grade ";
inputfile>>name;
while(inputfile)
{
calcAverage(inputfile,grade,numgrades,average);
letter = calculateGrade(average);
numStudents++; // Test
cout<<name<<" ";
for(i=0;i<numgrades;i++)
{
cout<<grade[i]<<" ";
SumCount=(SumCount+grade[i]); // Test
}
classAvg2=classAvg2+average; // Test
cout<<average<<" "<<letter<<" ";
inputfile>>name;
}
// calTestAverage(inputfile,grade,average,testAvg);
cout << endl << " # students: " << numStudents << " Test Average: " << testAvg2/numStudents << endl; // Test
// cout<<" Test Average = "<<testAvg <<endl<<endl;
inputfile.close();
return 0;
}
/* Function to retrieve the letter grade. */
char calculateGrade(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 test average.
void calTestAverage(ifstream &in, int grade[], double &average,double &testAvg) //
{
testAvg = 0;
for(int i = 7 ;i < 8;i++)
{for(int j = 1; j < 99 ;j++)
{
in>>average;
testAvg = testAvg + average;
}
}
testAvg = testAvg/10;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.