1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <iostream>
#include <string>
using namespace std;
void getStudInfo(string& fname, string& lname, float& exam1, float& exam2, float& exam3);
float calGPA(int exam1, int exam2, int exam3);
void dispLetterGrade(string fname, string lname, float GPA, char grade);
int main()
{
int numStud, i;
float studAvg, exam1, exam2, exam3;
char grade;
string fname, lname;
i = 0;
cout << "How many students are in the class? ";
cin >> numStud;
while(i < numStud)
{
getStudInfo(fname, lname, exam1, exam2, exam3);
studAvg = calGPA(exam1, exam2, exam3);
dispLetterGrade(fname, lname, studAvg, grade);
i = i + 1;
}
system("PAUSE");
return 0;
}
void getStudInfo(string& fname, string& lname, int& exam1, int& exam2, int& exam3)
{
cout << "Enter student's first name: ";
cin >> fname;
cout << "Enter student's last name: ";
cin >> lname;
cout << "Enter the score for exam 1: ";
cin >> exam1;
if(exam1 >= 0 || exam1 <= 110)
{
cout << "Sorry that is not a valid entry \n Enter the score for exam 1: ";
cin >> exam1;
}
cout << "Enter the score for exam 2: ";
cin >> exam2;
if(exam2 >= 0 || exam2 <= 110)
{
cout << "Sorry that is not a valid entry \n Enter the score for exam 2: ";
cin >> exam2;
}
cout << "Enter the score for exam 3: ";
cin >> exam3;
if(exam3 >= 0 || exam3 <= 100)
{
cout << "Sorry that is not a valid entry \n Enter the score for exam 3: ";
cin >> exam3;
}
}
float calGPA(int exam1, int exam2, int exam3)
{
float calGPA;
calGPA = (exam1 + exam2 + exam3)/3;
return calGPA;
}
void dispLetterGrade(string fname, string lname, float studAvg, char grade)
{
if (studAvg >= 90)
{
grade = 'A';
}
else if (studAvg >= 80)
{
grade = 'B';
}
else if (studAvg >= 70)
{
grade = 'C';
}
else if (studAvg >= 60)
{
grade = 'D';
}
else if (studAvg >= 59)
{
grade = 'F';
}
else
cout << "Invalid test score.\n";
cout << fname << " " << lname << endl << studAvg << " " << grade << endl;
}
|