/* Lowest Score Drop - This program calculates the average of a group oftest scores, where the lowest score in the group is dropped. It usesthe following functions:* void getScore()* void calcAverage()* int findLowest()Input Validation: No test scores lower than 0 or higher than 100 areaccepted. */#include "Utility.h"/* Prototypes: Get score, Calculate average, Find lowest */void getScore(int &);void calcAverage (int, int, int, int, int);int findLowest (int, int, int, int, int);int main(){/* Variables: Scores 1 through 5 */int scoreOne = 0,scoreTwo = 0,scoreThree = 0,scoreFour = 0,scoreFive = 0;/* Display: Information */cout << "\t\tAverage Test Score Calculator\n\n"<< "This application allows you to enter five test scores,\n"<< "to find the lowest score, which will be dropped, before\n"<< "the average is calculated and displayed.\n\n";/* Call: getScore, the values are stored in scoreOne through scoreFive */getScore(scoreOne);getScore(scoreTwo);getScore(scoreThree);getScore(scoreFour);getScore(scoreFive);/* Call: calcAverage */calcAverage(scoreOne, scoreTwo, scoreThree, scoreFour, scoreFive);pauseSystem();return 0;}/* **********************************************************Definition: getScoreThis function asks the user for a test score, stores it ina reference parameter variable, and validates it. It iscalled by main once for each of the five scores entered.********************************************************** */void getScore(int &scores){static int cnt = 1;/* Get: Scores */cout << "Please Enter Test Score " << (cnt++) << ": ";cin >> scores;/* Validation: If the user enters a number lower than 1or greater than 100, he or she will receive a messageand be asked to enter the score again */while (scores < 0 || scores > 100){cout << "\nIt seems that you have entered a number that\n"<< "was below 1 or above 100. Please enter a valid\n"<< "test score " << (cnt - 1) << ": ";cin >> scores;}}/* **********************************************************Definition: calcAverageThis function calculates and displays the average of thefour highest scores. It is called once by main and getspassed the five test scores.********************************************************** */void calcAverage(int avgScoreOne, int avgScoreTwo, int avgScoreThree,int avgScoreFour, int avgScoreFive){/* Variables: Average score, Drop lowest */int avgScore = 0,dropLowest = 0;/* Call: findLowest, pass the test scores as arguments, and getthe lowest test score */dropLowest = findLowest(avgScoreOne, avgScoreTwo, avgScoreThree,avgScoreFour, avgScoreFive);/* Calculate: The average test score */avgScore = (avgScoreOne + avgScoreTwo + avgScoreThree +avgScoreFour + avgScoreFive - dropLowest) / 4;/* Display: The formatted average test score */cout << "\nYour average test score is: " << avgScore << endl;}/* **********************************************************Definition: findLowestThis function finds and returns the lowest of the fivescores passed to it. It is called by calcAverage, whichuses the function to determine which of the five scoresto drop.********************************************************** */int findLowest(int lowestScoreOne, int lowestScoreTwo,int lowestScoreThree, int lowestScoreFour,int lowestScoreFive){/* Variable: Lowest score initialized to lowestScoreOne */int lowestScore = lowestScoreOne;/* These conditional statements determine the lowest test score */lowestScore = lowestScoreTwo < lowestScore ? lowestScoreTwo : lowestScore;lowestScore = lowestScoreThree < lowestScore ? lowestScoreThree : lowestScore;lowestScore = lowestScoreFour < lowestScore ? lowestScoreFour : lowestScore;lowestScore = lowestScoreFive < lowestScore ? lowestScoreFive : lowestScore;/* Display: The lowest score that will be dropped */cout << "\nThe lowest test score out of five was " << lowestScore<< "\nand will be dropped from the calculation.\n";/* Return: The lowest test score */return lowestScore;}
Thursday, January 5, 2017
Programming Challenge 6.11 - Lowest Score Drop
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment