CODE USED FOR C++ CODE FOR C++ A particular competition has five judges, each of
ID: 3865138 • Letter: C
Question
CODE USED FOR C++
CODE FOR C++
A particular competition has five judges, each of whom award 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: double getJudgeData() should ask the user for a judge's score, validate it, and then return it to main. This function should be called by main once for each of the five judges. [score l = get Judge Data (); score2 = get Judge Data (); etc.] void calcScore0 should calculate and display the average of the three scores that remain after dropping the highest and the lowest scores the performer received. This function should be called just once by main and should be passed the five scores. double find Lowest () should find and return the lowest of the five scores passed to it. double find Highest () should find and return the highest of the five scores passed to it. Input Validation: Do not accept judge scores lower than 0 nor higher than 10. Sample Input/Output:Explanation / Answer
#include <iostream>
using namespace std;
double getJudgeData() {
double score;
cout<<"Enter Score from a Judge: ";
cin >> score;
if(score < 0 || score>10){
cout<<"Invalid score. Score sould be between 0 and 19"<<endl;
return -1;
}
return score;
}
double findLowest(double scores[], int size) {
double min =scores[0];
for(int i=0; i<size; i++){
if(min > scores[i]){
min = scores[i];
}
}
return min;
}
double findHighest(double scores[], int size) {
double max =scores[0];
for(int i=0; i<size; i++){
if(max < scores[i]){
max = scores[i];
}
}
return max;
}
void calcScore(double scores[], int size){
double sum = 0;
for(int i=0; i<size; i++){
sum = sum + scores[i];
}
sum = sum - findLowest(scores, size)- findHighest(scores, size);
cout<<"The mean of the three middle scores: "<<(sum/3)<<endl;
}
int main()
{
cout<<"Grade Hopper's scoreboard: "<<endl;
double scores[5];
for(int i=0; i<5; i++) {
scores[i] = getJudgeData();
if(scores[i] == -1){
i--;
}
}
calcScore(scores, 5);
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Grade Hopper's scoreboard:
Enter Score from a Judge: 9.7
Enter Score from a Judge: 6.9
Enter Score from a Judge: 8.4
Enter Score from a Judge: 7.9
Enter Score from a Judge: 8.3
The mean of the three middle scores: 8.2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.