Due date: 1/26 @ 9:40 am
Use the electronic submissions server.
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.
Purpose:
The goal of this problem set is to practice the designing data representations using structures and functions for processing such forms of data. Furtehrmore, you must follow the design recipe when you develop functions.
HtDP Problems:
Answer the questions in problems 6.3.1, 6.4.1, and 6.5.1 for the following structure definitions:
1. (define-struct person (name age)) 2. (define-struct magazine (title year month)) 3. (define-struct coffee (brand weight price decaf?)) 4. (define-struct appointment (name purpose hour))
Problem A1:
Your mail advertising firm has a database on people. The database access function delivers records according to the following data definition:
(define-struct db (last first middle prefix street no city state zip priority)) ;; A db record (DBR) is: ;; (make-db ;; String String Char String String ;; Number String State Zip Number)) ;; A State is a String such "AZ" ... "WY". ;; A Zip is a String such as 01000 or 09999.Design the function
create-address
, which consumes a DBR and produces a three-line address string. Hint:"\n"
is a string that ends a line when printed on a computer monitor or on paper.Problem A2:
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.Design the function
tick-time
, which adds one minute to the given time.Design the function
time->string
, which converts a time to a string like a clock. For example, when given(make-time 1 6)
produces "01:06".If you fill in the dots in the following code snippet, running it displays a clock that adds a minute per second:
;; Time -> Image ;; convert time to text image with ;; font size 22 and color 'red (define (draw-time t) ...) ;; how far from the left the clock time is displayed (define X-OFFSET 5) ;; the width of the display (just enough for a clock time) (define WIDTH (+ 10 (image-width (text "00:00" 20 'red)) X-OFFSET)) ;; Time -> Scene ;; place the image of the clock in an empty scene (define (time-scene t) (place-image (draw-time t) X-OFFSET 0 (empty-scene WIDTH 30))) ;; run the program with one tick per second (big-bang WIDTH 30 1 (make-time 0 0)) (on-redraw time-scene) (on-tick-event tick-time)Do not attempt this before you have finished the design of the functions.
Optional:
Modify the data definition so that Time also keeps track of seconds. Then modify
tick-time
. Modify means copy all functions that you wish to modify and add ".v1" to the end of the function name. That way you can turn in the program proper and the optional functions in one definitions window.
Last modified: Sun Jan 21 13:32:41 EST 2007