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
|
//Pre-processor Directive
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//Constant Variables
const int NUM_TESTS = 2;
const string LINE = "----------------------------------------------------------------\n";
const string CALL = "Enter a test score between 0 and 100: ";
//Function prototypes
void getTestScore(int&);
void calcAvgAndDisplayResult(int, int, int); //5b
int findAndReturnLowest(int, int, int);//5ci
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()
{
//Variables
int score1, score2, score3;
//Function Calls
getTestScore(score1);//5ai
getTestScore(score2);//5ai
getTestScore(score3);//5ai
cout << LINE;
calcAvgAndDisplayResult(score1, score2, score3); //5bi
cout << LINE;
system("pause");
return 0;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void getTestScore(int& score) {
cout << CALL;
cin >> score;
}
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void calcAvgAndDisplayResult(int score1, int score2, int score3)
{
//Get lowest score.
int lowest = findAndReturnLowest(score1, score2, score3);//5cii
cout << "Lowest test score: "<< lowest <<endl;
float average = static_cast <float>(score1 + score2 + score3 - lowest) / NUM_TESTS;
cout << "Average test score (after dropping the lowest score) = " << average<<endl;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
The findAndReturnLowest function finds and returns
the lowest of the three scores passed to it
*/
int findAndReturnLowest(int score1, int score2, int score3)
{
int lowest = score1;
//Determine lowest score
if (score2 <= score1 && score2 <= score3)
lowest = score2;
if (score3 <= score1 && score3 <= score2)
lowest = score3;
return lowest;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|