You need to turn in your source code (the contents of a definitions window), your test runs (the contents of an interactions window after you've executed the definitions), and your error log. If you don't turn in all three of those things, you'll lose points.
You may keep the error log in a text file and e-mail it in, or you may instead use the PSP on-line forms.
For the source code and test runs, you may save each one to a file and e-mail it to me, or you may use the "handin" button in DrScheme. If you don't have a "handin" button (it'll look like a hand holding a pen), see the directions for installing it.
For all the programming assignments, be sure to follow the design recipe.
This assignment is to be done in pairs, just like previous homeworks, but with a different partner.
Do (but don't turn in) exercises 7.1.1, 7.1.2, 7.1.3, 7.3.1, and 7.5.1, (some of which are very similar to exercises we did in class). Although you don't need to turn these in, make sure you know how to do them before going on to the next exercises.
A bank has three kinds of accounts: checking, savings, and credit.
Write structure definitions, contracts for the functions that come for free, and input and output templates, for all three of these. Write input and output templates for the mixed type "account" (i.e. "a checking, savings, or credit account").
The bank thinks of withdrawing money as an operation that takes an
account and an amount, and returns an account of the same kind as
the original, but with a changed balance and one more transaction.
For example,
(withdraw (make-checking 800 5) 200)
"should be (make-checking 600 6)"
Develop this withdraw
function. Note that
since a credit account's balance indicates how much you owe,
withdrawing money from a credit account increases the balance
rather than decreasing it.
Next, develop a checked-withdraw
function,
which is like withdraw except that if someone tries to withdraw
too much, it prints an error message (using the built-in
error
function, see section
7.5) and doesn't return anything at all.
For a savings account, you can't withdraw more than the balance. All checking accounts have $1000 overdraft protection, so you can withdraw up to $1000 more than the balance, but no more than that. For credit accounts, you can't withdraw so much that the new balance is more than the credit limit.
Error log: /15
checking-account struct type
|
Definition: /5 | Contracts: /5 | Examples: /5 | Templates: /10 |
savings-account struct type
|
Definition: /5 | Contracts: /5 | Examples: /5 | Templates: /10 |
credit-account struct type
|
Definition: /5 | Contracts: /5 | Examples: /5 | Templates: /10 |
account mixed type
|
Examples: /5 | Templates: /10 | ||
withdraw |
Contract: /10 | Examples: /10 | Definition: /20 | Results: /10 |
checked-withdraw |
Contract: /5 | Examples: /5 | Definition: /10 | Results: /5 |
Following directions | /20 |
Writing contracts from word problems | /20 |
Choosing examples | /20 |
Choosing names | /20 |
Coding | /20 |
Code re-use and choice of auxiliaries | /20 |