|
home—lectures—exams—hws—D2L—breeze (snow day)
Due Sep.13 (Fri)15 (Sun) 23:59 (both hardcopy, and on Desire2Learn).
Your name and the assignment-number
must be in a comment at the start of the file.
Your hardcopy must be stapled.
Use the Beginning Student language1 All pertinent steps of the design-recipe must be evident; in particular test cases that precede the function are worth a signification portion of the points.
Rather than repeating code, you should have helper functions as appropriate.
(10pts)
Write the three functions
For any test cases involving inexact numbers, use
TODO for prof:Ian: the following paragraphs are more about c2f, not f2c!
In some odd countries (namely Canada, and most of the rest of the world), temperatures are measured in degrees Celcius, instead of degrees Fahrenheit. So when you are traveling and you look in the newspaper and see a forecast for 25°C, it might sound chilly until a friendly Canadian citizen tells you that this is a balmy 77°F. Other notable temperatures2 include freezing (0°C, which is 32°F), and boiling (100°C, which is 212°F). (However: if you really want to internalize metric, you're better off thinking in terms of new reference points than converting.) The general case for converting degrees-Celcius into degrees-Fahrenheit is given by the arithmetic formula
F(C) = 9⁄5 · C + 32
You read in a science article that the surface of the
sun is 5700K (“kelvins”3), and
that absolute zero is (conveniently) 0 Kelvin.
These numbers seem even more baffling, until
that same cheerful Canadian tells you that
to convert a temperature
from Kelvins to °C, you simply subtract 273.15.
So 0 K (absolute zero) is -273.15°C, which in turn is -459.67°F, brr.
Similarly, 273.15K (freezing) is 0°C which (as we've seen earlier)
is 32°F.
(Hint: If somebody gives you a temperature in Kelvins, converting that temperature into degrees Celsius is pretty easy. How can you then leverage code from the preceding problem, to convert that many degrees Celsius amount into degrees Fahrenheit?)
From Futurama The Series Has Landed:
Fry: Ooh, nighttime on the moon!
Old coot: It git down to minus one hundr'd, sev'nty-three.
Fry, worriedly: Fahrenheit, or Celsius?
Old coot: First one, then th' other.
(check-expect (pluralize 3 "t-shirt") "3 t-shirts") (check-expect (pluralize 1 "fish") "1 fish") (check-expect (pluralize 2 "fish") "1 fishes") (check-expect (pluralize 2 "cactus") "2 cacti") |
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) |
(3pts)
Write a function
Alas, the library
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 the image of the pac-man on the screen?
Do NOT include information which never changes (is “invariant”). For example, the fact that the pac-man is yellow never changes, so you wouldn't have a field for the color.
See also scheme-resources—ITEC380 Racket resources.
1 choose Beginnning Student language by: DrRacket: Language > Choose Language... > Teaching Languages > How to Design Programs: Beginning Student. ↩
2 One other intriguing test case is that -40°C = -40°F. Is it some mystical coincidence, that two scales exactly meet at such a nice round number, instead of some random number with a bajillion decimal places?
Well, it is a small bit of luck that the answer is an integer, but every integer celcius temperature corresponds to an even fifth-of-a-fahrenheit temperature, because of the 9/5 in the formula. Where does 9/5 come from?
The factor of 9/5 stems from the difference between freezing and boiling in the two systems: (212-32)/(100-0) = 180/100 = 9/5. Both scientists Fahrenheit and Celsius chose integers for the freezing and boiling of water, so that there'd be an integer number of notches on their thermometer between the two. This is the ultimate reason why conversions between the two systems use rational numbers, and not some long irrational real number arising randomly from nature.
If some martians came to Earth and (fascinated by all the ambient water) decided that they would invent a new temperature scale where the freezing point of water was declared as -27°Martian and the boiling point as 123°Martian, we'd still end up with a conversions which used fractions, not irrationals.
↩3Interestingly, you never say “degrees” with the Kelvin scale; the unit of temperature has just the one-word name “kelvins” rather than a two-word name “degrees fahrenheit”. ↩
4 Do not copy/paste the contents into an already-open DrRacket window: The reason is that the already-open window will be set to beginner-student language, but the file isn't written in beginner-student. If you did this, you'll get an error about “read: #lang not enabled in the current context”. ↩
5
One person reported doing this, but getting an error about `not a module`.
If this happens to you, try downloading arc2.rkt, and
home—lectures—exams—hws—D2L—breeze (snow day)
©2013, Ian Barland, Radford University Last modified 2013.Oct.04 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |