Write a C++ program that calculates grades for each student in a course. You can
ID: 3759479 • Letter: W
Question
Write a C++ program that calculates grades for each student in a course. You can assume that a course will never contain more than 128 students. The final grade of each student depends upon 3 test scores. Your program should read the ID number followed by three test scores for each student in the course from an input file. Once your program has read all information pertaining to a student, your program should calculate the average score of all tests for that student.
Then your program should calculate the mean and standard deviation of the average scores. Depending upon the mean, standard deviation and average score of a student, grades can be assigned for each student using the following pattern:
A Grade - Students having average score higher than B Grade Range
B Grade - Students having average score between the [Mean+(1.5)*Standard Deviation] and [Mean-(0.5)*Standard Deviation]
C Grade - Students having average score between the [Mean+(0.5)*Standard Deviation] and [Mean-(0.5)*Standard Deviation]
D Grade - Students having average score between the [Mean-(0.5)*Standard Deviation] and [Mean-(1.5)*Standard Deviation]
F Grade - Students having average score lower than D Grade Range
The program should calculate and print the letter grade for each student in the class. The Program should also meet the following requirements:
-File streams should be used to input student data into the program
-The program should declare and use a class studentype class.
-All data members of each intsance of class studentype should be declared private.
-All data pertinent to a particular student within the course should be contained within a single class studentype object for that student.
-The class studentype class should contain a member function (method) named PrintGrade. The program should define and use the PrintGrade member function to print the letter grade of a given student to standard output (The CPU Screen).
An example input file is shown below.
101 55 66 76
102 51 87 65
103 50 45 35
104 54 87 65
105 99 98 97
and this list can just keep going. The first number is the Student ID number and the next 3 are the test scores.
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
void calculate_mean_sd (int arrcal[], int &num);
void calculate_and_print_grades (int arrcal[], int num);
int main (void)
{
int arrcal [10],
num;
cout<<"Please enter the number of scores that you would like to determine the grades for: ";
cin>>num;
for (int i=0; i<num; i++)
{
cout<<"Please enter a score: ";
cin>>arrcal[i];
}
calculate_mean_sd (arrcal, num);
calculate_and_print_grades (arrcal, num);
return 0;
}
void calculate_mean_sd (int arrcal[], int &num)
{
double mean,
dSum,
sum_deviation,
standard_dev;
for (int i=0; i<num; i++)
{
dSum+=arrcal[i];
}
mean=dSum/num;
cout<<" Mean= "<<mean<<endl;
for (int i=0; i<num; i++)
{
sum_deviation+=(arrcal[i]-mean)*(arrcal[i]-mean);
}
standard_dev=sqrt(sum_deviation/num);
cout<<"Standard deviation= "<<standard_dev<<endl;
return;
}
void calculate_and_print_grades (int arrcal[], int num)
{
double mean,
standard_dev;
char * gradeArray = new char[num];
for (int i=0; i<num; i++)
{
if (arrcal[i]<(mean-1.5*standard_dev))
cout<<"The letter grade is F. "<<gradeArray[i];
else if ((mean-(1.4*standard_dev)) <=arrcal[i] && arrcal[i]<(mean-(0.5*standard_dev)) )
cout<<"The letter grade is D. "<<gradeArray[i];
else if ((mean-(0.4*standard_dev)) <=arrcal[i] && arrcal[i]<(mean+(0.5*standard_dev)) )
cout<<"The letter grade is C. "<<gradeArray[i];
else if ((mean+(0.4*standard_dev)) <=arrcal[i] && arrcal[i]<(mean+(1.5*standard_dev)) )
cout<<"The letter grade is B. "<<gradeArray[i];
else
cout<<"The letter grade is A. "<<gradeArray[i];
}
return;
}
#include <iostream>
#include <cmath>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.