CS 227 Lecture -*- Outline -*- * An exercise in problem solving and recursion This is to be used at the end of Chapter 4 ** explain the baseball ideas in the following ------------- YEAR AB H 2B 3B HR BB SB CS Hank Aaron 1959 629 223 46 7 39 51 8 0 1971 495 162 22 3 47 71 1 1 AB = At Bat (Chances) H = Hits = 1B + 2B + 3B + 4B 1B = singles = H - (2B+3B+HR) 2B = doubles (2 bases) 3B = triples (3 bases) HR = 4B = home runs (4 bases) BB = base on balls (walk, 1 base) SB = stolen base (1 base) CS = caught stealing Total Bases = 1B + 2*2B + 3*3B + 4*HR + SB + BB Total Average = (Total Bases) / (AB - H + CS) ------------- ** Give them 2 minutes to formulate questions on the following problems ------------- POORLY SPECIFIED PROBLEMS 1. Find a player's home runs for a given year from the player's record 2. Compute a player's home runs total for all the given years (can you use iteration?) 3. Compute a player's total average for a given year. 4. Compute a player's total average for all the given years. YOU ARE TO COME UP WITH QUESTIONS TO CLARIFY THESE (2 minutes) --------------- Hint if you can't think of any questions, try to write down an answer ** take clarifying questions (hands up) they should ask about: what the procedures should be called year-homers career-homers year-total-average career-total-average what if the year isn't there (errors) what if the denominator is zero? examples: Aaron's TA in 1959 is about 1.089 in 1971 about 1.181 input format? ------------- ; YEAR AB H 2B 3B HR BB SB CS (year-homers 1959 '((1959 629 223 46 7 39 51 8 0) (1971 495 162 22 3 47 71 1 1))) ------------- ** write solutions to 1-3 Be sure to do #2 iteratively ------------- For 15 minutes, either in groups of 3 or 4, write solutions to problems 1-3. 1. Find a player's home runs for a given year from the player's record 2. Compute a player's home runs total for all the given years (can you use iteration?) 3. Compute a player's total average for a given year. ; YEAR AB H 2B 3B HR BB SB CS (year-homers 1959 '((1959 629 223 46 7 39 51 8 0) (1971 495 162 22 3 47 71 1 1))) --------------