Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************
- * AUTHOR : Joseph De Ruyter
- * ASSIGNMENT #1 : Basic Input / Output
- * CLASS : CSC5
- * SECTION : MW 2:20p - 5:30p
- * DUE DATE : 9/18/2019
- ****************************************************************/
- #include <iostream>
- #include <iomanip>
- using namespace std;
- /****************************************************************
- * COMPUTE GPA
- * ______________________________________________________________
- * This program takes user inputed grades and converts them
- * to an integer, 0 through 4, based on the grade. The program
- * then calculates the grade point average based on the amount
- * of grades submitted. If no grades are submitted, nothing
- * will output.
- *
- * ______________________________________________________________
- * INPUT
- * Grade : Users grade
- * X : Sentinel value to stop the program
- * x : Sentinel value to stop the program
- *
- * OUTPUT
- * totalGrade : Total number of grade points
- * gpa : Grade point average of all grades
- *
- *
- ****************************************************************/
- int main()
- {
- // Declare constants
- const float A = 4;
- const float B = 3;
- const float C = 2;
- const float D = 1;
- // Declare variables
- int count;
- char grade;
- int totalGrade;
- float gpa;
- float numberOfGrades;
- // Display header
- cout << "***********************************************" << endl;
- cout << "* PROGRAMMED BY : Joseph De Ruyter" << endl;
- cout << "* CLASS : CSC5" << endl;
- cout << "* SECTION : MW 2:20p-5:30p" << endl;
- cout << "* PROJECT #2 : Repetition & Switch Statement" << endl;
- cout << "***********************************************" << endl;
- cout << endl;
- // For loop (repeat 3 times)
- for (count = 1; count <= 3; count++)
- {
- // Reset variables for loop
- totalGrade = 0;
- numberOfGrades = 0;
- // Output test header
- cout << "Test # " << count << ":" << endl << endl;
- cout << "\tEnter Letter Grade(enter 'X' to exit): ";
- cin >> grade;
- // While loop (continue until sentinel value)
- while(grade != 'x' && grade != 'X')
- {
- // Statement to assign grades a value
- switch (grade)
- {
- case 'A':
- case 'a': totalGrade += A; numberOfGrades += 1;
- break;
- case 'B':
- case 'b': totalGrade += B; numberOfGrades += 1;
- break;
- case 'C':
- case 'c': totalGrade += C; numberOfGrades += 1;
- break;
- case 'D':
- case 'd': totalGrade += D; numberOfGrades += 1;
- break;
- case 'F':
- case 'f': numberOfGrades += 1;
- break;
- default: cout << "\n\tInvalid letter grade, "
- "please try again\n" << endl;
- }
- // Ask for another grade
- cout << "\tEnter Letter Grade(enter 'X' to exit): ";
- cin >> grade;
- }
- // Declare grade point average (gpa)
- gpa = (totalGrade/numberOfGrades);
- // If statement to check division by zero (no grades)
- if (numberOfGrades > 0)
- {
- cout << "\nTotal Grade Points: " << totalGrade << endl;
- cout << "GPA: " << setprecision(2) << fixed << gpa;
- cout << endl << endl << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement