7 Placement 2
7.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.
7.2 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.
7.3 Design Recipe
The book emphasizes a design recipe for writing and presenting programs. The design recipe is designed to help students in three ways: to (a) offer structure to those having trouble writing the program; (b) give a sense of what it means to write functional, clean, maintainable, and reliable code (i.e., the kinds that professional programmers have to produce); and (c) provide a structure for seeking help from course staff.
a clear and correct signature;
a crisp and correct purpose statement; and
a good suite examples and tests
You will be graded on all of these. If you have programmed before, you’re especially likely to neglect everything but the function definition. You will then get an especially poor grade.
You do not need to provide data definitions of lists, since these are already in the book.
7.4 Library
(require 2htdp/image)
You may also find some string functions useful.
7.5 File Format
For this assignment onward, we would greatly prefer if you do not use Racket features like embedded images, embedded comment boxes, etc. While these are all really nice, Gradescope does not understand any of them, making it much more complicated for us to read your code. This is really Gradescope’s fault, not Racket’s, but we’re stuck with these tools…
7.6 Programming Tasks
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!
Some of the problems refer to “words”. You may assume every string represents a word irrespective of its content, i.e., you do not need to check the content unless explicitly asked to do so by the assignment.
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 as the backdrop atop which all other images are overlaid.
Note: You may sometimes find that two images you expect to be equal are reported as not equal by Racket. This is because 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 rectangle with a width of 10px, and successive bars are adjacent (use beside/align). Don’t have spaces between the bars.
Use a 1x1 solid white rectangle bar as the base case, so it will always be present as the right-most bar.
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.
To write this function, you may not use any built-in string functions other than string-append.
7.7 Math Tasks
Please also answer the following math questions.
Find the numerical value of: \[\sum_{n=1}^{100}(4n -3)\]
Let \(f(x) = x + 1\) and let \(g(x) = 2x - 4\). Is there a number \(C\) with the property that for all \(x > C\), we have \(g(x) > f(x)\)? If so, what is it, and if not, why not?
Don’t just write the answer: also show us why us your solution is correct (e.g., show your steps).
7.8 Grading Standards
This assignment onward will be graded.
The latter will be (mostly) graded by computer, so it’s vital you follow the problem specification exactly. If you do not, the grading software will almost certainly assign you a zero. We will not fix these mistakes by hand. If, from prior computing courses, you are accustomed to your instructor fixing these problems for you, please be aware that that won’t happen here.
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 mentioned above.
When writing tests, imagine that you aren’t just testing your own implementation. Suppose you are instead being asked to write tests to grade someone else’s work. What cases do you need to cover? What are some ways they might have gotten the problem wrong?
7.9 Turnin
For the programming portion, create 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-code.rkt.
For the math portion, there will be a separate turnin section on Gradescope.
Concrete instructions on how to upload your work will be posted to EdStem.
Failure to follow any of these instructions may result in zero credit. If you have prior computing experience and are used to your teachers fixing things for you, please know that that doesn’t happen here.
Be sure to read and follow the instructions in Placement AFQ and Anticipated Frequent Questions as well (e.g., note the requirement of anonymity) for this and all subsequent assignments.