Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the sport of diving, seven judges award a score between 0 and 10, where each

ID: 3598995 • Letter: I

Question

In the sport of diving, seven judges award a score between 0 and 10, where each score may
be a floating-point value. The highest and lowest scores are thrown out, and the remaining
scores are added together. The sum is then multiplied by the degree of difficulty for that
dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied
by 0.6 to determine the diver’s score.
• Write a computer program that inputs a degree of difficulty and seven judges’ scores
and outputs the overall score for that dive.
• The program should use an ArrayList of type Double to store the scores.
Hints.
• Input the degree of difficulty.
• Input 7 judge scores.
• Find position of min score.
• Find position of max score.
• Sum scores without the min and max scores.
• Calculate total score.

Run your program make sure it is working correctly.

Explanation / Answer

Below is your code

#include <iostream> //for std::cin and std::cout functionality

#include <algorithm> //for std::sort

const float scoreMultiplier = 0.6; //the multiplier you multiply the score by

const float lowestScore = 0; //the lowest possible score

const float highestScore = 10; //the highest possible score

const float lowestDifficulty = 1.2; //the lowest possible difficulty

const float highestDifficulty = 3.8; //the highest possible difficulty

const int numberOfJudges = 7; //the number of judges

using namespace std; //for endl and stuff

float scoreCalc(float (&scoreArray)[numberOfJudges], float difficulty); //function to calculate the final score

int main() {

float scores[numberOfJudges] = {0};

float difficulty = 0;

float finalScore = 0;

float temp = 0;

bool isValid = false;

char repeat=0;

do { //this loop is for the repeat functionality

/* BEGIN SCORE INPUT SECTION */

cout << "Please input the " << numberOfJudges << " judges scores. Type the score and press [ENTER] to move on to the next score: " << endl;

for (int i=0; i<numberOfJudges; i++) { //I want to do this check for every value that's stored in the array

do {

cin >> temp; //store user input in a temp variable

isValid = (temp >= lowestScore) && (temp <= highestScore); //check that the temp is within the boundaries we set in the constants

if (isValid) { //if it is...

scores[i] = temp; //store the value of the temp in the current position of the scores array

break; //and break this do/while loop

} else { //otherwise...

cout << "Invalid input. Please input a value between " << lowestScore << " and " << highestScore << "." << endl; //cout an error and don't store the temp

} //keeps the do/while going as long as temp is not valid

} while (!isValid); //there are better ways to do input validation I'm sure

} //but I don't know them yet

/* END SCORE INPUT SECTION */

/* BEGIN DIFFICULTY INPUT SECTION */

cout << "Please input the difficulty factor: " << endl;

do {

cin >> temp; //store user input in a temp variable

isValid = (temp >= lowestDifficulty) && (temp <= highestDifficulty); //check that the temp is within the boundaries we set in the constants

if (isValid) {

difficulty = temp;

break;

} else {

cout << "Invalid input. Please input a value between " << lowestDifficulty << " and " << highestDifficulty << "." << endl;

}

} while (!isValid);

/*END DIFFICULTY INPUT SECTION */

cout << "Sorting scores..." << endl;

sort(scores, scores+numberOfJudges); //sort's syntax means that I have to use numberOfJudges as the size of the array (because it is)

cout << "The scores entered are as follows:" << endl;

for (int j=0; j<numberOfJudges; j++) {

cout<<scores[j]<<" ";

}

cout << "." << endl;

cout << "Calculating final score...";

finalScore = scoreCalc(scores, difficulty);

cout << "The final score is: " << finalScore << endl;

cout << "Would you like to calculate another score?(y/n): ";

cin >> repeat;

cout << endl;

} while (repeat == 121 || repeat == 89); //only repeat the program if the user entered "y" (ascii dec 121) or "Y" (ascii dec 89)

return 0;

}

float scoreCalc(float (&score)[numberOfJudges], float difficulty) {

float finalScore = 0;

float sum = 0;

for (int j=0; j<numberOfJudges; j++) {

if(!(j==0||j==6)) {

sum+=score[j];

}

}

finalScore = sum * difficulty * scoreMultiplier;

return finalScore;

}

Output

Please input the 7 judges scores. Type the score and press [ENTER] to move on to
the next score:
1
2
4
3
7
6
5
Please input the difficulty factor:
1.2
Sorting scores...
The scores entered are as follows:
1 2 3 4 5 6 7 .
Calculating final score...The final score is: 14.4
Would you like to calculate another score?(y/n): n