Due: Wednesday, February 11, 2009 at 500 pm.
The goal of this problem set is to help you design abstractions and to deploy pre-defined abstractions in a functional context. In addition, the assignment should familiarize you with closures.
Remember that you must follow the design recipe. Your deliverables include the data analysis, contract and purpose header, design strategy and template, code, and tests.
HtDP: 19.1.6, 20.2.2, 20.2.4, 21.2.2, 21.2.3
(define-struct bank (name total-assets bad-assets old-price new-price)) ;; A Bank is ;; (make-bank String Number Number Number Number) ;; where ;; -- name is the name of the bank ;; -- total-assets is the total assets of the bank ;; -- bad-assets is the amount of bad assets of the bank ;; -- old-price is the price of the bank's stock on January 1, 2008 ;; -- new-price is the price of the bank's stock on January 1, 2009 (define-struct bailout (name amount)) ;; A Bailout is (make-bailout String Number) ;; where ;; -- name is the name of the bank ;; -- amount is the amount the government gives the bank
You are considering two formulas:
Design the functions:
bailout1 : Number (listof Bank) -> (listof Bailout) bailout2 : Number (listof Bank) -> (listof Bailout) total-cost1 : Number (listof Bank) -> Number total-cost2 : Number (listof Bank) -> Number
These functions should compute the amount to be paid to each bank, and the total cost for each formula. In each case, the Number argument is the percentage to be used in the formula.
After hearing your results, the President decides that these programs cost too much, and the percentages need to be scaled back. Design functions
magic-bailout-percentage1 : Number (listof Bank) -> Number magic-bailout-percentage2 : Number (listof Bank) -> Number distribute-bailout1 : Number (listof Bank) -> (listof Bailout) distribute-bailout2 : Number (listof Bank) -> (listof Bailout)In each case, the Number argument is the total cost of the bailout. (magic-bailout-percentageX c lob), should return the percentage required so that the total bailout cost for lob matches the given cost c.
Stating this algebraically, we want, for any number c and list of banks lob,
(total-cost1 (magic-bailout-percentage1 c lob) lob) = c (total-cost2 (magic-bailout-percentage2 c lob) lob) = cThe distribute-bailout functions produce the (listof Bailout) corresponding to the calculated percentage.
Last modified: Wed Jan 14 16:05:23 EST 2009