Please write the program below with C using codeblocks Baseball Batting Averages
ID: 3534694 • Letter: P
Question
Please write the program below with C using codeblocks
Baseball Batting Averages: A baseball player’s batting average is calculated as the number of hits divided by the official number of at-bats. In calculating official at-bats, walks, sacrifices, and occasions when hit by the pitch are not counted. Write a program that takes an input file containing player numbers and batting records for 20 players. Trips to the plate are coded in the batting record as follows: H – hit, O – out, W – walk, S – sacrifice, P – hit by pitch. The program should read the input file and store the player number and corresponding batting average into two parallel arrays. Print the player numbers and corresponding averages. Then sort the batting average array into ascending order using either the selection sort or bubble sort algorithm and print the sorted array. Calculate and print the average, median, and mode for the batting average array, using a frequency array to find the average. The input file is in the format shown below. ) The input information is saved in a while called baseball.txt
Sample input file:
12 HOOOWSHHOOHPWHO
4 OSOHHHWWOHOHOOO
7 WPOHOOHWOHHOWOO
Data Validation: If the batting code read from the data file is not ‘W’, ‘H’, O’, or ‘S’, the program should print a message and not include that particular code in the batting average.
Use separate functions to:
1. Read the data and find the batting averages.
2. Print the player numbers and batting averages.
3. Sort the averages.
4. Print the sorted averages.
5. Calculate the mean (average) of the batting averages.
6. Calculate the median of the batting averages.
7. Build the frequency array.
8. Calculate the mode of the batting averages.
9. Print the mean, median, and mode for the batting average array.
Explanation / Answer
This will read the data, print it and find the average of it.
Dont forget to add your input file reference in header.
You can add methods in the code. To fulfil other requirements. But this works great for computing the batting average.
All you need is to extend it by adding more functions as per your need.
Here is the sample output for your input.