HtDP Problem Set

Section 7

Problem 1:

Use the following data and structure definitions to solve this problem.

A Document-summary is one of
  • (make-letter Symbol Symbol Symbol)
  • (make-memo Symbol Symbol Symbol Symbol)
  • (make-resume Symbol Symbol Boolean)


(define-struct letter (to date signature))
(define-struct memo (from to date subject))
(define-struct resume (name date sent?))

Develop the function from, which consumes a Document-summary and produces a symbol representing the author of the document (use the signature property of a letter, the from property of a memo, and the name property of the resume).


Problem 2:
Develop data and structure definitions for a collection of 3D shapes. The collection includes

Develop the function volume. The function consumes a 3D shape and produces the volume of the object.

The volume of a cube is the cube of the length of one of its edges. The volume of a prism is the product of its length, width, and height. The volume of a sphere is 4/3 * PI * r3.


Problem 3:
Develop data and structure definitions for trains. A train is one of Develop the function hold-all? that, given a train and a number of passengers, produces true if the train could contain them all and false if not.


Problem 4:
Develop data and structure definitions for school employees. An employee is one of

The payroll office needs to compute various taxes before printing a paycheck. Develop the function tax, which takes an employee structure and a tax rate and returns the amount of tax for the pay period (per month for principals and teachers and the hours worked for an assistant).


Problem 5:
Develop data and structure definitions for financial accounts. An account is one of

Develop a data definition for a response. A response is either 'Error or an account.

Develop the function withdrawal, which consumes an account and an amount and produces a response. In the case in which a withdrawal would cause the balance of a savings account to go below zero, 'Error would be produced. Otherwise a new savings account would be produced with a new balance and the number of transactions incremented by one. A checking account has overdraft protection up to $1000, so a withdrawal would signal 'Error if the balance were lower than $-1000. A credit account's balance increases upon withdrawal, but cannot go beyond the spending limit.


Jamie Raymond
Matthias Felleisen

01 december 2003