In Scheme, we write larger programs and functions by combining the results of smaller ones. This set of questions helps you practice combining programs.
As you answer each of the remaining problems, use comments in your file to clearly indicate the number of the problem you are solving.
hot dog 2.95 taco 1.50 fries 1.50 burger 3.95 salad 5.00 pizza 12.00
share-pizza-cost
that consumes the number of slices eaten
by one person and determines that person's share of the cost of a pizza.
For this and all remaining problems, make sure you write a contract and purpose for each function.
price-with-tip
that will add a 15% tip to a given number. Write a contract and a purpose for your function.
share-with-tip
that consumes the number of slices of
pizza eaten by one person and computes that person's share of the cost of a pizza, including the cost of the tip.
add-side
that consumes two images
(for a meal item and a side-dish item), and produces an image
similar to this, picturing both the meal item and
the side item:
If you don't know how to do this problem, then you need to go back and do all the problems in Homework 0. Don't forget to document the function with a contract and purpose. Show two test cases for your function.
A waiter working at the pizza shop can stack two items in his
arm when he delivers an order to a table. Of course, he knows how to balance
the items so they don't fall over.
Write a function stack-two
that consumes images
of two items and returns an image with the second item just above the
first one. To ensure that the stack of items is balanced, you should center the items one above the other, like this:
The images must be centered regardless of their sizes (in other words, don't assume that the images supplied as inputs to the function are of any particular height or width).
[HINT: It's difficult to know if your function is working correctly if you use only the images supplied in this assignment, since they are all of similar width and height. I suggest testing your function by stacking (and centering) two images of your own creation of obviously different dimensions.]
Note that Scheme has a function max
that consumes two
numbers and produces the larger of the numbers. You should also be using
the image-width
and image-height
functions provided with the image.ss
teachpack.
Is your function getting too complicated? Should you decompose the problem into multiple functions?
You will be able to complete the remaining problems after we cover the cond statement in Tuesday's lecture.
food-cost
that consumes a string that represents the name of
a food item, and produces the cost of that food item.
number-I-can-buy
which consumes
a number representing an amount of money, and a string that represents the name
of a food item, and returns the number of food items of that type that can
be purchased with the given amount of money. The DrScheme function
floor
truncates a real number.
Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Name your file according the the naming conventions for Homework 1. Your name must be listed in a comment at the top of your file. Files submitted after 5pm on Wednesday, January 20 will be considered late, and will be subject to the late homework policy.