Assignment 3a
Due Date Monday Tuesday at 9:00pm (Week 3)
Caution! Submit your answers to the first three problems separately from your examples for the last problem. There are two assignments available on the handin-server that you can submit to: be careful to submit the correct answers to the correct assignment.
Purpose It is time to graduate from programming to program design.
Finger Exercises
Exercise 1 Design amount-of-ticket. Given the speed of a car and the speed limit of some road, the function determines the penalty a driver has to pay. Here is the table printed on the back of such speeding tickets:
Percentage of Excess Speed
Amount ($)
up to 10
50
up to 25
150
up to 100
400
beyond
2500
Hint Create a wish list, because you will need auxiliary functions.
Exercise 2 Design the world program control. Its task is to move a red dot—
as in (circle 3 "solid" "red")— on a 200-by-200 canvas in response to the left and right arrow keys. Every time the user presses the left arrow key, the dot moves left by 5 pixels; when the user presses the right arrow key, the dot moves right by 8 pixels. The dot does not respond to any other keyboard input. The main function consumes the initial x coordinate of the dot.
Graded Exercises
Exercise 3 (Exercise 73 from HtDP) Design the function posn-up-x, that consumes a Posn p and a number new-x, and produces a new Posn whose x-coordinate is the given new-x value.
Exercise 4 Design move-linear, which consumes three numbers, p representing some position (e.g. the x- or y-coordinate of something), v representing a velocity in that coordinate, and dt an amount of time, and produces a number representing the new position after dt time has elapsed. (An example in English, to get started: “A car starts at x = 50 feet, and is moving at v = 20 feet/second. Where will it be after dt = 2.5 seconds?”)
Exercise 5 Design move-ball, which (intuitively) computes the result of a ball moving in a straight line for a period of time. The function consumes a Ball-2d b and an amount of time dt. To create the resulting Ball-2d, both the x- and y-coordinates move linearly, and the velocity is unchanged.
Exercise 6Forum is a client program; read that page for general guidelines on how client programs work.
Forum a multi-week project where you will be implementing (most of) the functionality of Piazza. This week, you will only be implementing a simplified set of user interactions, and we will not yet consider the networking part that makes Piazza useful. For today’s homework, we want you only to design examples for the world program simple-forum. For Thursday’s homework, you will be implementing this behavior, too.Your examples should demonstrate what you think the client should do when it processes different user inputs. Obviously, there are infinitely many possible sequences of inputs, so you must be selective: choose examples that you think are representative and informative: your classmates should be able, upon reading your examples, to implement a client themselves.
Note: When you submit this homework, you will need to include whatever supporting information is necessary to understand your examples. This may include data definitions, purpose statements and/or signatures, as necessary.
Note: You cannot write examples that test your main function directly, since that function calls big-bang and so is not easily testable. Instead, you should write examples for each of the handlers that your program uses (i.e. the functions you use with on-tick, to-draw, etc.).