CPE 101
Programming Assignment

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 their first name. 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 first name and four integers: the number of field goals attempted, field goals made, free throws attempted, and free throws made. For example,
Hank  9 5 4 3
are statistics for player Hank 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:

3. The team average field goal percent and free throw percent.

4. Invalid data message: "Invalid data in line X."

5. File open error message: "Can't open input file."  The application should then terminate.

6. Given this data file, the report should be formatted as shown here:

Invalid data in line 11
                  Daring Dunkers Player Statistics

 Player        Field Goals             Free Throws             Total

               Tried  Made    %        Tried  Made    %        Points
Jerry             2     1    0.50         2     1    0.50         3
Akeem             0     0    0.00         0     0    0.00         0
Larry             2     2    1.00         2     2    1.00         6
Julius           25    15    0.60        12     8    0.67        38
WiltTheStilt     83    66    0.80        17    14    0.82       146
Obi              20    13    0.65         7     6    0.86        32
LightningGeorge   4     1    0.25         3     2    0.67         4
PistolPete       25    20    0.80        14    12    0.86        52

                    Team Avg 0.73           Team Avg 0.79

  FUNCTIONAL REQUIREMENTS

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 each number is an integer between 0 and 100 (inclusive), 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 (see above), and skip processing the player's record, but continue reading the rest of the file.

4. For each player, the program is to compute: 

Total points = Field goals made * 2 + free throws made

Field 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 names in the order they appear in the data file and the team averages. 

ASSUMPTIONS

1. Each player has a unique first name (no two player's share the same name).   The name has no embedded blanks and has a maximum length of 15 characters.

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).

4.  There will be at most 1000 unique players in the data file.

DISCUSSION
We will utilize an array of records to accumulate the individual player totals for each statistics: GoalsTried, GoalsMade, ThrowsTried, ThrowsMade.  

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 and display zero percent. (Although unlikely, it's possible that the entire team was shutout, so we need a similar check in the team average computations).

Your design must decompose the solution into five subprograms (procedures or functions):
  1. Reading the data from the file.  (See Figure 6.2 and Ch 11.1)
  2. Validating the data
  3. Searching to see if the player already exists.
  4. Performing the computations and printing the results.
  5. A function to perform the percent calculation (including check for zero denominator).

 Do not use global variables.  You must pass all needed data to subprograms via parameters.

Grading

This extra credit is worth 40% of a regular project.

40%    Correct functionality; reading data file, performing computations, displaying results, data validity checking.
20%    Correct design and implementation of the required functions.
15%    Design Quality: Proper use of arrays of records, correct use of structured loops and decisions.  
5%    Correct layout and formatting of the display.
15%   Coding style.
5%    Clean compile (no warnings using the required compiler flags of -Wall -ansi -pedantic).
Remember, code that does not compile will receive a grade of zero.

Submitting Your Work

You need to submit your source code electronically using the   handin   utility: No late submittals will be accepted! 

  1. You may submit as many source code files as you like, but only one of them may contain a main function.
  2. The file containing the main function must be named bbstats.c.
  3. Your files will be compiled with this command:   gcc -c -Wall -ansi -pedantic *.c
  4. Move the necessary file(s) to your Unix1 account using your favorite secure file transfer program.
  5. Log on to Unix1 using your favorite Secure Shell client program.
  6. Change directory (cd) to the directory containing your source file to hand in.  
  7. Be sure to compile and test your code on Unix1 using the required compiler flags ( -Wall --ansi -pedantic) one last time just before turning the files in.
  8. Submit your code using handin:
    handin graderjd Project6  bbstats.c  (optional other files)