 Due date: 10/2 @ 6pm Problem 0 [5%]:
Find one interesting article from the weeks news on the use of
software/computers in society. Summarize the article in your own words
with a single 200word paragraph, as
a pair, one playing writer, the other playing editor. Add both the article
and the summary in with the rest of your problem set.
The goal of this problem set is to practice designing data representations
using unions of classes and functions for processing unions. You must
follow the design recipe. The graders will look for data definitions,
contracts, purpose statements, examples/tests, and properly organized
function definitions. For the latter, you must design templates. You do
not need to include the templates with your homework, however. If you do,
comment them out.  The problem set also contains problems concerning
computation rules.
HtDP Problems:
7.2.1, 7.2.2
Problem A1
Collect four signatures from the course staff: one from a TA, one from
the tutor who graded your last homework, and two from any other
tutors. Look for their office hours on the web page for the course and
visit them. [4 points]
Problem A2
Evaluate the following expressions step by step and write down next to each
step whether it is (1) arithmetic (of any form), (2) function application
("plugging in") or (3) a conditional step:
(define (disttoO x y)
(sqrt (+ (* x x) (* y y))))
(disttoO 3 4)
(definestruct point (x y))
(define (disttoO p)
(sqrt (+ (sqr (pointx p)) (sqr (pointy p)))))
(disttoO (makepoint 3 4))
(define (step x)
(cond
[(< 1 x) (sqr x)]
[(< 0 x) (* 2 x)]
[else (sqr (+ x 1))]))
(step 0)
For sanity checks, you may want to write down each step inside of
drscheme. Since computation means calculating, you know that every step
must produce the same answer. So if you're ever unsure whether you're
calculation is still on track, just run the whole program and watch the
same answer pop up for as many steps as you have written down.
Problem A3
A stock brokerage classifies customers into two groups: lowvolume traders
and highvolume traders. For the first group, they just record the name
and the value of the last purchase (a plain number). For the second group,
they track the values of the last three purchases.
Design a data representation for customers and a function that computes
the average value of their trades.
Problem A4
A clothes discount store sells two kinds of wares: regular and
discounted. For regular items, they track the item number (as a string)
and its price. For discounted items, they track the item number (as a
string), the base price, and the number of weeks it has been in stock. For
every week that a discount price has been in stock, the store discounts
the item by 5% from the base price.
Design a data representation for the store's items and a function that
computes the current price of an item. (Think of the program in a cash
register and how it computes the current price from the price tag.)
Problem A5
Below is a data definition for a class of shapes.
Add an interpretation for the Square and Rectangle classes. Both represent shapes
whose borders are parallel to the borders of a canvas (window).
Develop the template funforshape, which outlines functions that consume Shapes.

Use the template to design shapemovex. The function consumes a Shape (sh and a number
(delta). It produces a shape that is like sh but translated by delta pixels along
the xdirection.

Use the template to design shapein. The function consumes a Shape (sh) and a Posn (p),
and determines whether p is inside (or on the boundary) of sh.
Domain Knowledge: for a point to be within a circle, its distance to the center must be
smaller than (or equal to) the radius. For a point to be within a rectangle, its x
coordinate must be between the x coordinate of the left line and the x coordinate of
the right line. How do you compute the x coordinates of these lines? Naturally something
analogous must hold for the y coordinates. Remember that squares are just
special rectangles.

Use the template to design shapedraw. The function consumes a Shape (sh) and a scene
(sc) and adds sh to sc.
Domain Knowledge: The documentation of world.ss specifies
how to add (place) a figure into a scene.
Hint: most of the exercises do not depend on each other. If you're stuck with one, try another one.
;;  copy and paste into drscheme 
;; Shape is one of:
;;  Circle
;;  Square
;;  Rectangle
(definestruct circl (x y r outline c))
;; Circle =
;; (makecircl Number Number Number Boolean Symbol)
;; interpretation: x and y determine the center of the circle,
;; r the radius, outline whether it's outlined or solid,
;; and c its color
(definestruct squar (x y size outline c))
;; Square =
;; (makesquar Number Number Number Boolean Symbol)
;; interpretation: Supply a good interpretation of Square.
(definestruct recta (x y width height outline c))
;; Rectangle =
;; (makerecta Number Number Number Number Boolean Symbol)
;; interpretation: Supply a good interpretation of Rectangle.
;; ... problem solving steps ...
;; inspect for expected results:
(define sh (makesquar 100 100 50 true 'red))
(define pt (makeposn 130 130))
(shapein sh pt)
(shapedraw (makecircl 130 130 5 true 'red)
(shapedraw sh
(emptyscene 300 300)))
