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
|
#include <iostream>
#include <iomanip>
using namespace std;
double averageGrade();
double classAverage(double labAvg, double testAvg, double projectAvg);
void getLetterGrade(double totalAvg, char &letterGrade);
void displayGradeReport(double labAvg, double testAvg, double projectAvg, double totalAvg, char letterGrade);
int main()
{
//Variables
double average = 0.0;
double labAvg = 0.0;
double testAvg = 0.0;
double projectAvg = 0.0;
double totalAvg = 0.0;
char letterGrade = ' ';
char yesNo = ' ';
do
{
//Input Section
cout << "Enter the student's lab grades below." << endl << endl;
average = averageGrade();
labAvg = average;
cout << "Enter the student's test grades below." << endl << endl;
average = averageGrade();
testAvg = average;
cout << "Enter the student's project grades below." << endl << endl;
average = averageGrade();
projectAvg = average;
totalAvg = classAverage(labAvg, testAvg, projectAvg);
cout << endl;
//Display Section
displayGradeReport(labAvg, testAvg, projectAvg, totalAvg, letterGrade);
cout << "Do you want to enter data for a new student? (Y/N): ";
cin >> yesNo;
yesNo = toupper(yesNo);
} while (yesNo == 'Y');
cout << endl;
system("pause");
return 0;
}
double averageGrade()
{
double grade = 0.0;
double gradeTotal = 0.0;
int totalWorks = 0;
double average = 0.0;
cout << "Enter the first grade (-1 to exit): ";
cin >> grade;
while (grade != -1)
{
gradeTotal += grade;
totalWorks++;
cout << "Enter the next grade (-1 to exit): ";
cin >> grade;
}
cout << endl;
average = gradeTotal / totalWorks;
return average;
}
double classAverage(double labAvg, double testAvg, double projectAvg)
{
double totalAvg = 0.0;
labAvg *= 0.5;
testAvg *= 0.4;
projectAvg *= 0.1;
totalAvg = labAvg + testAvg + projectAvg;
return totalAvg;
}
void getLetterGrade(double totalAvg, char &letterGrade)
{
if (totalAvg >= 90)
{
char letterGrade = 'A';
}
else if (totalAvg < 90 && totalAvg >= 80)
{
char letterGrade = 'B';
}
else if (totalAvg < 80 && totalAvg >= 70)
{
char letterGrade = 'C';
}
else if (totalAvg < 70 && totalAvg >= 60)
{
char letterGrade = 'F';
}
}
void displayGradeReport(double labAvg, double testAvg, double projectAvg, double totalAvg, char letterGrade)
{
cout << "Lab average: " << labAvg << endl;
cout << "Test average: " << testAvg << endl;
cout << "Project average: " << projectAvg << endl;
cout << "Class average: " << totalAvg << endl;
cout << "Letter grade: " << letterGrade << endl;
cout << endl;
}
|