GPA homework
Develop a program that calculates Grade Point Average (GPA) for students. A grade of A is worth 4 points, B is worth 3 points, C is worth 2 points, D is worth 1 points and F is worth 0 points. Grades other than A, B, C, D, and F should not be calculated in GPA. When a grade is entered for a course, credit hours for that course should also be entered so that the GPA can be calculated correctly. For example, if a student has taken 3 courses and earned the following grades:
Course Grade Credit Hours
1 A 3.0
2 B 4.5
3 A 1.0
The student's GPA should be calculated as
GPA = (4.0*3.0 + 3.0 * 4.5 + 4.0*1.0) / (3.0+4.5+1.0)
A student can take up to 5 courses. Only A, B, C, D, F, W, P are allowed for grade
//Purpose: calculate student's gpa
//Programmer:
//Input:
//-- grade1, grad2, grade3, grade4, grade5
//-- hours1, hours2, hours3, hours4, hours5
//-- many (courses), (more) student
//Output: gpa
//Algorithm:
//1. ask how many courses the student take
//2. get all class information
//3. convert grade to points
//4. calculate gpa
//5. diplay gpa
#include <iostream>
#include <string>
using namespace std;
//------------ Algorithm 8: not use loop to process courses, switch convert --------
int main()
{
//declaration and initialization
//??????????? what variables still need to be declared and intialized??????
char grade1, grade2, grade3, grade4, grade5; //letter grades for classes
double hours1, hours2, hours3, hours4, hours5; // credit hours of classes
char student; //Y if more student to process
double gpa; //final gpa
double totalgp, totalhrs; //total grade points, total credit hours
grade1=grade2=grade3=grade4=grade5 = student = ' ';
hours1=hours2=hours3=hours4=hours5 = -1;
gpa = -9999;
totalgp = totalhrs = -999;
//============ do this outer do...while AFTER you complete everything else =======
//do
//{
//========================================================================
//1. Ask how many courses the student takes
//!!!!! DON't FORGET INPUT VALIDATION !!!!!
// ????????? your code ????????
//2. get class information and 3. convert letter grade to calculate weighted grade points
// if (many == 1) **** remove // after many is declared *******
{
//?????????? input validation ???????
cout << "Class letter grade (A, B, C, D, F, W, P ONLY): ";
cin >> grade1;
//?????????? input validation ?????
cout << "Class credit hours (example 3.5): ";
cin >> hours1;
//!!!!!!!!!!!!!!!!! convert letter to points!!!!!!!!
//????????? complete the switch ... case below accordingly ?????
//switch (grade1)
{ //start of switch for converting letter grade to grade points
} //end of switch for converting letter grade to grade points
//
}
// ??????? more code for many == 2, many == 3, etc
//4. calculate gpa
// DON'T FORGET ONLY CERTAIN GRADES SHOULD BE CALCULATED IN GPA
// if (gp1>0) ****** remove // after gp1 is declared
{
// totalgp = totalgp + gp1; ***** remove // after gp1 is declared ****
totalhrs=totalhrs+hours1;
}
// ???? more for gp2, gp3, etc
gpa = totalgp / totalhrs;
//5. diplay gpa
//?????????? missing code ???????
//????????? input validation ???????
cout << "More students to process? (Y or N): ";
cin >> student;
//=================DO THIS OUTER DO.. WHILE LAST===========
//} while (student == 'Y' || student == 'y');
//================================
return 0;
}
12 years ago
Purchase the answer to view it

- answer.zip