1998 HIGH SCHOOL PROGRAMMING CONTEST

 

Problem 2 – Take me out to the ballpark

Description:

The E'ville Summer Softball League is now in full swing.  The statistician just quit, and the commissioner needs a program that will calculate each player’s batting average and the team batting average.  Your program should be able to handle up to 20 teams with up to 12 players  per team.

 

This is a interactive program.  The program should start with a greeting as shown on the output below.  The prompting for input should follow the example below.  The first input is the number of teams who will be in the league.  The input for each team will be the team’s name, then the number of players on the team.  The program should then prompt for player information for the number of players specified.  Player information is the player’s name, the number of at bats and the number of hits.  After all the player information is read in for a team, the information for the next team(if any) is read in.

 

The input will be limited in a number of ways.  Any player being listed will have been up to bat at least once.  There will be at least one valid player on each team listed.   Assume the number of hits will always be less than or equal to the number of at bats.

 

The output will be a list of the teams’ batting statistics.  The first line should be the team’s name.  The following lines should have a player name and their batting average. The batting average should be carried out to three decimal places.  Finally, the team batting average should be on the last line and calculated from the (total team hits)/(total team at bats).  Exact spacing of the statistics will not be enforced.

 

 

 

 

 

 

 

Example:

(Boldface indicates user input)

 

 

Welcome to E'ville’s Summer Softball League!

 

How many teams are in this year’s league? 2

Enter the name for team # 1 ? Hopper’s Heroes

How many players are on team # 1 ? 3

Name for player # 1 ? Bob

The number of at bats for player # 1 ? 20

The number of hits for player # 1 ? 10

Name for player # 2 ? Jim

The number of at bats for player # 2 ? 25

The number of hits for player # 2 ? 5

Name for player # 3? Joe

The number of at bats for player # 3 ? 21

The number of hits for player # 3? 7

 

Enter the name for team # 2 ? Don’s Dragons

How many players are on team # 1 ? 2

Name for player # 1 ? Al

The number of at bats for player # 1 ? 22

The number of hits for player # 1 ? 9

Name for player # 2 ? Ken

The number of at bats for player # 2 ? 24

The number of hits for player # 2 ? 7

 

Hopper's Heroes

 

Player Bob                                .500

Player Jim                                .200

Player Joe                                .333

The team average is 0.333

 

 

Don's Dragons

 

Player Al                                 .409

Player Ken                                .292

The team average is 0.348