On this page:
2.1 Language
2.2 Reading
2.3 Design Recipe
2.4 Library
2.5 File Format
2.6 Programming Tasks
2.7 Math Tasks
2.8 Grading Standards
2.9 Turnin

2 Placement 2🔗

2.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.

2.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.

2.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.

The book’s recipe is quite detailed. Here are the parts that we care about in the placement and in the subsequent course. For every function, we expect to see:
  • a clear and correct signature;

  • a crisp and correct purpose statement; and

  • a good suite of examples and tests.

in addition to the function definition.

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.

2.4 Library🔗

To do these assignments, make sure you add the following line at the top of your program:
(require 2htdp/image)

You may also find some string functions useful.

2.5 File Format🔗

For this assignment onward, we ask that you not use DrRacket’s fancy editor features like embedded images, embedded comment boxes, fractions written in repeating-decimal form, 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, but we’re stuck with it.

2.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”. Unless the problem explicitly says otherwise, you may assume every string represents a word, irrespective of its content (e.g., it may contain spaces inside it; that’s not your problem).

  • 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. (“Earlier” is in terms of the order in which you visit items when you traverse the list.) 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). The bars should be in the same order as the numbers in the list, with the same notion of ordering as in the previous problem.

    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 integers.

  • is-in? :: Any List-of-any -> Boolean

    Consumes a value and list of values and determines whether the former is one of the values 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.

2.7 Math Tasks🔗

Please also answer the following math questions.

  1. Find the numerical value of: \[\sum_{n=1}^{100}(4n -3)\]

  2. 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 your solution is correct (e.g., show your steps).

You can do this on a computer or on paper, whichever is most comfortable. You are welcome to write (whether on the computer or paper), but if you do, please make sure your handwriting and the image upload are legible. The Turnin section discusses file formats.

2.8 Grading Standards🔗

This assignment onward will be graded.

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. 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.

Both parts are equally important. (For the math, we will similarly check both the correctness of your answer and the soundness of your reasoning. Be sure to show all your steps!)

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?

2.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 of exactly the same type and order as above. Please name your file p2-code.rkt.

For the math portion, there will be a separate turnin section on Gradescope. Gradescope accepts only images or PDF files. Call this file p2-math; the filename would have a suffix that reflects the file type.

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.