A talent show competition has five (5) judges, each of whom awards a score betwe
ID: 3798096 • Letter: A
Question
A talent show competition has five (5) judges, each of whom awards a score between 0 and 10. The scores allow floating-point number values, such as 8.5. A participant’s final score is determined by eliminating the lowest and highest score (only one value, if there are duplicate lowest/highest scores) and then averaging the remaining scores (number of judges, minus 2). You are to implement a solution that implements the preceding requirements. You are to utilize an array to store and process the judge’s scores. The solution must include the following methods: 1. void getJudgeData(double[]): Obtain the scores for the five (5) judges. Call method getJudgeScore() to obtain each judge’s score. 2. double getJudgeScore(int): Solicit and validate the score value for an individual judge. You are to pass the judge’s number as a parameter to the method. Do not RETurn from the method until a valid value is entered. The RETurn value is the judge’s score. 3. double calculateScore(double[]): Calculates and RETurns the average of the judge’s scores after dropping one highest score and one lowest score received. This method shall call the following two methods to determine the lowest and highest scores received: a. double findLowest(double[]): RETurns the lowest score received. b. double findHighest(double[]): RETurns the highest score received. Extra Credit (5 points): Allow the User to determine the number of judges for the event. The number is to be restricted between 5 and 9 judges, inclusive. You are to utilize the following method to obtain the number of judges: 1. int nmbrJudges(): Prompt the User for the number of judges for the event. You must validate the input value and not RETurn from the method until a valid value is entered. The RETurn value is the number of judges.
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
void getJudgeData(double[]);
double getJudgeScore(int);
double calculateScore(double[]);
double findLowest(double[]);
double findHighest(double[]);
int nmbrJudges();
const int judges = nmbrJudges(); //Global variable calculating number of judges
void getJudgeData(double Scores[])
{
for(int i=0;i<judges;i++)
{
Scores[i] = getJudgeScore(i);
}
}
double getJudgeScore(int)
{
double score;
cin>>score;
return score;
}
double calculateScore(double Scores[])
{
double highest = findHighest(Scores);
double lowest = findLowest(Scores);
double totalScore,avgScore;
totalScore = 0;
for(int i=0;i<judges;i++)
{
totalScore = totalScore + Scores[i];
}
totalScore = totalScore -(highest+lowest);
avgScore = totalScore/(judges-2);
return avgScore;
}
double findLowest(double Scores[])
{
double lowest = 11;
for(int i=0;i<judges;i++)
{
if(Scores[i] < lowest)
lowest = Scores[i];
}
return lowest;
}
double findHighest(double Scores[])
{
double highest = 0;
for(int i=0;i<judges;i++)
{
if(Scores[i] >highest)
highest = Scores[i];
}
return highest;
}
int nmbrJudges()
{
int judges;
cout<<" Enter number of judges";
do
{
cin>>judges;
if(judges >=5 && judges <=9)
break;
}while(judges <=5 || judges >= 9);
return judges;
}
int main() {
double Scores[judges];
getJudgeData(Scores);
cout<<setprecision(2);
cout<<" The average score after eliminating highest and lowest score : "<<calculateScore(Scores);
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.