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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double programavg = 0;
double programscores = 0;
double programmax;
double quizavg = 0;
double quizscores = 0;
double quizmax;
double testavg = 0;
double testscores = 0;
double testmax;
char choicemore = 'y';
double examavg;
double overallavg;
/* This is the getIntSum function */
int getIntSum(string s, int exitVal)
{
int addpoints;
int totalpoints = 0;;
while (addpoints!=exitVal)
{
cout << s << exitVal << " to quit):";
cin >> addpoints;
totalpoints+=addpoints;
}
cout << endl;
return totalpoints;
}
/* This is the getPromptedInt function */
int getPromptedInt(string s, int min, int max)
{
int maxpoints;
cout << s << min << "..." << max << "):";
cin >> maxpoints;
cout << endl;
while (maxpoints>max || maxpoints<min)
{
cout << "Error: value must be between "
<< min << " and " << max << ". Please re-enter:";
cin >> maxpoints;
cout << endl;
}
return maxpoints;
}
/*This is the calcScore function */
double calcScore(double sum, double maxPoss)
{
double finalscore;
if (maxPoss>0)
{
finalscore = (sum / maxPoss);
finalscore*=100;
return finalscore;
}
else
{
return 0;
}
}
/* This is the main function --------------------*/
int main()
{
/* This loop is for the purpose of repeating while the user wants to */
while (choicemore=='y')
{
programmax = getPromptedInt("Enter the maximum possible program points (", 0, 1200);
programscores = getIntSum("Enter a program score (", -1);
quizmax = getPromptedInt("Enter the maximum possible quiz points (", 0, 120);
quizscores = getIntSum("Enter a quiz score (", -1);
testmax = getPromptedInt("Enter the maximum possible test points (", 0, 300);
testscores = getIntSum("Enter a test score (", -1);
programavg = calcScore(programscores, programmax);
quizavg = calcScore(quizscores, quizmax);
testavg = calcScore(testscores, testmax);
cout << fixed << setprecision(2) << "Program average is: " << programavg;
cout << fixed << setprecision(2) << endl << "Quiz average is " << quizavg;
cout << fixed << setprecision(2) << endl << "Test average is: " << testavg;
// The following loop is to calculate the exam average
if (testavg==0)
{
examavg = quizavg;
cout << setprecision(2) << fixed << endl << "Exam average is: " << examavg;
}
else
{
examavg = ((((testavg * 3) + quizavg)) / 4);
cout << setprecision(2) << fixed << endl << "Exam average is: " << examavg;
}
// This loop is for displaying the Overall average
if (testavg==0)
{
overallavg = ((.6*quizavg) + (.4*programavg));
cout << endl << "Overall average is: " << overallavg;
}
else
{
overallavg = ((.4*programavg) + (.15*quizavg) + (.45*testavg));
cout << endl << "Overall average is: " << overallavg;
}
// This next loop is the warning message for low test scores
if (examavg<55)
{
cout << endl << endl << "*** Your exam average is below 55%! ***" << endl;
}
else
{
cout << endl;
}
cout << endl << "Another (y/n)? ";
cin >> choicemore;
cout << endl;
}
return 0;
}
| |