Advertisement
Guest User

CSC5HELPPLEASE

a guest
Oct 23rd, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. /*****************************************************************
  2.  * AUTHOR        : Joseph De Ruyter
  3.  * ASSIGNMENT #1 : Basic Input / Output
  4.  * CLASS         : CSC5
  5.  * SECTION       : MW 2:20p - 5:30p
  6.  * DUE DATE      : 9/18/2019
  7.  ****************************************************************/
  8.  
  9. #include <iostream>
  10. #include <iomanip>
  11. using namespace std;
  12.  
  13. /****************************************************************
  14.  * COMPUTE GPA
  15.  * ______________________________________________________________
  16.  * This program takes user inputed grades and converts them
  17.  * to an integer, 0 through 4, based on the grade. The program
  18.  * then calculates the grade point average based on the amount
  19.  * of grades submitted. If no grades are submitted, nothing
  20.  * will output.
  21.  *
  22.  * ______________________________________________________________
  23.  * INPUT
  24.  *   Grade           : Users grade
  25.  *   X               : Sentinel value to stop the program
  26.  *   x               : Sentinel value to stop the program
  27.  *
  28.  * OUTPUT
  29.  *   totalGrade      : Total number of grade points
  30.  *   gpa             : Grade point average of all grades
  31.  *
  32.  *
  33.  ****************************************************************/
  34. int main()
  35. {
  36.     // Declare constants
  37.     const float A = 4;
  38.     const float B = 3;
  39.     const float C = 2;
  40.     const float D = 1;
  41.     // Declare variables
  42.     int count;
  43.     char grade;
  44.     int totalGrade;
  45.     float gpa;
  46.     float numberOfGrades;
  47.  
  48.     // Display header
  49.             cout << "***********************************************" << endl;
  50.             cout << "* PROGRAMMED BY : Joseph De Ruyter"              << endl;
  51.             cout << "* CLASS    : CSC5"                               << endl;
  52.             cout << "* SECTION  : MW 2:20p-5:30p"                     << endl;
  53.             cout << "* PROJECT #2    : Repetition & Switch Statement" << endl;
  54.             cout << "***********************************************" << endl;
  55.             cout << endl;
  56.     // For loop (repeat 3 times)
  57.     for (count = 1; count <= 3; count++)
  58.     {
  59.             // Reset variables for loop
  60.             totalGrade = 0;
  61.             numberOfGrades = 0;
  62.             // Output test header
  63.             cout << "Test # " << count << ":" << endl << endl;
  64.             cout << "\tEnter Letter Grade(enter 'X' to exit): ";
  65.             cin >> grade;
  66.         // While loop (continue until sentinel value)
  67.         while(grade != 'x' && grade != 'X')
  68.         {
  69.             // Statement to assign grades a value
  70.             switch (grade)
  71.             {
  72.                 case 'A':
  73.                 case 'a': totalGrade += A; numberOfGrades += 1;
  74.                     break;
  75.                 case 'B':
  76.                 case 'b': totalGrade += B; numberOfGrades += 1;
  77.                     break;
  78.                 case 'C':
  79.                 case 'c': totalGrade += C; numberOfGrades += 1;
  80.                     break;
  81.                 case 'D':
  82.                 case 'd': totalGrade += D; numberOfGrades += 1;
  83.                     break;
  84.                 case 'F':
  85.                 case 'f': numberOfGrades += 1;
  86.                     break;
  87.                 default: cout << "\n\tInvalid letter grade, "
  88.                                  "please try again\n" << endl;
  89.             }
  90.             // Ask for another grade
  91.             cout << "\tEnter Letter Grade(enter 'X' to exit): ";
  92.             cin >> grade;
  93.         }
  94.         // Declare grade point average (gpa)
  95.         gpa = (totalGrade/numberOfGrades);
  96.         // If statement to check division by zero (no grades)
  97.         if (numberOfGrades > 0)
  98.         {
  99.             cout << "\nTotal Grade Points: " << totalGrade << endl;
  100.             cout << "GPA: " << setprecision(2) << fixed << gpa;
  101.             cout << endl << endl << endl;
  102.         }
  103.     }
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement