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
|
#include <iostream>
#include "TestScores.h"
using namespace std;
int main()
{
// Test program with and without the exceptions
// First test will be normal array
int marks1[] = {79, 89, 86, 100, 82, 94, 73 };
testAvg(5, marks1);
// Next, test the array with a negative test grade
int marks2[] = {40, -60, 70 };
testAvg(3, marks2);
//Finally, test the array with a grade over 100
int marks3[] = {140, 30};
testAvg(2, marks3);
return 0;
}
//******************************************************************************
// The testAvg function will accept an array of grades as an argument *
// and will return the average of those grades. *
//******************************************************************************
void testAvg(int len, int marks[])
{
TestScores test(len, marks);
int result = 0;
try
{
result = test.getAvg();
cout << "The average of the test are: " << result << endl;
}
catch(char * err)
{
cout << err << "\n";
}
}
|