Contestant Score Calculator You will complete a program that calculates a contes
ID: 3602946 • Letter: C
Question
Contestant Score Calculator
You will complete a program that calculates a contestant's score based on the scores from five judges. The highest and lowest of the judges' scores are thrown out, and the contestant's score is the average of the remaining three judges' scores. I have already written the main function: contestantScore.cpp. You should not make any modifications to this file. You will modify the code in the contestantScore.h file. I have provided you the function to get user input. You will write two additional functions, as specified in the comments in the file. Note that the prototypes of the functions you write must match the calls to those functions from the main program. You may not use global variables.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// These functions are used for computing a average of numbers where the lowest and highest numbers in the series are dropped
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
//// This function gets a double between 0 and 100 from console input
//// DO NOT MODIFY THIS FUNCTION
//
double getDouble0to10(string message)
{
double num;
cout << message;
cin >> num;
// Check for valid input
// We have to be careful when comparing doubles.
// If the user enters a number just slightly bigger than 10
// (such as 10.00000000000000001) the computer will
// not see that the user input is greater than 10. I can't get the
// same thing to happen with the low end of the input, probably because
// I am alwyas entering a negative sign before the number. But I use
// the floor function just to be safe. We use the floor
// and ceil functions to ensure we are comparing whole numbers.
while ( !cin || floor(num) < 0 || ceil(num) > 10 )
{
// Reset the input stream and remove any remaining
// input
cin.clear();
cin.ignore(5000, ' ');
// Ask for valid input
cout << "You entered incorrect input" << endl;
cout << "Enter a double between 0 and 10: ";
cin >> num;
}
// Return the number input by the user
return num;
} // end getDouble0to100 function
////////////////////////////////
// Start of your code
//
// This function finds the minimum and maximum of a series of 5 numbers
// This function should have a void return type.
// You must use some reference parameters for this function.
//
// Write this function
//
//
// Find the average of 5 numbers excluding the minimum and maximum
// If there is more than one number with the minimum or maximum value,
// only exclude the number one time. For example, if the numbers are:
// 4.5 6.7 2.3 7.8 2.3, the average is calculated using the numbers:
// 4.5 6.7 2.3.
//
// This function must call the above function that finds the minimum and maximum
// values in a series of 5 numbers.
//
// This function does not use reference parameters
//
// Write this function
//// End of your code
////////////////////////////////
Explanation / Answer
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
//// This function gets a double between 0 and 100 from console input
//// DO NOT MODIFY THIS FUNCTION
//
double getDouble0to10(string message)
{
double num;
cout << message;
cin >> num;
// Check for valid input
// We have to be careful when comparing doubles.
// If the user enters a number just slightly bigger than 10
// (such as 10.00000000000000001) the computer will
// not see that the user input is greater than 10. I can't get the
// same thing to happen with the low end of the input, probably because
// I am alwyas entering a negative sign before the number. But I use
// the floor function just to be safe. We use the floor
// and ceil functions to ensure we are comparing whole numbers.
while ( !cin || floor(num) < 0 || ceil(num) > 10 )
{
// Reset the input stream and remove any remaining
// input
cin.clear();
cin.ignore(5000, ' ');
// Ask for valid input
cout << "You entered incorrect input" << endl;
cout << "Enter a double between 0 and 10: ";
cin >> num;
}
// Return the number input by the user
return num;
} // end getDouble0to100 function
////////////////////////////////
// Start of your code
//
// This function finds the minimum and maximum of a series of 5 numbers
// This function should have a void return type.
// You must use some reference parameters for this function.
//
// Write this function
//
void findMinMax(double arr[], double *min, double *max)
{
int i;
(*min) = 11.0;
(*max) = -1.0;
for( i = 0 ; i < 5 ; i++ )
{
// if current element is greater than the element in max
if(arr[i] > (*max))
(*max) = arr[i];
// if current element is smaller than the element in min
if(arr[i] < (*min))
(*min) = arr[i];
}
}
//
// Find the average of 5 numbers excluding the minimum and maximum
// If there is more than one number with the minimum or maximum value,
// only exclude the number one time. For example, if the numbers are:
// 4.5 6.7 2.3 7.8 2.3, the average is calculated using the numbers:
// 4.5 6.7 2.3.
//
// This function must call the above function that finds the minimum and maximum
// values in a series of 5 numbers.
//
// This function does not use reference parameters
//
// Write this function
//// End of your code
////////////////////////////////
double getAverage(double arr[])
{
int i;
double min, max;
// get the minimum and maximum value
findMinMax(arr, &min, &max);
double sum = 0.0;
for( i = 0 ; i < 5 ; i++ )
{
sum += arr[i];
}
// excluding the minimum and maximum
sum = sum - max - min;
double average = sum / 3.0;
return average;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.