Assignment 5

Due Date : 10/16 10/19 @ 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

Develop the function check-pass-6-10?, which consumes a list of passwords (represented as strings) and produces a boolean indicating whether all are at least 6 characters but no more than 10 characters long. Generalize the function to check-pass?, which consumes a list of passwords and a minimum and maximum length and produces a boolean indicating whether all passwords are within the allowed length span.

Problem 2

A weather station measures the temperature in degrees Fahrenheit every day at noon and midnight (actually the second measurement is taken at 11:59pm on the same calendar day). The temperatures are saved in two lists, one list for noon and one for midnight. Develop the function anomaly, which consumes the two temperature lists and outputs a list of booleans, true if the corresponding midnight temperature is greater than the one for noon.

Problem 3

Develop the function cesarify which consumes a list of symbols and returns the same list but with every instance of 'pizza doubled. For example,

            (cesarify (cons 'wurst (cons 'huevos (cons 'pizza (cons 'pants empty)))))
would be expected to return
            (cons 'wurst (cons 'huevos (cons 'pizza (cons 'pizza (cons 'pants empty)))))

Problem 4

The 2htdp/image teachpack contains many functions which create images of simple geometric figures: circle, ellipse, line, triangle, and so on. Provide a data definition for a catalog where each entry names a figure and also contains a corresponding example. It should be possible to make catalogs containing any number of figures. Show how to use this data definition to construct a specific sampler catalog of at least five different figures. Now develop the function show-example, which consumes the name of a figure (represented as a symbol) and the sampler. It produces the corresponding sample image or false if the named figure was not in the sampler.

Problem 5

Suppose we have the following class of data:
            (define-struct ball (x y color))
            ;; Ball = (make-ball Number Number Color)
            ;; Color is one of 'red, 'yellow, 'blue, etc.
Think of instances of ball as a Cartesian point, specifying where the ball is located, and the color of the ball.

Provide a data definition for lists of Balls.

Provide a template for processing such lists.

Design the function lob-length, which counts how many Balls are on a given list of Balls.

Design the function lob-x, which extracts all the x coordinates from a list of Balls.

Design the function lob-draw, which consumes a list of Balls and adds them to an empty scene of 300 x 300 as appropriately colored circles of radius 3.

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

Design lob-member?. The function consumes a list of Balls, lob, and a Ball b and determines whether b occurs in lob.