Assignment 5

Due date: 2/16 @ 9:50 am

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 designing functions for data that represent lists of items. The graders will look for data definitions, contracts, purpose statements, examples/tests, and properly organized function definitions. For this assignment you must have a template for each function you design.


HtDP Problems:

9.5.4, 9.5.7, 10.2.4


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.

  1. Provide a data definition for lists of Posns.
  2. Provide a template for processing such lists.
  3. Design the function lop-length, which counts how many Posns are on a given list of Posns.
  4. Design the function lop-x, which extracts all the x coordinates from a list of Posns.
  5. Design the function lop-draw, which consumes a list of Posns and adds them to an empty scene of 300 x 300 as red dots with a radius of 3.
  6. Design the function lop-filter, which consumes a list of Posns and produces one that contains only those Posns from the given list that are within a 300 x 300 grid.
  7. Design lop-intersect. The function consumes a list of Posns lop and a Posn p. It then determines whether p occurs on lop.


Problem A2:

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 
  1. 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.
  2. Design the function display, which consumes a world and returns its current image.
  3. 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.
  4. Optional: Make the program run and display the animated slide from above.

Last modified: Sat Feb 10 13:44:41 EST 2007