Writing Conditional Functions
Directions: Complete steps 1 and 2 on a clean sheet of paper. Submit
to me after finishing Step 2.
Step 1: Do Exercise 5.1.1 without using DrScheme.
a) Evaluate (reply "How Are You?") by hand.
b) Write out four more examples for this function.
(define (reply s)
(cond
[(string=? s "Good Morning") "Hi"]
[(string=? s "How Are You?") "Fine"]
[(string=? s "Good Afternoon") "I Need A
Nap"]
[(string=? s "Good Evening") "Boy Am I
Tired"]))
Step 2: Do Exercise 4.3.3 without using DrScheme. (Feel free to use
a calculator - there is one on each of your computers. To get to it
the steps are: Start->Programs->Accessories->Calculator.)
What is the value of:
(cond
[(<= n 1000) (* .040 1000)]
[(<= n 5000) (+ (* 1000 .040)
(* (- n
1000) .045))]
[else (+ (* 1000 .040)
(* 4000 .045)
(* (- n 10000)
.055))])
when n is (a) 500, (b) 2800, and (c) 15000
Directions: Complete Step 3 in DrScheme.
Step 3: Do Exercise 4.4.1 in
DrScheme, using the Design Recipe (version
2). [Develop a
function interest. Like interest-rate, it consumes a deposit
amount. Instead of the rate, it produces the
actual amount of interest that the money
earns in a year. The bank pays a flat 4% for
deposits of up to $1000, a flat 4.5% per year
for deposits of up to $5000, and a flat 5%
for deposits of more than $5000.]
When you are finished:
Save the Definitions Window as [last-name]427def.scm.
Save the Interactions Window as [last-name]427int.scm.
E-mail me both of these files by 11:59 p.m. tonight.
Last Modified: 4/27/06