Assignment 3

Due Date : 10/2 @ 11:59pm

Note

For each function that you design you are expected to follow the Design Recipe in the same way as we did in class. Failure to show all your work for each step will cost you points.

Problem 1

Consider the following structure definitions:

  1. (define-struct movie (title producer))
  2. (define-struct boyfriend (name hair eyes phone))
  3. (define-struct cheerleader (name number))
  4. (define-struct CD (artist title price))
  5. (define-struct sweater (material size producer))
For each structure definition
  1. Provide the names of the constructors and selectors.
  2. Provide the contract for each constructor and selector.
  3. Provide data definitions for each structure definition. Make appropriate assumptions about what data goes with which field.
  4. Provide templates (one for each structure definition).

Problem 2

For this problem ensure that you have added the following line at the top of your file


(require 2htdp/image) 
Here is a data definition for keeping track of time on a clock (which, of course, is just 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 here for more on the text function.

Problem 3

Answer question 7.2.1 from "How to Design Programs".