steamengines

grade average program

Nov 6th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1330 - 003
  3. //This program should calculate students weighted averages.
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. double averageGrade(double &);
  9. double classAverage(double &, double, double, double);
  10. void getLetterGrade(char &, double);
  11. void displayGradeReport(double, double, double, double, char);
  12.  
  13.  
  14.  
  15. int main()
  16. {
  17.     double labAverage = 0.0;
  18.     double testAverage = 0.0;
  19.     double projectAverage = 0.0;
  20.     double finalAverage = 0.0;
  21.     char letterGrade = ' ';
  22.     char loopQ = ' ';
  23.     letterGrade = toupper(letterGrade);//Keeping the characters entered uppercase.
  24.     cout << fixed << setprecision(2);//Just putting this here so it doesn't get in the way.
  25.  
  26.     do//Where the loop will start.
  27.     {
  28.         cout << "Please enter your lab grades." << endl;
  29.         averageGrade(labAverage);//Calls the averageGrade function.
  30.         system("cls");
  31.         cout << "Your lab average is " << labAverage << endl << endl;
  32.  
  33.         cout << "Please enter your test grades." << endl;
  34.         averageGrade(testAverage);//Calling the averageGrade function once again.
  35.         system("cls");
  36.         cout << "Your test average is " << testAverage << endl << endl;
  37.  
  38.         cout << "Please enter your project grades." << endl;
  39.         averageGrade(projectAverage);//Calling th averageGrade function AGAIN!.
  40.         system("cls");
  41.  
  42.         finalAverage = classAverage(finalAverage, labAverage, testAverage, projectAverage);//Calling the classAverage function, and also sending some variables.
  43.  
  44.         getLetterGrade(letterGrade, finalAverage);//Calling this function will give us a letter grade.
  45.  
  46.         displayGradeReport(labAverage, testAverage, projectAverage, finalAverage, letterGrade);//This function will display everything.
  47.        
  48.         cout << "Would you like to enter data for a new student? " << endl; //posttest loop
  49.         cin >> loopQ;
  50.         system("cls");
  51.     } while (loopQ == 'y');
  52.     if (loopQ == 'n')
  53.     {
  54.         cout << "Thank you for using this program!" << endl;
  55.     }
  56.  
  57.     system("pause");
  58.     return 0;
  59. }
  60.  
  61. double averageGrade(double &gradeAverage)
  62. {
  63.     double grades = 0.0;
  64.     int numGrades = 0;
  65.     double sum = 0.0;
  66.     char loopies = 'Y'; //Kind of like the primeread.
  67.  
  68.     do
  69.     {
  70.         cin >> grades;
  71.         numGrades++; //Acumulator
  72.         sum = grades + sum;
  73.         cout << "Would you like to enter more grades? (Y/N)";//This is really annoying but the only way I found to do this.
  74.         cin >> loopies;
  75.         loopies = toupper(loopies);
  76.  
  77.         switch (loopies) { //Switch to determine what to do if they have no more grades.
  78.         case 'N':
  79.             gradeAverage = sum / numGrades;
  80.         }
  81.  
  82.     } while (loopies == 'Y'); //End of the loops.
  83.     return gradeAverage;
  84. }
  85.  
  86. double classAverage(double &averageClass, double labAverage, double testAverage, double projectAverage)
  87. {
  88.     double const LAB_WEIGHT = .50;
  89.     double const TEST_WEIGHT = .40;
  90.     double const PROJECT_WEIGHT = .10;
  91.  
  92.     averageClass = (labAverage * LAB_WEIGHT) + (testAverage * TEST_WEIGHT) + (projectAverage * PROJECT_WEIGHT);
  93.  
  94.  
  95.     return averageClass;
  96. }
  97.  
  98. void getLetterGrade(char &gradeLetter, double finalAverage)
  99. {
  100.     if (finalAverage >= 90.00)
  101.     {
  102.         gradeLetter = 'A';
  103.     }
  104.     else if (finalAverage >= 80.00 && finalAverage < 90.00)
  105.     {
  106.         gradeLetter = 'B';
  107.     }
  108.     else if (finalAverage >= 70.00 && finalAverage < 80.00)
  109.     {
  110.         gradeLetter = 'C';
  111.     }
  112.     else if (finalAverage >= 60.00 && finalAverage < 70.00)
  113.     {
  114.         gradeLetter = 'D';
  115.     }
  116.     else
  117.     {
  118.         gradeLetter = 'F';
  119.     }
  120. }
  121.  
  122. void displayGradeReport(double averageLab, double averageTest, double averageProject, double averageFinal, char gradeLetter)
  123. {
  124.     cout << "Your lab average is     " << averageLab << endl;
  125.     cout << "Your test average is    " << averageTest << endl;
  126.     cout << "Your project average is " << averageProject << endl << endl;
  127.     cout << "Your overall class average is " << averageFinal << endl;
  128.     cout << "You currently have a " << gradeLetter << " in this class." << endl << endl;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment