Related questions with answers
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.
Solution
VerifiedFirst, we will import the required libraries:
#include <iostream>
#include <iomanip>
using namespace std;
Now, we will define the getJudgeData function.
It will ask the user for a judge’s score and store it in a reference
parameter variable.
It will also check if the score lies within the range or not.
// getJudgeData function definition
void getJudgeData(double &s)
{
// asking user to enter data
cout <<"\nEnter score between 0 and 10: ";
cin>>s;
// checking is the score is in
// the range 0 - 10.
while(s<0||s>10)
{
cout<<"Score must be in the range 0 - 10. Please re-enter score: ";
cin>>s;
}
}
Now, we will define the findLowest function.
It will find and return the lowest of the five scores passed to it by using comparison within if statements.
// findLowest function definition
double findLowest(double s1,double s2,double s3,double s4,double s5)
{
// assigning low to s1
double low=s1;
// checking is anyother score is less than low
if(s2<low)
low=s2;
if(s3<low)
low=s3;
if(s4<low)
low=s4;
if(s5<low)
low=s5;
// returning low
return low;
}
Now, we will define the findHighest function.
It will find and return the highest of the five scores passed to it by using comparison within if statements.
// findHighest function definition
double findHighest(double s1,double s2,double s3,double s4,double s5)
{
// assigning high to s1
double high=s1;
// checking if anyother score is
// more than high
if(s2>high)
high=s2;
if(s3>high)
high=s3;
if(s4>high)
high=s4;
if(s5>high)
high=s5;
// return high
return high;
}
Now, we will define the calcScore function.
It will calculate the average of the three scores that remain after dropping the highest and lowest scores the performer received.
// calcScore function definition
void calcScore(double s1,double s2,double s3,double s4,double s5)
{
// declaring variables
double sum,low,high,avg_score;
// calling findLowest
low=findLowest(s1,s2,s3,s4,s5);
// calling findHighest function
high=findHighest(s1,s2,s3,s4,s5);
// compting the score
// as per given in the quesiton
sum=s1+s2+s3+s4+s5-low-high;
avg_score=sum/3;
// printing the final score
cout<<"\nThe contestant's talent score is: "<<setprecision(2)<<fixed<<sum/3.<<endl;
}
In the end, we will define the main function.
// main function
int main()
{
// declaring variables
double s1,s2,s3,s4,s5;
char a;
// using a do-while loop
do
{
// calling getJudgeData function
// five times
getJudgeData(s1);
getJudgeData(s2);
getJudgeData(s3);
getJudgeData(s4);
getJudgeData(s5);
// calling calcScore function
// and passing the arguments
calcScore(s1,s2,s3,s4,s5);
// asking user if he wants to continue
cout<<"\nDo you want to enter another set of scores? (y/n) ";
cin>>a;
}while(a=='y'||a=='Y');
return 0;
}
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•ISBN: 9780124077263David A. Patterson, John L. Hennessy
Starting Out with C++ from Control Structures to Objects
8th Edition•ISBN: 9780133769395Godfrey Muganda, Judy Walters, Tony Gaddis
Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. CormenMore related questions
- linear algebra
- linear algebra
- biology
1/4
- linear algebra
- linear algebra
- biology
1/7