Problem Set 3

home work!

Programming Language BSL

Purpose This problem set concerns the design and processing of itemizations and self-referential data definitions and composing functions.

Finger Exercises HtDP/2e: 119, 120, 123, 124, 125, 127, 128, 130, 140, 141, 146, 147, 148, 150, 151, 152, 153, 154, 155

Solutions must be submitted to Blackboard by 7:00pm on Thursday, May 26.

The solutions to all of the following problems should be contained in one .rkt file.

You MUST follow the Design Recipe when you develop functions in this problem set. Name your functions using the names given below. Late homework is not accepted

image

Problem 1

A movie store sells two kinds of movies: regular and classic. For regular movies, they track the product id (a string, such as "234-87-1DX"), its base price, and the number of years it has been in their collection. For each year a movie is in stock, it is marked down by 3.5% of the base price, but no movie is sold for less than $2. For classic movies, they track the product id (again, represented as a string), and its price, which is never discounted.

Design a data representation for the store’s items and a function that computes the current price of an item. (Think of the program in a cash register and how it computes the current price from the price tag.)

Problem 2

You have been hired by the local psychology department to assist with the software for a perception experiment. For the first step, the lab director would like you to design a world program that records the first two mouse clicks ("button-down" mouse events) and draws the two clicks and a line between them on the canvas. The experimenter must be able to specify for how many seconds the world program runs.

The program should draw the first mouse click as a five-pointed, solid-red star and the second one as a five-pointed, solid-blue star.

Read the documentation for on-tick to understand how a world program can run for a specified number of seconds.

Problem 3

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 4

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 5

The goal of this problem is to develop a camera-roll program such as you may have on your smart phone. The camera-roll starts with the first photo and displays the next photo if the right arrow is pressed.

Here are the data definitions you should use:

;; LoImg (List-of-Image) is one of:

;; -- empty

;; -- (cons Image LoImg)

 

(define-struct cr (index images))

;; A CR (Camera Roll) is a (make-cr PositiveNumber LoImg)

;; intepretation:

;;  The index represents the position of the current image.

;;  The index must be between 0 and the number of images in LoImg.

Create a world program to display images from a CR and allow the user to scroll through the photos back and forth using the left and right arrow keys:

Design the function display-photo, which consumes a CR and returns the current image.

Design the function change-photo, which allows a user to change the current photo with the left and right arrow keys. If the current photo is the first photo, then pressing the left arrow should not change the photo. Likewise, if the current photo is the last photo, pressing the right arrow should have no effect.

Note: You will need to use several helper functions.