The following code outputs this example include using namesp
The following code outputs this example:
#include
using namespace std;
 int main()
 {
    int grade;   // letter grade entered by user
    int aCount = 0; // count of A grades
    int bCount = 0;   // count of B grades
    int cCount = 0; // count of C grades
    int dCount = 0; // count of D grades
    int fCount = 0; // count of F grades
   cout << \"Enter the letter grades.\" << endl
        << \"Enter the EOF character to end output.\" << endl;
       //loop until user types end of file key sequence
        while ((grade = cin.get()) != EOF)
        {
        //determine which grade was entered
            switch ( grade ) // switch statement inside nested loop
            {
            case \'A\': // grade was uppercase A
            case \'a\': // or lowercase a
                aCount++; //increment aCount
                break; // exit switch
           
            case \'B\':
            case \'b\':
                bCount++;
                break;
           case \'C\':
            case \'c\':
                cCount++;
                break;
           case \'D\':
            case \'d\':
                dCount++;
                break;
           case \'F\':
            case \'f\':
                fCount++;
                break;
           case \'\ \':
            case \'\\t\':
            case \' \' :
                break;
                   
            default:
                cout << \"Incorrect letter grade entered.\"
                    << \"Enter new grade.\" << endl;
                            break;
 } // end switch
        } // end while
    //output results
    cout << \"\ \ Number of students who recieved each letter grade.\"
        << \"\ A: \" << aCount
        << \"\ B: \" << bCount
        << \"\ C: \" << cCount
        << \"\ D: \" << dCount
        << \"\ F: \" << fCount
        << endl;
From what I am understanding, the task is to modify this code so that it will calculate the total gpa of the infromation entered by the user. All of the A\'s are 4, all of the B\'s are 3, all of the C\'s are 2, all of the D\'s are 1, and all of the F\'s are 0. The out put adds the A\'s then divides by the number of entries...same for the rest of the grades.
Enter the letter grades. AZ Number of students who recieved each letter grade. A: 3 B: 2 C: 3 D:2 Press any key to continue . . .Solution
Please find the modified code below, with its output. Please find the comments.
#include <iostream>
 #include <string>
using namespace std;
int main()
 {
 int grade; // letter grade entered by user
 int aCount = 0; // count of A grades
 int bCount = 0; // count of B grades
 int cCount = 0; // count of C grades
 int dCount = 0; // count of D grades
 int fCount = 0; // count of F grades
 cout << \"Enter the letter grades.\" << endl
 << \"Enter the EOF character to end output.\" << endl;
 //loop until user types end of file key sequence
 while ((grade = cin.get()) != EOF)
 {
 //determine which grade was entered
 switch ( grade ) // switch statement inside nested loop
 {
 case \'A\': // grade was uppercase A
 case \'a\': // or lowercase a
 aCount++; //increment aCount
 break; // exit switch
   
 case \'B\':
 case \'b\':
 bCount++;
 break;
 case \'C\':
 case \'c\':
 cCount++;
 break;
 case \'D\':
 case \'d\':
 dCount++;
 break;
 case \'F\':
 case \'f\':
 fCount++;
 break;
 case \'\ \':
 case \'\\t\':
 case \' \' :
 break;
   
 default:
 cout << \"Incorrect letter grade entered.\"
 << \"Enter new grade.\" << endl;
 break;
 } // end switch
 } // end while
 //output results
 cout << \"\ \ Number of students who recieved each letter grade.\"
 << \"\ A: \" << aCount
 << \"\ B: \" << bCount
 << \"\ C: \" << cCount
 << \"\ D: \" << dCount
 << \"\ F: \" << fCount
 << endl;
 
 double totalgpa = ((aCount*4)+(bCount*3)+(cCount*2)+(dCount*1)+(fCount*0))/(aCount+bCount+cCount+dCount+fCount); //find total gpa by multiplying each enrtry with its point and divide total by no:of entries
   
 cout << \"Total Gpa = \" << (double)totalgpa << endl;
 }
------------------------------------------------
OUTPUT:
Enter the letter grades.
 Enter the EOF character to end output.
 a
 B
 c
 C
 A
 d
 f
 C
 D
 A
 b
 1
 Number of students who recieved each letter grade.
 A: 3
 B: 2
 C: 3
 D: 2
 F: 1
 Total Gpa = 2



