CS 161

Diving

Lab 8: Loops

Due Thursday, April 12th at the beginning of class

Overview

In this assignment, you will be writing a program to calculate the score of a professional diver.  Each dive receives a score from seven judges. The scores are between 0 and 10, and they are real numbers.  The scores are totaled and the highest score and the lowest score are thrown out.  The sum of the remaining scores is multiplied by a degree of difficulty (a real number between 1 and 4) and then by 0.6.  This is the score for one dive.  Each diver might perform multiple dives.  The program should calculate the overall score for a diver by averaging the scores of the individual dives.

Before each dive (except the first one), your program should ask the user if they want to continue.  If they answer “Y”, your program should prompt them to enter the data for a dive.  For each dive, your program should prompt the user for the degree of difficulty and then it should read in seven scores.  Your program should then display the score for this dive.  Your program should continue scoring dives until the user indicates that they do not wish to continue.  Input and output should be formatted as shown below. 

Remember to document your program. Include the comments at the top with name, date, class, purpose, etc.  But also include comments throughout your program to show what you’re doing.  Your program will be read, please make it easy to understand!

Example Input and Output (The actual input is shown in bold.).

Welcome to the diving score program.  This program will calculate an overall score for a diver, based on individual dives.

Dive 1:

Please enter the degree of difficulty: 3.5

Enter a score: 5.5

Enter a score: 6.0

Enter a score: 7.0

Enter a score: 6.5

Enter a score: 6.5

Enter a score: 5.5

Enter a score: 7.5

 

The diver’s score for dive 1 is 66.15

 

Would you like to continue (Y or N): y

 

Dive 2:

Please enter the degree of difficulty: -2.0

Invalid entry.  Please try again.

Please enter the degree of difficulty: 2.0

Enter a score: 8.0

Enter a score: 8.5

Enter a score: 8.5

Enter a score: 9.0

Enter a score: 8.0

Enter a score: 8.5

Enter a score: 8.0

 

The diver’s score for dive 2 is 49.80

 

Would you like to continue (Y or N): N

 

The average score for these dives is 57.97

 

Input Specifications

The input should be read in as shown above.  You need to check for input that is outside the valid ranges.  The range for degree of difficulty is 1 to 4 (including 1 and 4).  The range for scores is 0 to 10 (including 0 and 10).  You should print an error message and prompt the user again for the input.

If the user enters something other than ‘Y’, ‘y’, ‘N’ or ‘n’ when asked if they wish to continue, the program should prompt them again for their response until they enter a valid answer.

Output Specifications

Output should be formatted as shown in the sample run above.  Remember to use the correct precision for the floating point numbers.

Required Functions

Your program needs to include at least three functions.

·         One should be a function that finds and returns the maximum value given two input values (all values should be floating point). 

·         Another should be a function that finds and returns the minimum value given two input values. 

·         The third function should calculate the score of a dive.  The function should handle all of the input and output for scoring the dive.  It does not need to take in any parameters.  It should return the score of the dive. 

These should all be static functions in the Diving class (you only need one class for this program – it will have the three static functions described above and main).

Other Requirements

You must use at least two different types of loops in your program.

Do not declare seven different variables to hold the various scores.  Do the processing in a loop.

Getting Started

You should always try to develop your programs incrementally.  For this program, you might first write the logic to score a dive.  Do not worry about throwing out the high and low scores.  Get this to compile and run.  Now add in the logic for finding the high and low values and add the logic for discarding them.  Next you can add the loop for processing more than one dive and the logic to calculate and display the average.

Testing

Be sure to test your program with a wide variety of input values, so that you can be sure that your output is correct.  When you submit your program, I will test it with both valid and invalid input. An important test case for this program is if the user indicates that they do not wish to continue before entering the first dive (so that you don’t have any scores).  Your program should output an average score of 0 (be care not to divide by 0, though!).  

Submission

Submit your program as diving.