|
Comp210: Principles of Computing and Programming
|
Before you start the homework, you should remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. All are available from the class web site ( http://www.owlnet.rice.edu/~comp210) .
You should turn in one copy of the
homework for your team (not one per person) .
Clearly print the names of both team members inside the
homework. Use the proper file naming convention!
Use the drop-off link given on the class homepage.
Be sure to completely follow ALL the steps of the
Design Recipe and write down any templates that are determined by your data
definitions!
posn
with fields x
and y
, representing a
position on a canvas (a drawing window). (As in
Section 6.1 of the text.) Test that the teachpack has indeed been
loaded, by creating a sample posn
or two.translate-posn: posn, num,
num --> posn
posn
, and an
x- and y-offset, and returns a new posn
which has been
offset from the first. 'red
, 'yellow
, 'white
,
'black
, 'blue
, 'green
}.
Technically we should have a data definition for Color, so copy the previous sentence in your code. You don't need any examples-of-data for Color (they're already listed) nor any templates for Color (you're not writing any functions which will process Colors).
Do create examples-of-data for Circles, of course. However, you do
not need to write a template, since we aren't (yet) writing
functions that handle (just) a circle.
cond
branches for a Shape?) perimeter: shape --> number
Note that in the design recipe, you have already given
examples and a template for a Shape, so don't repeat that. (Though
presumably you'll copy/paste the template to start writing your
function.) You're not making any new datatype declarations, so you
won't have any templates or examples-of-data.
Remember that (define-struct myStruct (...))
myStruct?: ANY --> boolean
in?: shape, posn --> boolean
Again you'll presumably copy/paste the Shape template from part (d); don't make any new templates since we're not defining a new data type.
translate-shape: shape,
number, number --> shape
draw-shape: shape --> true
In what you turn in, you do not need to show the output of this function, but you should still show the test cases with your code.
my-picture: posn num --> true
Write a function my-picture2: posn --> true
my-picture
. The two copies should be offset from one another,
and may be of different sizes.
Feel free to play around and include additional parameters to these functions.
Note on combining draw-effects: Since each of the drawing
operations of draw.ss returns true
, if you
want to draw (say) a circle and a solid line, you can use
and
: evaluate (and (draw-circle ...)
(draw-solid-line ...))
true
(just like the provided functions).
Also note that and
can actually accept two or
more
arguments:
.
(50 points total)
Last Revised Sunday, 21-Nov-2004 14:10:38 CST
©2004 Stephen Wong and Dung Nguyen