A particular talent competition has 5 judges, each of whom awards a score betwee
ID: 3634587 • Letter: A
Question
A particular talent competition has 5 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 3 remaining scores. Write a program that uses these rules to calculate the 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 5 judges.
double calcScore() should calculate and return the average of the 3 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 5 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 5 scores passed to it.
int findHighest() should find and return the highest of the 5 scores passed to it.
Input Validation: Do not accept judge scores lower than 0 or higher than 10.
Explanation / Answer
Dear,
//Header file section
#include <iostream>
using namespace std;
//function prototypes
void getJudgeData(double &x);
double findLowest(double ,double ,double ,double,double);
double findHighest(double,double,double,double,double);
void calcAverage(double,double,double,double,double);
void main()
{
//variable declaration
double j_score1,j_score2,j_score3,j_score4,j_score5;
cout<<"Score collection of all the five judges ";
//function calls to get each judges data
getJudgeData(j_score1);
getJudgeData(j_score2);
getJudgeData(j_score3);
getJudgeData(j_score4);
getJudgeData(j_score5);
//function call to obtain average
calcAverage(j_score1,j_score2,j_score3,j_score4,j_score5);
//pause system for a while
system("pause");
}
//function definitions
void getJudgeData(double &x)
{
cout<<"Enter score of judge you got: ";
cin>>x;
while (x < 0 || x > 10)
{
cout<<"ERROR: Reenter: ";
cin>>x;
}
}
double findLowest(double a,double b,double c, double d,double e)
{
double lowest;
lowest=a;
if (b<lowest)
lowest=b;
if (c<lowest)
lowest=c;
if (d<lowest)
lowest=d;
if (e<lowest)
lowest=e;
return lowest;
}//end findLowest
double findHighest(double a,double b,double c, double d,double e)
{
double largest;
largest=a;
if (b>largest)
largest=b;
if (c>largest)
largest=c;
if (d>largest)
largest=d;
if (e>largest)
largest=e;
return largest;
}//end findLargest
void calcAverage(double a,double b,double c, double d,double e)
{
double lowest;
double largest;
double sum;
// function call to retrive lowest score
lowest=findLowest(a,b,c,d,e);
//function call to retrieve highest score
largest=findHighest(a,b,c,d,e);
sum=a+b+c+d+e;
sum=sum-largest;
sum=sum-lowest;
sum=sum/3;
//outputting average score
cout<<" After droping highest and lowest scores which you recieved, ";
cout<<"Your average score is "<<sum;
}//end calAverage
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.