C Program 7 Grading on the Curve Letter grades are sometime
C++ Program 7 : Grading on the Curve. Letter grades are sometimes assigned to numeric scores by using the grading scheme commonly called grading on the curve. In this scheme, a letter grade is assigned to a numeric score, according to the following table: ------------------------------------------------------------------------ x = Numeric Score Letter Grade ------------------------------------------------------------------------ x < m - (3/2)(Sigma) F m - (3/2)(Sigma) <= x < m - (1/2)(Sigma) D m - (1/2)(Sigma) <= x < m + (1/2)(Sigma) C m + (1/2)(Sigma) <= x < m + (3/2)(Sigma) B m + (3/2)(Sigma) <= x A ------------------------------------------------------------------------- where m is the mean (average) score and Sigma is the standard deviation. (See below for more details.) Read a list of floating-point numbers representing numerical scores into an array, calculate their mean (average), and their standard deviation, and then output each score, it\'s distance in Sigma\'s from the mean, and it\'s corresponding letter grade. Also output the values for the mean and sigma once, before you write out each score/distance from mean/letter grade. Note that you should be able to run the program for multiple lists of scores. You should be able to input a list of any size (including 0) and handle it correctly. Assume the \"valid\" (non-negative) scores are terminated by a sentinel value that is negative. ********************************************************************** * * * Because the purpose of this program is, in part, to work with * * arrays and functions, you should have (at least) the following * * functions: * * * * 1) A GetData function that gets the scores into an array * * (and gets them back to the calling function.) * * 2) A function to calculate the mean and Sigma and make them * * available to the calling function. * * 3) A function to take the mean, Sigma, and a score and * * a) Calculate how many Sigma\'s above/below the mean the score * * is. * * b) Calculate the letter grade * * c) Gets those 2 values back to the calling function so it * * can print them out. * * * ********************************************************************** Mean = (sum of all x\'s) / N where N = number of values Sigma = sqrt(variance) where... Variance = [1 / N] [ sum of (pow((x - mean), 2) ) ] ------------------------------------------------------------------------- Run with the following datasets (note the 0 is a valid score, and the -10\'s are to signal no more data and they themselves should NOT be added into the data that\'s processed for means, sigmas, etc. 100 80 70 60 40 -10 100 80 60 40 20 -10 100 60 50 40 0 -10 ------------------------------------------------------------------------- Create the hardcopy to hand in by using the same procedure you use in 78/lab (see http://web.mst.edu/~davem/CSc78/lab.assignments/lab1.txt If you don\'t remember how, or if you don\'t have the lab course. See me if you need more help, and I\'ll be glad to explain.) ------------------------------------------------------------------------ Remember to use global constants where appropriate, comment where needed, and indent reasonably for readability. Pick useful names for variables.
Solution
Hope this will help -
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
class CurvedGrading
{
private:
double mean, standard_dev;
public:
CurvedGrading()
{
mean = 89.1;
standard_dev = 99.1;
}
double getMean( double x[], int n )
{
double sum2 = 0;
int j;
for ( j = 0; j < n; j++ )
{
sum2 += x[j];
}
return mean = sum2 / n;
}
void computeStandardDev( double x[], int n )
{
double sum = 0, m;
int k;
m = getMean( x, n );
for ( k = 0; k < n; k++ ) {
sum += pow( x[k] - m, 2.0 );
}
standard_dev = sqrt( sum / n );
}
void displayLetterGrade( double x[], int n )
{
ofstream print;
char lgrade[100];
int p;
print.open(\"p1.out\");
if (print.is_open()){
print << \"Mean: \" << mean << \"\ Standard Deviation: \" << standard_dev << \"\ \ \";
print << \"| STUDENT | NUMERIC_GRADE | LETTER_GRADE | \ \";
for ( p = 0; p < n; p++ ) {
if ( x[p] >= mean + (3 * standard_dev / 2) )
lgrade[p] = \'A\';
else if ( x[p] >= mean + (standard_dev / 2) )
lgrade[p] = \'B\';
else if ( x[p] >= mean - (standard_dev / 2) )
lgrade[p] = \'C\';
else if ( x[p] >= mean - (3 * standard_dev / 2) )
lgrade[p] = \'D\';
else
lgrade[p] = \'F\';
print << setw(6) << p + 1 << setw(14) << x[p] << setw(14) << lgrade[p] << endl;
}
}
else
cout << \"Error opening file. Output filename must be \\\"p1.out\\\"\" << endl;
print.close();
}
};
int main()
{
ifstream read;
CurvedGrading curving;
double scores[100];
int count = 0, i = 0;
read.open(\"p1.in\");
if (read.is_open())
{
while (read >> scores[i])
{
count++;
i++;
}
curving.computeStandardDev( scores, count );
cout << \"\ File successfully opened and processed. Check \\\"p1.out\\\" for results.\ \ \";
curving.displayLetterGrade( scores, count );
}
else
cout << \"\ Error opening file. Input filename must be \\\"p1.in\\\"\ \ \";
read.close();
return 0;
}

