8.5 Placement 2
8.5.1 Language
For the following assignment, you must use Racket’s Beginning Student language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
8.5.2 Library
(require 2htdp/image)
You may also find some string functions useful.
8.5.3 Reading
Read Part 2 of HtDP 2/e, specifically chapters 8 and 9 through 9.1 (you don’t need to go further).
If you find something unfamiliar (e.g., the material references if), note that we skipped reading Part 1 so you may need to peek in there to look it up.
8.5.4 Task
Define the following functions. Even if you think they correspond to a function that already exists, write it yourself. We’re testing your ability to program, not to read documentation!
score-by-length :: List-of-strings -> Number
Consumes a list of strings that represents words. Produces the sum of the lengths of these words. (Imagine you’re writing a game based on words, and this is a scoring function. We’ll return to this theme.)
overlay-all :: List-of-images -> Image
Consumes a list of images and overlays them, with earlier images in the list over later ones. Use a 10x10 solid white rectangle for the base case.
Note: Image equality is an imperfect art. Images that visually appear identical may in fact be very slightly different, causing a test to fail.
bar-graph :: List-of-numbers -> Image
The numbers in the list represent heights of bars in a bar graph (assume they have already been scaled and reflect the desired heights). Generate a bar graph where each bar is a black solid 10px rectangle and successive bars are adjacent (use beside/align). Don’t have spaces between the bars. Use a 1x1 solid white rectangle for the base case.
You can assume that all the numbers are non-negative.
is-in? :: Any List-of-any -> Boolean
Consumes a value and list of values and determines whether the former is anywhere in the latter: returns #true if it is and #false otherwise.
Use equal? for comparison.
words-to-sentence :: List-of-strings -> String
Consumes a list of strings that represent words. Concatenate these strings with a space between every pair of words.
Write this function explicitly. You may not use any built-in string functions other than string-append.
8.5.5 Work Expectations
From this assignment onward, for the rest of the placement and the course, you will be graded on both the quality of your code and the correctness of your answers. The latter will be (mostly) graded by computer, so it’s vital you follow the problem specification exactly. The former will be (mostly) graded by hand, and we will look for how well you have presented the parts expected by the Design Recipe. Both parts are equally important.
8.5.6 Turnin
Please turn in a single file that contains the five functions named above (it can contain any other helper definitions you like as well). The functions must be named exactly as above and must take parameters exactly as above. Please name your file p2.rkt. (Note: Google Drive will automatically rename your file(s) to include your name. This is fine.)
Failure to follow any of these instructions may result in zero credit.
Upload your file here. You will need to be logged into the Google@Brown domain to upload.