Language C At the Olympic Games many of the events are judge

Language C++
At the Olympic Games many of the events are judged in the following manner. An individual athlete\'s performance it judged by a variable number of judges (up to 10). Each of the athletes receives a grade from 0.00 to 10.0 from each of the judges. The performance score of of the athletes is obtained by rejecting both the lowest and highest score and taking the average of the remaining scores. Write a complete C program that will read in data in the following format: 1234 6 4.5 9.3 5.6 8.7 9.2 5.9 where 1234 represents the athlete id 6 represents the number of judges and the remaining numbers represent the 6 scores Your program is to compute the average score for each athlete. It should then print the athlete id followed by the average score for that athlete. In addition it should determine which athlete had the highest score and prim a message with the athlete\'s name and average. Data to be used 2365 7 8.8 7.4 6.3 7.1 5.6 7.3 6.4 2345 6 8.9 8.9 4.5 4.5 6.7 9.2 43

Solution

#include <iostream>
#include <vector>

using namespace std;

void printAthleteDetails(int athleteId,float average);
float computeAverage(vector<float> scores, int noOfJudges);

int main() {
  
char continueInput;
float maxAverage = 0.0;
float maxAverageAthleteId;
while(true)
{
cout<<\"Enter athlete details(y/n):\";
cin>>continueInput;
if(continueInput == \'n\')
break;
else
{
int athleteId,noOfJudges;
float score;
cin>>athleteId;
cin>>noOfJudges;
vector<float> scores;
for(int i = 0; i < noOfJudges; i++)
{
cin >> score;
scores.push_back(score);
}
float average = computeAverage(scores,noOfJudges);
printAthleteDetails(athleteId,average);
if(average > maxAverage)
{
maxAverage = average;
maxAverageAthleteId = athleteId;
}
}
}
cout<<\"Max average, \"<<maxAverage<<\" is achieved by athleteId \"<<maxAverageAthleteId<<endl;
return 0;
}

float computeAverage(vector<float> scores, int noOfJudges)
{
float average;
float minScore = 10.0,maxScore = 0.0,sumOfScores=0.0;
for(int i = 0; i < scores.size(); i++)
{
if(scores[i] < minScore)
minScore = scores[i];
if(scores[i] > maxScore)
maxScore = scores[i];
sumOfScores += scores[i];
}
average = (sumOfScores - minScore - maxScore)/(noOfJudges - 2);
return average;
}

void printAthleteDetails(int athleteId,float average)
{
cout<<athleteId<<\"\\t\"<<average<<endl;
}

Language C++ At the Olympic Games many of the events are judged in the following manner. An individual athlete\'s performance it judged by a variable number of
Language C++ At the Olympic Games many of the events are judged in the following manner. An individual athlete\'s performance it judged by a variable number of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site