Write A Grading Program For A Class
Write A Grading Program For A Class
graded on the basis of ten points. There is one midterm exam and one final exam each graded on the basis of 100 points. The final exam counts for 50% of the grade, the midterm counts for 25% a nd the two quizzes together count for a total of 25%. (do not forget to normaliz e the quiz scores. They should be converted to a percent before they are average d in). Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80 is a C, any grade of 60 or mor e (but less than 70) is a D, and any grade below 60 is an F. the program will re ad in the student's scores and output the student's record, which consist of two quiz and two exam scores as well as the student's average numeric score for the entire course and final letter grade. Define and use a structure for the studen t record. If this is a class assignment, ask your instructor if input/output sho uld be done with keyboard and screen or if it should be done with files. If this is to be done with files, ask your instructor for instructions on file names. /*** ch6p1.cpp ***/ #include <iostream.h> #include <iostream.h> #include <iomanip.h> /*** structure for Student's grades ***/ struct StudentGrade { int quiz1; int quiz2; int midterm; int final; int total; double percent,avg; char letterGrade; }; /*** void void void Prototype declarations ***/ getData(StudentGrade& g); setLetterGrade(StudentGrade& g); format(int n);
#define W(i) setw(17) #define Y(i) setw(10) void main() { StudentGrade g; getData(g); const const const const const double Q_PERCENT = 12.5; double M_PERCENT = 25.0; double F_PERCENT = 50.0; int Q_SCORE = 10; int E_SCORE = 100;
// create struct StudentGrade // get data from user // // // // // percent distribution for quizzes percent distribution for midterm percent distribution for final maximum score possible for quizzes max score possible for exams
// convert numeric score to percentage double q1 = double(g.quiz1) / Q_SCORE * Q_PERCENT; double q2 = double(g.quiz2) / Q_SCORE * Q_PERCENT;
double m = double(g.midterm) / E_SCORE * M_PERCENT; double f = double(g.midterm) / E_SCORE * F_PERCENT; // get total of numeric score and percentage g.total = g.quiz1 + g.quiz2 + g.midterm + g.final; g.percent = q1 + q2 + m + f; // total maximum numeric score and total percentage int tScore = Q_SCORE * 2 + E_SCORE * 2; double tPercent = Q_PERCENT * 2 + M_PERCENT + F_PERCENT; setLetterGrade(g); format(1); cout << endl << endl; // calculate letter grade // format with one precision
// output results cout << Y(i) << "TEST" << Y(i) << "TEST" "GRADE SCORE" << W(i) << "MAXIMUM SCORE" << endl; cout << Y(i) << "PERIOD" << Y(i) << "SCORE" "DISTRIBUTION" << W(i) << "DISTRIBUTION" << endl cout << Y(i) << "Quiz 1" << Y(i) << g.quiz1 q1 << "%" << W(i) << Q_PERCENT << "%" << endl; cout << Y(i) << "Quiz 2" << Y(i) << g.quiz2 q2 << "%" << W(i) << Q_PERCENT << "%" << endl;
<< Y(i) << "SCORE" << W(i) << << endl; << Y(i) << Q_SCORE << W(i) <<
cout << Y(i) << "Midterm" << Y(i) << g.midterm << Y(i) << E_SCORE << W(i) << m << "%" << W(i) << M_PERCENT << "%" << endl; cout << Y(i) << "Final" << Y(i) << g.final f << "%" << W(i) << F_PERCENT << "%" << endl; << Y(i) << E_SCORE << W(i) <<
cout << Y(i) << "____________________________________________________________ ___________\n"; cout << Y(i) << "TOTAL" << Y(i) << g.total .percent << "%" << W(i) << tPercent << "%" << endl; << Y(i) << tScore << W(i) << g
cout << Y(i) << "Average" << Y(i) << (double(g.total) / tScore * tPercent) << "%" << endl; cout << Y(i) << "Grade: " << Y(i) << g.letterGrade << endl; } // end main() ///////////////////////////////////////////////////////////////////// /*** get input from user ***/ void getData(StudentGrade& g) { cout << "Enter Quiz 1 score (maximum is 10): ";
cin >> g.quiz1; cout << "Enter Quiz 2 score (maximum is 10): "; cin >> g.quiz2; cout << "Enter Midterm score (maximum is 100): "; cin >> g.midterm; cout << "Enter Final score (maximum is 100): "; cin >> g.final; /*** force default values if data invalid ***/ g.quiz1 = g.quiz1 > 10 ? 10 : g.quiz1; g.quiz1 = g.quiz1 < 0 ? 0 : g.quiz1; g.quiz2 = g.quiz2 > 10 ? 10 : g.quiz2; g.quiz2 = g.quiz2 < 0 ? 0 : g.quiz2; g.midterm = g.midterm > 100 ? 100 : g.midterm; g.midterm = g.midterm < 0 ? 0 : g.midterm; g.final = g.final > 100 ? 100 : g.final; g.final = g.final < 0 ? 0 : g.final; return ; } // end getData() ///////////////////////////////////////////////////////////////////// /*** computer letter grade ***/ void setLetterGrade(StudentGrade& g) { if (g.percent >= 90.0) g.letterGrade = 'A'; else if (g.percent >= 80.0) g.letterGrade = 'B'; else if (g.percent >= 70.0) g.letterGrade = 'C'; else if (g.percent >= 60.0) g.letterGrade = 'D'; else g.letterGrade = 'F'; } // end setLetterGrade() ///////////////////////////////////////////////////////////////////// /*** format output with decimal precision ***/ void format(int n) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(n); } // end format() /////////////////////////////////////////////////////////////////////