Try Magic Notes and save time.Try it free
Try Magic Notes and save timeCrush your year with the magic of personalized studying.Try it free

Related questions with answers

Question

A particular 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 the three remaining scores. Write a program that uses this method to calculate a contestant’s score. It should include the following functions: - void getJudgeData () 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 five judges. - void calcScore () should calculate and display the average of the three 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 five 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 () should find and return the lowest of the five scores passed to it. - int findHighest () should find and return the highest of the five scores passed to it. Input Validation: Do not accept judge scores lower than 0 or higher than 10.

Solution

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 2

First, we will import the required libraries:

#include <iostream>
#include <iomanip>
using namespace std;


Now, we will define the getJudgeData function. It will ask the user for a judge’s score and store it in a reference parameter variable. It will also check if the score lies within the range or not.

// getJudgeData function definition
void getJudgeData(double &s)
{
    
    // asking user to enter data
    cout &lt;&lt;"\nEnter score between 0 and 10: ";
    cin>>s;
    
    // checking is the score is in
    // the range 0 - 10.
    while(s<0||s>10)
    {   
        cout&lt;&lt;"Score must be in the range 0 - 10. Please re-enter score: ";        
        cin>>s;
    }

}


Now, we will define the findLowest function. It will find and return the lowest of the five scores passed to it by using comparison within if statements.

// findLowest function definition
double findLowest(double s1,double s2,double s3,double s4,double s5)
{
    // assigning low to s1
    double low=s1;

    // checking is anyother score is less than low
    if(s2<low)
      low=s2;

    if(s3<low)
      low=s3;
 
    if(s4<low)
      low=s4;
    
    if(s5<low)
      low=s5;
   
   // returning low
   return low;
}


Now, we will define the findHighest function. It will find and return the highest of the five scores passed to it by using comparison within if statements.

// findHighest function definition
double findHighest(double s1,double s2,double s3,double s4,double s5)
{ 
    // assigning high to s1
    double high=s1;
    
    // checking if anyother score is 
    // more than high
    if(s2>high)
      high=s2;
    
    if(s3>high)
      high=s3;
    
    if(s4>high)
      high=s4;
    
    if(s5>high)
      high=s5;
    
    
    // return high
    return high;
}


Now, we will define the calcScore function. It will calculate the average of the three scores that remain after dropping the highest and lowest scores the performer received.

// calcScore function definition
void calcScore(double s1,double s2,double s3,double s4,double s5)
{
    // declaring variables    
    double sum,low,high,avg_score;
    
    // calling findLowest 
    low=findLowest(s1,s2,s3,s4,s5);
    
    // calling findHighest function
    high=findHighest(s1,s2,s3,s4,s5);
    
    // compting the score
    // as per given in the quesiton
    sum=s1+s2+s3+s4+s5-low-high;
    avg_score=sum/3;
    
    // printing the final score
    cout&lt;&lt;"\nThe contestant's talent score is: "&lt;&lt;setprecision(2)&lt;&lt;fixed&lt;&lt;sum/3.&lt;&lt;endl;
}     


In the end, we will define the main function.

// main function
int main()
{
    // declaring variables
    double s1,s2,s3,s4,s5;
    char a;
    
    // using a do-while loop
    do
    {
        // calling getJudgeData function
        // five times
        getJudgeData(s1);
        getJudgeData(s2);
        getJudgeData(s3);
        getJudgeData(s4);
        getJudgeData(s5);
        
        // calling calcScore function
        // and passing the arguments
        calcScore(s1,s2,s3,s4,s5);
    
    
        // asking user if he wants to continue
        cout&lt;&lt;"\nDo you want to enter another set of scores? (y/n) ";
        cin>>a;
    
        
    }while(a=='y'||a=='Y');
    
    
    return 0;
}

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263David A. Patterson, John L. Hennessy
226 solutions
Starting Out with C++ from Control Structures to Objects 8th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++ from Control Structures to Objects

8th EditionISBN: 9780133769395Godfrey Muganda, Judy Walters, Tony Gaddis
1,374 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
895 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
849 solutions

More related questions

1/4

1/7