|
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
Due: Sep.11 (Mon) 15:00, on D2L and hardcopy.
Your submitted file should be named “hw02.rkt”
.
(To save toner/ink,
your hardcopy can omit the images that are already exactly in this assignment,
and you may print in black-and-white.)
Standard instructions for all homeworks:
Of course, Pizzas have topping in the middle, and crust around the edge. (You can think of the full pizza being a disc, with a smaller pure-topping-covered disc inside of it.)
For now, your code does not need to give a correct
answer for pizzas whose diameter is less
than twice the
Note that this is a computer-sciency definition of “suffix”.
It has nothing to do with syllables or English.
More precisely:
we say that string a has b as a suffix, iff:
there exists a string x such that
hint:You can certainly usecond (orif ) if you like, but they're not actually needed; you can instead use amin ormax in a clever (but standard) way.
`if`: We will mentionif in class on Friday.
To experiment with functions-which-create-and-handle-images in DrRacket,
include
(rectangle 80 20 'solid 'blue) (circle 20 'solid 'red) (ellipse 80 20 'outline 'orange) (beside (rectangle 80 20 'outline 'blue) (circle 20 'solid 'red)) (underlay (rectangle 80 20 'outline 'blue) (circle 20 'solid 'red)) ; Think of 'underlay' and 'beside' as being "addition for images" ; underlay with an offset: (underlay/offset (rectangle 80 20 'outline 'blue) 0 10 (circle 20 'solid 'red)) ; If you want to explore documentation: ; In DrRacket, position the caret on a function-name ; like 'underlay', and hit F1. |
For functions that return an image, your expected-value should either be (a) an expression involving calls to: the image primitives and/or previously-tested functions, OR (b) an image-literal (but, show the expressions you used to create that image-literal).
For example, if the problem were to "create a function that takes in a width, and returns a solid
purple rectangle with the given width and a 16:9 aspect ratio", then the "expected result" part
of the test cases might involve calling the image-library's functions like
(check-expect (screen 32) (rectangle 32 18 'solid 'purple)) (check-expect (screen 16) (rectangle 16 9 'solid 'purple)) (check-expect (screen 0) (rectangle 0 0 'solid 'purple)) ; Note: for the expected 0x0 rectangle, I could equally well write: (check-expect (screen 0) empty-image) |
You only need steps 4,5,7,8 of the design recipe (once you decide what how you'll represent "size", which is a straightforward choice), and we're only using existing, simple datatypes (so no steps 1-3 or 6).
(check-expect (super-cool-ski-instructor-meme "spend all semester making memes") ) |
(check-expect (futurama-fry-meme "the image-library is easy" "Java's GUI library is hard") ) |
We notice that there is a lot of repeated code in our
functions — very ugly.
We will refactor it out.
Task: Write a more general function
It is up to you to decide how many parameters (and their type) to provide to
Only submit your refactored versions of the functions for (b),(d),(e) — you don’t need to (and, shouldn’t) keep the original versions around.
In addition to the standard instructions for all hws above, here are some requirements for our homeworks:
For every functions you write, follow the design recipe, steps 4,5,7,8. (You don't need to label each step; just turn in the final result.) When grading, there are points for having a good purpose-statement, good tests, etc. In general, test cases alone can be worth nearly half the points.
home—lectures—recipe—exams—hws—D2L—breeze (snow day; distance)
©2017, Ian Barland, Radford University Last modified 2017.Sep.08 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |