| Due date: 09/30
Purpose:
The goal of this problem set is to help you design functions
that deal with arbitrarily large data.
Drill:
HtDP: 9.5.4, 9.5.6, 10.1.7, 10.2.2, 10.2.3, 12.4 (large!)
Required Problems:
Note: You may use DrScheme's HtDP Beginning Student
Language (with list abbreviations) to solve the problems. If you are
comfortable with using Intermediate Student Language (ISL) and facing the
pitfalls that come with it, you are welcome to switch.
- Design a program
total-wage that computes the total wages
a company pays in a single pay period from a list of wage records:
(define-struct wage (name hours wage/hour))
;; LOW is one of:
;; -- (cons Wage empty)
;; -- (cons Wage LOW)
;; Wage is (make-wage String Number Number)
The company distributes overtime-pay if someone works for more than 40
hours per week. Overtime-pay means a 10% bonus for all hours over 40. The
limit and the bonus are subject to wage negotiation.
The design recipe demands a non-standard form of conditions for the main
function. Why? How could you simplify the design?
Furthermore the design guideline suggests the use of two distinct
functions when applied to the data definition. Why?
- Dolls are special in Russia. One is always nested inside another, and
it (almost) never stops:
;; A Russian Doll (RD) is one of:
;; -- (cons "body" empty)
;; -- (list Dress RD)
;; A Dress is a string (that describes a layer of dressing).
Yes, this is a proper data definition. Why?
Design the function unwrap, which maps a RD to
the list of Dresses.
Design the function wrap, which maps a list of
Dresses to a RD.
Design the function image, which maps a RD to
an Image. Your function should represent each layer of dress
via a box that is larger than the representation of the inner RD
and that is labeled with an appropriate text.
- Design a program that renders an
Expr as an image:
(define-struct pls (x in?))
;; Expr is (make-pls 2LON Boolean)
;; interp. a pls struct represents an addition expression;
;; the boolean flag indicates whether it is an infix or
;; a prefix expression.
;; 2LON is one of:
;; -- (cons Number (cons Number empty))
;; -- (cons Number 2LON)
;; interp. a 2LON is a list with at least two numbers
Hint 1: The design guideline suggests the use of two distinct functions when
applied to the data definition. Why? Hint 2: This problem is related to
problem 1.3; re-read this problem for additional specifications.
- Project: Re-design the editor from problem 1.4, but use a
list-of-strings data representation for the state of the editor instead of
the string-based one. Discuss the design trade-off in a paragraph of 20 to
30 words. (We will deduct points for each word in excess of 30.)
|
|