Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone help me figure out how to rewrite my code for this programming challenge using arrays. Here is the question: A talent competition has

Could someone help me figure out how to rewrite my code for this programming challenge using arrays. Here is the question:

A 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 this method to calculate a contestant's score. It should include the following functions: void getJudgeData() -- This 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. void calcScore() -- This should calculate and display 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() -- This should find and return the lowest of the 5 scores passed to it. int findHighest() -- This should find and return the highest of the 5 scores passed to it. Finally, Input Validation: Do not accept judge scores lower than 0 or higher than 10.

And here is the program I wrote that I am needing to rewrite using arrays instead of individual variables to contain the scores.

#include

#include

using namespace std;

void getJudgeInfo(double &score);

void calcScore(double, double, double, double, double);

double findHighest(double, double, double, double, double);

double findLowest(double, double, double, double, double);

int main()

{

double score1, score2, score3, score4, score5;

getJudgeInfo(score1);

getJudgeInfo(score2);

getJudgeInfo(score3);

getJudgeInfo(score4);

getJudgeInfo(score5);

calcScore(score1, score2, score3, score4, score5);

return 0;

}

void getJudgeInfo(double &score)

{

cout << "Enter judge's score.";

cin >> score;

while (score < 0 || score > 10)

{

cout << "Invalid entry! Score must be between 1 and 10. Please enter another score. ";

cin >> score;

}

}

void calcScore(double score1, double score2, double score3, double score4, double score5)

{

double lowest = findLowest(score1, score2, score3, score4, score5);

double highest = findHighest(score1, score2, score3, score4, score5);

double average = ((score1 + score2 + score3 + score4 + score5) - lowest - highest) / 3;

cout << "The lowest score of " << lowest << " was dropped!" << endl;

cout << "The highest score of " << highest << " was dropped!" << endl;

cout << "The average is " << average << setprecision(2) << fixed << showpoint << endl;

}

double findLowest(double score1, double score2, double score3, double score4, double score5)

{

if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5)

return score1;

else if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5)

return score2;

else if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5)

return score3;

else if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5)

return score4;

else

return score5;

}

double findHighest(double score1, double score2, double score3, double score4, double score5)

{

if (score1 > score2 && score1 > score3 && score1 > score4 && score1 > score5)

return score1;

else if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5)

return score2;

else if (score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5)

return score3;

else if (score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5)

return score4;

else

return score5;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago