![]() |
![]() |
|
Due:
Section 01: Sep.16 (Tue) 23:59, on D2L and hardcopy in the following class
Section 11: Sep.17 (Wed)18 (Thu) 23:59, D2L.
Your submitted file should be named “hw03.rkt”1.
Standard instructions for all homeworks:
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).
(10pts) Watching a DVD takes longer than just the movie's play time: It takes 5 minutes to get everybody together, 1 minute to start the disc playing, and 3 minutes per preview (G-rated movies have 8 previews, all others have 4). Then, once the movie itself starts, there is a 5-minute pause for a bathroom break after every 42 minutes of movie (so long as the movie is still going).
Write the function actual-time which takes in a dvd struct (from lecture), and returns the actual time (in minutes) required to watch it.
hints:
- The functions
quotient andremainder can be helpful.- The built-in function
zero? can be effected by using(= 0 …) but is still surprisingly handy.- You can use
let* , or just useif as sub-expression of a larger expression.- You get more points for having a test-case that fails than for not having a test case that would fail.
You only need steps 4-8 of the design recipe, since we already did steps 1-3 of in lecture, for dvds.
Hints:
Imagine a friend has two different snap-shots of the game; what is the minimal information that your friend needs to tell you so that you can always properly draw/construct an image of that object on the screen.
Do NOT include information which never changes (is “invariant”) for a class.
For example, if all instances of an object are always the same color,
so you wouldn't have a field for the color.
See also scheme-resources—ITEC380 Racket resources.
1Note that if you have embedded images in your program, it won't be a plain-text file; that's okay. ↩
2 Choose one of the types above which is naturally represented as a struct/object with more than one field. That's probably all three of those answers, but conceivably not be. ↩
3 The natural constructor is the one that just initializes each field directly from its arguments. It's totally automatic; in fact tools like Eclipse offer a menu option to auto-generate the natural constructor. Just like we did for Book.java in class. ↩
©2015, Ian Barland, Radford University Last modified 2015.Sep.28 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |