For all the programming assignments, be sure to follow the design recipe. Write your function contract, examples, and function definition in the Definitions Window, save it to a file, and send me this file. Also test your program: since you've already included examples in the Definitions window, you should be able to hit the Execute button and see all the results (along with what you said they "should be"). Save the resulting Interactions window to a text file and send me this file too. Be sure to choose meaningful names for functions and parameters, and watch for opportunities to re-use functions you (or the textbook) have already written.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). You may do this using the PSP forms, or simply by keeping track in a text file or on paper.
This assignment is to be done in pairs, just like homework 2 (but with a different partner).
The nation of Progressiva has a simple tax code. The tax you pay is your salary times the tax rate, and the tax rate is 1/2% per thousand dollars of salary. For example, if you make $40,000, your tax rate is 1/2% times 40, which is 20%, so you pay 20% of $40,000, which is $8,000.
Develop a function to compute the net pay (i.e. pay after
taxes)
of a person with a given salary. HINT: you'll probably need
two auxiliary functions as well as net-pay
. Be sure to follow
all the steps of the design recipe for these functions, too.
This tax system has the peculiar feature that, beyond a certain income level, if you earn more, you actually get less take-home pay. Use your net-pay function to find this income level.
Now imagine the tax rate rises to 0.6% per thousand dollars of salary. (Fact of life: program specifications almost always change, and taxes almost always go up.) What would you need to modify in the program to handle this change?
You and your friends want to go on a weekend road-trip, but nobody has a car. You can rent a car with unlimited mileage for $30/day plus a fixed $10 processing fee, but you have to pay for the gas yourself: the car gets 30 miles to the gallon, and gas costs $1.50 a gallon. In addition, you're planning to stay in motels for $40/night; note that if you go away for Friday, Saturday, and Sunday (3 days), you actually only need motel rooms for 2 nights.
Develop a function named trip-cost
which takes in the number of
days you expect to be away, and the number of miles you expect to drive,
and tells you how much it'll all cost. For example, if you went for 3
days and drove 300 miles, it would cost $100 to rent the car, $80 to
stay in motels, and 10 gallons of gas, which costs $15, for a total of
$195.
Hint: This can be done as one big function, but please do it with several auxiliary functions instead. As always, follow all the steps of the design recipe for your auxiliary functions too.
Do (but don't turn in) some of the exercises in sections 4.1, 4.2, and 4.3, as many as you think you need in order to feel comfortable with booleans and conditionals.
Develop a function named grade-point
that takes
in a numeric grade average on a 100-point scale and returns one of the numbers
4.0, 3.0, 2.0, 1.0, or 0.0, as follows:
A carpet store needs a function to compute how much to charge its
customers. Carpeting costs $5/yard, but if you buy 100 yards or more,
there's a 10% discount on the whole order,
and if you buy 500 yards or more, the discount becomes 20% on the whole
order. Develop a function carpet-price
which
takes in the number of yards of carpeting and returns its total price.
Do exercise 4.4.3 in the textbook (the one about the credit card refund). As usual, watch for auxiliary functions and named constants. To be sure you understand the problem, work through the examples given in the problem by hand; don't start trying to write the function until you understand why those examples come out the way they do.
Do problem 1 in the supplementary problems for chapter 4.
Develop a function named smallest-of-3
which takes in 3 numbers and returns the smallest of them.
Error log: /15
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
net-pay & auxiliaries Find income level What would you need to change? |
/15 | /15 | /30 | /15 |
/5 | ||||
/5 | ||||
trip-cost & auxiliaries |
/15 | /15 | /30 | /15 |
grade-point |
/5 | /5 | /10 | /5 |
carpet-price & auxiliaries, if any |
/10 | /10 | /20 | /10 |
pay-back & auxiliaries, if any |
/10 | /10 | /20 | /10 |
smallest-of-3 |
/5 | /5 | /10 | /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 |