MST
Program 25
K. DZWONKIEWICZ
With
spring in the air we all look forward to the national pastime. You are the
manager of the UCMST baseball team; “The Pythagoreans”. You have all the stars
from the team’s performance during the winter when they played in the Cuban
league. You need to print out the team roster with their stats. There are 12
players on the team. Each player has between 1 and 200 at bats. Each player
will have a batting average based on their hits divided by their at bats.
Print
out a team roster with statistics ________________ as given below.
************************************************************************
TEAM ROSTER FOR UCMST PYTHAGOREANS: WINTER STATISTICS
# Name Hits At bats Average
1) Dr. Dre 12 36 0.333
2) Snoop 25 120 0.208
3) De La Soul 75 190 0.395
4) Vanbiesbrouck 5 45 0.111
5) Moog 18 101 0.178
6) Fuhr 19 86 0.221
7) Barrasso 60 189 0.317
8) Dupuis 1 200 0.005
9) Dzwonkiewicz 120 199 0.603
10) Stafford 45 167 0.269
11) Darnok 13 66 0.197
12) Kapusta 22 89 0.247
TEAM TOTALS
TOTAL HITS: 415 TOTAL AT BATS: 1488 TEAM AVERAGE: .278
Highest Average: Dzwonkiewicz 120 hits 199 at bats average: 0.603
************************************************************************
Use arrays for name, hits, atbats, average
Have a Function to fill the array of 12 names.
Have a Function randomly generate at bats [1…200] then hits [0…to that persons at bats], where each item gets put in an array (use hit[ ] and bats[ ] and ave[x]:)
Have a third Function calculate average into an array called ave[ ], its calculated by dividing ave[x] = hits[x] / (float) bats[x];
To find highest average have a FUNCTION called, where you send in aver array. In the function, look at each location in the array. Just send back the ‘x’ location, call it biggest, where this occurred. Then you can print the name[biggest], hits[biggest], ave[biggest], bats[biggest]. Start biggest at 0 and pos = 1 and compare; if ave[x] > biggest then Begin biggest = ave[x]; pos = x; end;
Have variables that accumulate all the hits, all the atbats and then calculate team average as average = tothits / (float) totbats (set these to zero at the beginning). Remember to us RANDOMIZE() once.