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 5

Due date: 10/10 @ 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 study the design and processing of self-referential unions. We focus on lists for now. Soon you will see that the design recipe applies to all forms of self-referential data definitions. -- You must follow the design recipe. The graders will look for data definitions, contracts, purpose statements, examples/tests, and properly organized function definitions. For the latter, you must design templates. You do not need to include the templates with your homework, however. If you do, comment them out. -- The problem set also contains problems concerning computation rules.

HtDP Problems:

9.5.4, 9.5.6, 10.1.7, 10.2.2, 10.2.3
Problem A0
Collect three signatures from tutors. Visit them as a pair during their office hours (see web page). You must ask for them by name, and you must ask at least one technical question about the text book. Use a yellow sticker to mark the page and write down the question. Use a sheet on which you write down the name of the tutors and they sign next to it. [6 points]

Problem A1:

Evaluate the following expressions step by step and write down next to each step whether it is (1) arithmetic (of any form), (2) function application ("plugging in") or (3) a conditional step:
1. ``````
(define (fahrenheit->celsius f)
(* 5/9 (- f 32)))

(define (celsius->fahrenheit c)
(+ (* 9/5 c) 32))

(celsius->fahrenheit (fahrenheit->celsius 212))

``````
2. ``````
(define-struct customer (title first last))

(define (formal* loc)
(cond
[(empty? loc) empty]
[else
(cons (formal (first loc)) (formal* (rest loc)))]))

(define (formal c)
(string-append "Dear "
(customer-title c)
" "
(customer-last c)))

(formal* (cons (make-customer "Dr." "Olin" "Shivers")
(cons (make-customer "Mstr." "ZC" "Flatt")
empty)))
``````

Problem A2:

DrScheme provides the following class of data:

``````
(define-struct posn (x y))
;; Posn = (make-posn Number Number)
``````
Think of instances of `posn` as Cartesian points.

Provide a data definition for lists of `Posn`s.

Provide a template for processing such lists.

Design the function `lop-length`, which counts how many `Posn`s are on a given list of `Posn`s.

Design the function `lop-x`, which extracts all the x coordinates from a list of `Posn`s.

Design the function `lop-draw`, which consumes a list of `Posn`s and adds them to an empty scene of 300 x 300 as red dots with a radius of 3.

Design the function `lop-filter`, which consumes a list of `Posn`s and produces one that contains only those `Posn`s from the given list that are within a 300 x 300 grid.

Design `lop-intersect`. The function consumes a list of `Posn`s `lop` and a `Posn` `p`. It then determines whether `p` occurs on `lop`.

Problem A3:

The goal of this problem is to develop a component of a slide show program such as PowerPoint or Keynote. The component displays a single, animated slide. That is, it starts with a plain background and adds phrases to the slide at the rate of one every second.

Here are the data definitions:

``````
(define-struct txt (content x y))
;; Str = (make-txt Number Number String)

;; LoStr is one of:
;; -- empty
;; -- (cons Str LoStr)

(define-struct world (image hidden))
;; World = (make-world Image LoStr)
;; intepretation:
;;  the world's image represents the image that the audience
;;  can see the world's list of Str represents the still
;;  hidden elements
```
```

Create a world with an empty blue 300 x 300 canvas to which the program will add the following three phrases: "Hello World", "Nice to Meet You", and "Good Bye, World", which the program will add one step at a time to the canvas. Make sure that a single change to your program changes the placements of all phrases on the slide.

Design the function `display`, which consumes a world and returns its current image.

Design the function `next`, which consumes a world and adds the next hidden `Str` to the currently visible slide image. Use 22pt font and red for the color of the text.

Optional: Make the program run and display the animated slide from above.

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