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).
This assignment is to be done in pairs, just like homework 2 (but with a different partner).
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 $2.10 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 330 miles, it would cost $100 to rent the car, $80 to
stay in motels, and 11 gallons of gas, which costs $23.10, for a total
of
$203.10.
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.
Hint: For readability, I
recommend defining variables to represent the numbers that are fixed as
part of the problem, e.g.
(define CAR-COST-PER-DAY 30)
(define FUEL-COST-PER-GALLON 2.10)
etc.
How much of your program would you need to change if the car's fuel efficiency were improved to 33 miles/gallon? For example, if you went for 3 days and drove 330 miles, it would still cost $100 to rent the car, $80 to stay in motels, but only 10 gallons of gas, which costs $21.00, for a total cost of $201.00. (Make the change to your program, try this example, and make sure it produces the correct answer.)
progress-bar
which takes in
three numbers (width, height, and progress)
and a string (color) and
produces a horizontal progress bar, as seen at right, in which the
leftmost progress pixels are solid and the rest are
outlined. You
may assume that width
, height
,
and progress
are all positive integers
and progress < width. 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.
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.
digital-thermometer
which takes in a
temperature (in degrees Fahrenheit) and produces an image of the
temperature as a number, colored either green (below 99°), yellow
(at least 99° but less than 101°), or red (at least 101°).number->string
function.
However, if you try it on a number like 98.6 you'll get a fraction
rather than a decimal. If you want it in decimal form, use(format "~v" number)
.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.
thermometer
which takes in a temperature (in degrees Fahrenheit) and
produces a picture of a thermometer, as shown at right. It should
handle temperatures from 95 to 105. Temperatures below 99 should
produce a green thermometer; those at least 99 but below 101 should be
yellow; and those of 101 or above should be red.Error log: /15
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
trip-cost & auxiliaries What would you need to change? |
/15 | /15 | /30 | /15 |
/5 | ||||
progress-bar |
/5 | /5 | /10 | /5 |
within? & auxiliaries, if any |
/10 | /10 | /20 | /10 |
smallest-of-3 |
/5 | /5 | /10 | /5 |
digital-thermometer |
/5 | /5 | /10 | /5 |
carpet-price & auxiliaries, if any |
/10 | /10 | /20 | /10 |
thermometer & auxiliaries (XC) |
/15 | /15 | /30 | /15 |
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 |