A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. Write a program that uses this method to calculate a contestant’s score. It should include the following functions: - void getJudgeData () should ask the user for a judge’s score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges. - void calcScore () should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores. The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop. - int findLowest () should find and return the lowest of the five scores passed to it. - int findHighest () should find and return the highest of the five scores passed to it. Input Validation: Do not accept judge scores lower than 0 or higher than 10.

Respuesta :

Answer:

//function format/ prototype

void call/getJudgeData(double &performanceScore);

void calcScore(double, double, double, double, double);

double findLowest(double, double, double, double, double);

double findHighest(double, double, double, double, double);

int main()

//declare variable to store user input

//for 5 judge scores

double score1, score2, score3, score4, score5;

//call function call/getJudgeData() 5 times

Call/getJudgeData(score1);

Call/getJudgeData(score2);

Call/getJudgeData(score3);

Call/getJudgeData(score4);

Call/getJudgeData(score5);

//call function calcScore() to display average

calcScore(score1, score2, score3, score4, score5);

//return 0 to mark successful termination of program

return 0;

void call/getJudgeData(double &performanceScore){

//prompt user to enter score and read

//from keyboard

cout << "Please enter performance score: (0-10)\n";

cin >> performanceScore;

//validate input using while loop

while(performanceScore < 0 || performanceScore > 10){

//print error message

cout << "Please enter score within range!\n";

cin >> performanceScore;

void calcScore(double score1, double score2, double score3, double score4, double score5){

//format output precision

cout << fixed << setprecision(2);

//print output message directly and call findLowest() and findHighest() directly

//divide by 3.0 to prevent integer division

cout << "Average of the 3 scores is ";

cout << ((score1+score2+score3+score4+score5)-findLowest(score1, score2, score3, score4, score5)-

findHighest(score1, score2, score3, score4, score5))/3.0 << ".\n";

double findLowest(double score1, double score2, double score3, double score4, double score5){

//use if/else statements to find lowest

//score and return it

if(score1 < score2 & score1 < score3 & score1 < score4 & score1 < score5)

return score1;

else if(score2 < score1 & score2 < score3 & score2 < score4 & score2 < score5)

return score2;

else if(score3 < score1 &score3 < score2&score3 < score4 & score3 < score5)

return score3;

else if(score4 < score1 & score4 < score2 & score4 < score3 &score4 < score5)

return score4;

else if(score5 < score1 & score5 < score2 & score5 < score3 & score5 < score4)

return score5;

}

double findHighest(double score1, double score2, double score3, double score4, double score5){

//use if/else statements to find highest

//score and return it

if(score1 > score2 & score1 > score3 & score1 > score4 & score1 > score5)

return score1;

else if(score2 > score1 & score2 > score3 & score2 > score4 & score2 > score5)

return score2;

else if(score3 > score1 & score3 > score2 & score3 > score4 & score3 > score5)

return score3;

else if(score4 > score1 & score4 > score2 & score4 > score3 & score4 > score5)

return score4;

else if(score5 > score1 & score5 > score2 & score5 > score3 & score5 > score4)

return score5;

}

Otras preguntas