BASKETBALL TEAM STATISTICS
OVERVIEW
The Daring Dunkers basketball team is computerizing its records. You are to write a program that computes field goal and free throw percentages for the players. The players on the team are identified by an ID code letter between 'A' and 'Z'. Their game statistics are stored in a text file. You are to read the text file, perform computations, and print a report summarizing their peformance. Also compute and display the team averages.INPUT REQUIREMENTS
The input is read from a data file named "bbstats.dat." Each line of the file represents statistics recorded for a player during one basketball game. The line contains the player's ID letter and four integers: the number of field goals attempted, field goals made, free throws attempted, and free throws made. For example,
are statistics for player H which show 9 attempted field goals, making 5 of them, and 4 free throws attempted out of which 3 scored.
Statistics for several games may be included in the text file, so there may be more than one record in the file for each player. It is not known in advance how many records are in the file.OUTPUT REQUIREMENTS
1. Title and column headings.
2. A report which lists for each player:
4. Invalid data message: "Invalid data in line X."
5. File open error message: "Can't open input file."
6. The report should be formatted like the example below:
Daring Dunkers Player StatisticsFUNCTIONAL REQUIREMENTSPlayer Field Goals Free Throws Total
Tried Made % Tried Made % Points
A 5 3 0.60 3 2 0.67 8
D 1 0 0.00 3 2 0.67 2
E 12 7 0.58 5 4 0.80 18
G 6 3 0.50 1 0 0.00 6
Team Avg 0.54 Team Avg 0.67
1. Open the data file and verify success.
2. Read the data from the file and accumulate the player data.
3. Perform validity checking on the input data: Verify that the ID is between 'A' and 'Z', and that each number is an integer between 0 and 100, and that shots made is not more than attempted. If the data is invalid, display an error message which gives the line number in the file, and skip processing the player's record.
4. For each player, the program is to compute:
Total points = Field goals made * 2 + free throws madeField goal percent = field goals made / attempted
Free throw percent = free throw made / attempted
5. For the entire team, compute:
Team Average field goal percent = Total field goals made / Total field goals attempted.Team Average free throw percent = Total free throws made / Total free throws attempted.
6. Print the player summary report (with ID's in alphabetical
order) and the team averages. There may be less than 26 players on the
team, so the report shouldn't display anything for ID's that had no data
in the file.
ASSUMPTIONS
1. Each player has a unique ID letter. (no two player's share the same ID).
2. The data in the file is complete, that is, there are no missing data items for a player.
3. The numeric data is integers (not float or character).
DISCUSSION
We will utilize four integer arrays to accumulate the
individual player totals for each statistics: GoalsTried, GoalsMade, ThrowsTried,
ThrowsMade. The player ID can serve as the index to the array. We will
also use an array of boolean values, Players, in which each element is
TRUE if valid data was read for that player. We will then examine this
array when printing the report to see if we need to output anything for
this player.
The logic is straightforward: read and accumulate all the data from the file, then process the array from start to finish, performing computations as you go. Print out team averages at the end. One possible error condition we need to check for, is that a player may have no shots attempted, in which case the percent computation would get a divide by zero error. We need to include code to prevent this from happening. (Although unlikely, it's possible that the entire team was shutout, so we need a similar check in the team average computations).
TESTING HINTS
Your test plan needs to include data to provide minimum
coverage testing. Also test all invalid input data cases. Include data
at all boundary cases (e.g., 'A' and 'Z'). Include test cases for data
files with multiple lines of data for the same player.