Problem Set 1
Purpose The purpose of this problem set is to remind you of the pattern-matching skills that your elementary-school teachers tried to teach you and to get you to “play” with BSL and DrRacket.
Finger Exercises Run a program from the HtDP/2e Prologue. Modify it and watch how its behavior changes. HtDP/2e: exercises 1, 2, 3, 5, 7, 9, 10.
Solutions must be submitted to Blackboard by 7:00pm on Thursday, May 12th.
The solutions to all of the following problems should be contained in one .rkt file. Comment out portions that are not code. Your file must be able to run without errors. Late homework is not accepted
How much does he get if he works 5 hours? 10 hours? 25 hours? per month.
Make a table that shows the results. Use the Interactions area in DrRacket as a calculator.
Write a mathematical formula for calculating how much the boy earns if he works H hours.
Using your formula, find out how much the boy earns when a major event forces him to work for 100, 122, and 135 hours in a single month.
Define the program total-discount. It consumes three numbers: the price of the most expensive item, the price of the second most expensive item (or zero if only one item is bought) and the price of the third most expensive item (or zero if only one or two items are bought) in that order. It produces the value of the discount.
Problem 3 Define the program meters->miles that converts meters/second to miles/hour. The function consumes a velocity in meters/second and produces the velocity in miles/hour. Look up the conversion factor to convert from meters/second to miles/hour.
Problem 4 In BSL, you can juxtapose strings just like you can add numbers:
> (string-append "hello" " " "world") "hello world"
Develop the function greeting. It accepts a string and returns a greeting for a formal letter, prefixing the given name with "Dear " and concluding the string with a colon. Thus, (greeting "Professor") produces "Dear Professor:" as the result.
Problem 5 Develop a function called distance-traveled. The function consumes an initial velocity, v0, a final velocity, vt, (velocity units are ft/sec) and time, t, (in seconds). The function produces the distance traveled in feet at time t.
Some background information: we assume a constant acceleration. Acceleration, a, is calculated by finding the change in velocity divided by the time elapsed. Distance traveled, x, is found by:
x = v0t + 1⁄2at2
You should develop a helper function called acceleration which calculates a constant acceleration given an initial velocity, a final velocity and time elapsed.
Problem 6 Define the program draw-house which draws a house from a triangle, square and rectangle. The function consumes one number and draws the shapes and places them using values derived from this one number.
For instance,
(draw-house 40) produces the image:
And (draw-house 100) produces the image: