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
|
//main implementation
#include <iostream>
#include "TestScores.h"
using namespace std;
void menu();
int main ()
{
const int NUMOFSCORES = 10;
int userinput;
double goodScoresArray[NUMOFSCORES] = {92, 84, 98, 72, 77, 68, 88, 94, 96, 59};
double tooLowScoresArray[NUMOFSCORES] = {-92, 84, 98, 72, 77, 68, 88, 94, 96, 59};
double tooHighScoresArray[NUMOFSCORES] = {192, 84, 98, 72, 77, 68, 88, 94, 96, 59};
TestScores myGoodTests(goodScoresArray);
TestScores myNegativeTest(tooLowScoresArray);
TestScores myHighTest(tooHighScoresArray);
menu();
cin >> userinput;
switch (userinput)
{
case 1:
cout << "This is the normal array. The average of the scores is: " << myGoodTests.getAverage() << endl;
menu();
break;
case 2 :
try
{
cout << "This is the negative array. " << myNegativeTest.getAverage() << endl;
}
catch(TestScores::NegativeScore)
{
cout << "Negative Score entered!";
}
case 3:
try
{
cout << "This is the array with a number larger than 100. " << myHighTest.getAverage() << endl;
}
catch(TestScores::TooLargeScore)
{
cout <<"Score greater than 100 entered!";
}
}
return 0;
}
void menu()
{
cout << " Please indicate which demonstration you would like to perform.\n";
cout << " Enter the appropriate item number.\n\n\n";
cout << "1. Demonstrate valid array triggering no exceptions\n";
cout << "2. Demonstrate a negative test score by throwing the NegativeScore Exception\n";
cout << "3. Deomstrate a score larger than 100 by throwing TooLargeScore Exception\n";
cout << "4. Quit the program\n\n";
}
|