In: Computer Science
Programming Challenge #10. C++ Early Objects 10ed.
A 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
#include <iostream> #include <iomanip> using namespace std; // Function prototypes double getJudgeData(); double calcScore(double, double, double, double, double); double findLowest(double, double, double, double, double); double findHighest(double, double, double, double, double); int main() { double score1, score2, score3, score4, score5, // 5 judge's scores finalScore; // Inform the user what the program does cout << "After you enter 5 judge scores for this contestant, \n" << "this program will drop the highest and lowest score \n" << "and then average the remaining three scores.\n\n"; return 0; }// end of main function
the three remaining scores. Write a program that uses these rules
to calculate and display a contestant's score.
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double getJudgeData();
double calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);
int main()
{ //variables to store score
double score1;
double score2;
double score3;
double score4;
double score5;
cout << "After you enter 5 judge scores for this contestant,
\n"
<< "this program will drop the highest and lowest score
\n"
<< "and then average the remaining three scores.\n\n";
// get score
score1=getJudgeData();
score2=getJudgeData();
score3=getJudgeData();
score4=getJudgeData();
score5=getJudgeData();
//get highest lowest and average
double lowest = findLowest(score1, score2, score3, score4,
score5);
double highest = findHighest(score1, score2, score3, score4,
score5);
double average= calcScore(score1, score2,
score3, score4, score5); //dropping highest lowest
cout << "Highest Score: " <<
highest<<endl;
cout << "Lowest Score: " << lowest<<endl;
cout<<"Excluding highest and lowest scores, the average score
was "<< average<< endl;
return 0;
}
double getJudgeData(){
double score;
cout<<"Enter a judge's score: ";
cin>> score;
while(score<0||score>10)
{cout<<"Score must be between 0.0 and 10.0: " <<
endl;
cout<<"Re-Enter a judge's score: "<< endl;
cin>>score;
}
return score;
}
double calcScore (double score1, double score2, double score3,
double score4, double score5){
double sum;
double average;
double lowest = findLowest(score1, score2, score3, score4,
score5);
double highest = findHighest(score1, score2, score3, score4,
score5);
sum = score1 + score2 + score3 + score4 + score5; //add all
sum = sum - (highest); //subtract highest
sum = sum - (lowest); //subtract lowest
average = double (sum / 3 ); //find average
return average;
}
double findLowest(double score1, double score2, double score3,
double score4, double score5){
int arr [5];
arr[0]= score1;
arr[1]= score2;
arr[2]= score3;
arr[3]= score4;
arr[4]= score5;
double lowest = arr[0]; //assume first is lowest
for(int i = 0; i < 5; i++){
if(arr[i] < lowest){ //update if another lowest comes
lowest = arr[i];
}
}
return lowest; //return the lowest at the end
}
double findHighest(double score1, double score2, double score3,
double score4, double score5){
int arr [5];
arr[0]= score1;
arr[1]= score2;
arr[2]= score3;
arr[3]= score4;
arr[4]= score5;
double highest = arr[0]; //assume first is highest
for(int i = 0; i < 5; i++){
if(arr[i] > highest){ // update if any other comes highest
highest = arr[i];
}
}
return highest; //return the new highesr
}
OUTPUT:
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP