Teaching
211 F '06
 
Assignments
The Hand In
The Recipes
The World
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 3

Due date: 9/25 @ 6pm

Problem 0 [5%]:

Find one interesting article from the weeks news on the use of software/computers in society. Summarize the article in your own words with a single 200-word paragraph, as a pair, one playing writer, the other playing editor. Add both the article and the summary in with the rest of your problem set.


The goal of this problem set is to practice designing data representations using structures and functions for processing such forms of data. Furthermore, you must follow the design recipe and the guidelines when you develop functions.


HtDP Problems
6.3.1, 6.4.1, 6.5.1
Problem A1
Here is a data definition for keeping track of time on a clock (which we know is a computer with a display attached to it):

(define-struct time (hours minutes))
;; Time = (make-time Number Number)
;; Constraints: 
;; The first number is always between 0 and 11; 
;; the second number is always between 0 and 59. 

Use these definitions for the following exercises:
  1. Design the function tock from Time to Time. It adds one minute to the given time.
  2. Design the function time->text, which converts a time to a text. The text should look like the display of a common alarm clock, i.e., it should separate the minutes from the hours with a colon. Hint: a text is an image, not a string, but you will need a string version of the time, too. See HelpDesk (image.ss) for text.
  3. Optional: After you have developed these functions, you may wish to add the following lines to your program:
    
        (big-bang 100 30 .1 (make-time 0 0))
        (on-tick-event tock)
        (on-redraw time->text)
    
    
    If you do, be sure to delete them before you turn in your solution. We will subtract points if you leave them in.
Problem A2

You've found a summer job with the pyschology department. They'd like you to develop a program that helps people control the movement of a ball across the screen. (They wish to study brain models and reaction times and this is just a small part of it.)

The ball can move on straight lines only, that is, up, down, left, or right. Mouse clicks change the ball's location.

  1. Develop a data representation for the current position of the ball. The position is best described with a pair of positive integers.
  2. Develop a data representation for velocity of the ball. You may assume that the ball always moves exactly 10 pixels at a time but remember that velocity also includes the direction of the movement.
  3. Develop a data representation for the ball.
  4. Design the function ball-next, which consumes (the representation of) a ball and create a ball that represents where it will be after one "tick." (Hint: If a car is 100 miles from Boston's center and travels at 60 mph in the exact direction of this point, how close will it be after 1 hour of traveling? Now generalize this to a ball.)
  5. Design the function ball-image, which consumes (the representation of) a ball and produces a rectangle of 300 x 300 pixels with a red dot (diameter 10 pixels) placed at the ball's position.
  6. Design a function ball-change, which consumes a ball, two numbers (x and y), and a symbol (s). If s is 'button-down, the function creates a ball that moves in the direction of (x,y); otherwise, the function returns the given ball.
  7. Optional: After you have developed these functions, you may wish to add the following lines to your program:
    
        (big-bang 300 300 (/ 1.0 28) 
            a-ball-inside-the-rectangle)
        (on-tick-event ball-next)
        (on-redraw ball-image)
        (on-mouse-event ball-change)
    
    
    If you do, be sure to delete them before you turn in your solution. We will subtract points if you leave them in.

last updated on Thu Nov 30 11:55:15 EST 2006generated with PLT Scheme