Try Magic Notes and save time.Try it free
Try Magic Notes and save timeCrush your year with the magic of personalized studying.Try it free

Related questions with answers

Question

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 these rules to calculate and display 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.
  • double calcScore() should calculate and return 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.

Two additional 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.

Solutions

Verified
Answered 2 years ago
Step 1
1 of 2
<!-- HTML generated using hilite.me -->
#include <iostream>
#include <iomanip> //to format output
using namespace std;

//function prototype
void 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 getJudgeData() 5 times
getJudgeData(score1);
getJudgeData(score2);
getJudgeData(score3);
getJudgeData(score4);
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 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;
}

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263David A. Patterson, John L. Hennessy
226 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
895 solutions
Starting Out with C++: Early Objects 9th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++: Early Objects

9th EditionISBN: 9780134400242Godfrey Muganda, Judy Walters, Tony Gaddis
747 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
849 solutions

More related questions

1/4

1/7