Teaching
211 F '05
 
Assignments
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12
Set 13
Set 14

Problem Set 2

If you run any of the functions (as opposed to just testing them), comment out the code for running the functions before you submit your solution.

N.B.: Tests are not runs. A test is when you evaluate an expression and compare it to some expected result, while a run is when you evaluate an expression without anticipating any particular result for the expression.

Due date: 9/19 @ NOON

The goal of this problem set is to practice the design recipe for simple functions. The functions consume atomic forms of data (numbers, symbols, images). Some use conditionals to distinguish among different situations.

HtDP Problems:

2.2.3 [use the name "triangle-area"!], 2.3.2, 4.2.3, 4.4.4

Additional Problem 1:

Design a program that computes the number of insulin units from a given blood-level. See Problem Set 1(2) for the problem statement. Hint: Explore the function quotient of two numbers.

Once you have a first draft, make sure that the function doesn't produce negative numbers.

Additional Problem 2:

Your manager wants a running dot: a solid red dot that runs on a monitor from left to right, disappears on the right, and re-appears on the left.

For the first and last quarter of the band, the dot is to move at 4 pixels per second; in the middle sector its speed is 8 pixels per second. Your manager has decided to represent the running dot as just an number:

;; TeachPack: world.ss 

;; World = Number 
;; interpretation: the distance of the center from the left 

(define WORLD-WIDTH 100)

Design the function next, which consumes the current x coordinate of the dot and computes where the dot will be next. --- Ensure that changing the width of the band can be accomplished with a single modification of the program.

Design the function draw, which consumes the current x coordinate and produces a scene of 300 x 20 pixels with the red dot at the appropriate spot. The red dot should always have a diameter equal to the height of the scene. (How should you do this so that a change to the height changes the red dot's appearance, too?) Hint: Look up world.ss in HelpDesk.

Add the following code fragment at the bottom of your program and fill in the dots to get the red band to run:


;; --- run program run ---

;; World -> World
;; on every tick of the program:
(define (tock w) (update (draw w) produce (next w)))

(big-bang ...)
(on-tick-event tock) 

Do not attempt this before you have finished the design of the functions.


last updated on Sat Nov 26 15:34:41 EST 2005generated with PLT Scheme