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

C++ In the sport of diving, seven judges award a score between 0 -10. Each score

ID: 3916905 • Letter: C

Question

C++

In the sport of diving, seven judges award a score between 0 -10. Each score may be a double value. The scores are added together, with the highest and lowest scores are thrown out. This sum is then multiplied by the degree of difficulty for the dive. The degree of difficulty ranges from 1.2 to 3.8 points. The result is then multiplied by 0.6 to determine the diver’s final score.

You are to write a program which calculates a diver’s final score, accepting the degree of difficulty and individual judge scores as input from the user.

Your solution is to have the following functions defined:

void getDegree(double& degree)

This function accepts one ref parameter to be updated by the function. The function prompts the user for a degree of difficulty, reprompting the user until a valid value is entered, and returns the result in the reference parameter.

void getScores(double scores[], int numScores)

This function accepts two parameters, a double array and the length of that array. The function prompts the user for scores, and fills the array. The function should make sure that the user enters valid scores.

double sum(const double scores[], int numScores)

This function accepts two parameters, a double array and the length of that array. This function accepts one double array as a parameter, and returns the sum of the array.

double highest(const double scores[], int numScores)

This function accepts two parameters, a double array and the length of that array. The function returns the largest value in the array.

double lowest(const double scores[], int numScores)

This function accepts two parameters, a double array and the length of that array. The function returns the smallest value in the array.

double average (vector<double> finals)

This function accepts one <double>vector parameter, and returns the average of all values in the vector.

It is a good idea to test your functions with a practice main function before starting the actual project main.

MAIN PROGRAM

You can follow the algorithm below in your main function, calling the functions described above to carry out the appropriate tasks.

Program algorithm:

Your main will need an array of size 7 to store the judge scores for a diver. Your program will also need a vector to store the final scores of all divers.

Get the degree of difficulty

While there are more divers

     Get the scores for a diver

     Compute the sum of all scores

     Determine the highest score

     Determine the lowest score

     Compute the final score for the diver and store

Print out all final scores

Print out the average of all diver’s final dive scores

Be sure that your code is well commented. Each function should have a comment indicating what the function does, and how it works if not trivial.

Explanation / Answer

You should have initialized best to 0 and worst to 10. The reason for this is because if you initialize best to 10, there will be no other score you can possibily enter that is greater than 10, so best will never update to a different value. The same story happens when you initialize worst to 0. No score will ever be less than 0, so worst will always be 0, no matter what the lowest score you entered actually was.

Also a minor tweak you should make is to change the scores array to a double array instead of an int array. The instructions tell you indirectly to do this because they say that scores can be floating-point values. If you keep it as an integer array, the program would only appear to work if you entered whole number scores for each judge.

I would also initialize Total to 0, just to follow good programming practices, since Total will have a garbage value if you don't initialize it.

I have posted the corrected code below:

PROGRAM IN C++:

#include<iostream>

using namespace std;

int main()

{
  
    double score[7];
    double difficulty;
    double Total = 0;
    double best = 0;
    double worst = 10;
  
    cout << "Enter the difficulty level (1.2 - 3.8): ";
    cin >> difficulty;
    if (difficulty < 1.2)
        difficulty = 1.2;
    if (difficulty >3.8)
        difficulty = 3.8;
  
    for( unsigned int i = 0; i < 7; i++ )
      
    {
      
        std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
        std::cin >> score[i];
        if (score[i] > 10)
            score[i] = 10;
        if (score[i] < 0)
            score[i] = 0;
        if (score[i] > best)
            best = score[i];
        if (score[i] < worst)
            worst = score[i];
        Total += score[i];
      
    }
  
    Total = ((Total - (best + worst)) * difficulty * 0.6);
  
    cout << "Scores =      ";
    for (unsigned int i=0, Total=0; i < 7; i++)
      
    {
        cout << score[i] << " " << std::flush;
    }
    cout <<endl;
    cout<< "Difficulty level = "<< difficulty <<endl;  
    cout<< "Total score = "<< Total << endl;
  
    system("PAUSE");  
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote