Lab 3: Structures
1. Simple Structures
A bank has many programs that process information about the various accounts. For our purposes, an account has three pieces of information: the name of the account holder, the account number, and the amount of money in the account.Exercise 1: Write the data definition and structure definition for a bank account. Write down the names of the constructor(s), predicate(s), and selector(s) introduced by the structure definition, and a contract for each. Finally, write three example bank accounts. Remember to give the example accounts names so you can use them again later.
Exercise 2: Design a function that consumes a bank account and a minimum balance and determines whether the account meets the balance requirement. Remember the design recipe! Use the stepper on some of your test cases to see how DrScheme evaluates the function.
Exercise 3: Design the function bigger-balance? that consumes two accounts and determines whether the first has a bigger balance than the second. Use the stepper to see how DrScheme evaluates this function as well.
Exercise 4 (optional): Design a function that consumes a bank account and produces a new account that is the same as the old one, except that it has earned 1% interest.
Quiz & Administrivia
2. Unions of Structures
(for solution, see below) A music store owner wants to write a program to manage the recordings in her inventory. Some of her recordings are on CDs, and the rest are on cassette tapes. A CD album has three properties:- an album title,
- an artist, and
- the number of discs in the album.
- an album title and
- an artist.
- a first name and
- a last name.
Exercise 5: Write a data definition and structure definitions for the recordings in the store. Construct examples! (Hint: if you don't have "A Recording is either a ..." written down somewhere, then you haven't finished the exercise!)
Exercise 6: Write the template for functions that process recordings.
Exercise 7: Write a function that computes the price of a single recording. Audio tapes are $9, and CDs cost $11 for each disc in the album.

0 Comments:
Post a Comment
<< Home