Homework One
Finger Exercises
Comp 210
Due: At the beginning of class on 97.Jan.21 (Wed.)
These exercises are to be done with DrScheme.
-
Give the value returned by Scheme after evaluating each expression
in the following order.
- (+ 22 (* 4 7) -2)
- (- 4 3 2)
- (and #t (or #f #t))
- (if #f (if #f 3 4) (if #t 5 6))
- (define pi 3)
- (define area (lambda (r) (* pi r r)))
- (area pi)
- ;((lambda (x) (* 2 pi x)) 3)
; Ignore this question, or (if you want) show
; what the answer _will_ be when we raise the
; language level in the future.
- (lambda (x) (* 2 pi x))
- (if (= 3 2) (/ 1 0) (/ 1 2))
- (+ #f #t)
- Write Scheme versions of the following mathematical formulae,
and test each on at least two inputs
(one of which should be some sort of borderline case,
e.g. 32 degrees fahrenheit).
- celc( f ) = (5/9)(f-32)
- dist( a, t ) = 1/2 a t²
- root1( a, b, c ) = [-b - sqrt(b²-4ac)]/2a
- my-abs( x ) = x, if x >= 0, or -x if x < 0.
- Houston drivers love to drive fast. Most drivers accelerate quickly
from a standing stop to the de-facto speed limit of 80 miles per hour (mph)
and maintain that constant speed. Write a Scheme function that takes as
parameters the acceleration (in mph per second) of a car and an elapsed
driving time in seconds and returns the distance traveled (in feet) by
the car. I strongly suggest that you use several helper functions to aid
in making your program more readable.
Hint: Most physics book contain a formula relating acceleration to distance
traveled.
You may certainly use any function already written for a previous exercise.
You may wish to double-check your solution against these inputs:
(houston-driver-distance 6 5) = 110
(houston-driver-distance 10 10) = 704
Also test your function on one or two other values.