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🔗

These assignments don’t require any extra libraries. However, you may find some string functions useful (except where a problem tells you not to use them).

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.

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

Unless indicated otherwise, you should write all of these without using any of Racket’s list library functions.

  • count-long-words :: List-of-strings -> Number

    Consumes a list of strings that represent words. Produces a count of how many of those words have more than four letters. (Imagine you’re writing a game based on words, and this is a scoring function.)

  • longest-word :: List-of-strings -> String

    Consumes a non-empty list of strings that represent words, and produces the longest word in the list. If two or more words are tied for the longest, produce the one that appears earliest in the list. (“Earliest” is the leftmost one when viewing the list.)

  • total-vowels :: List-of-strings -> Number

    Consumes a list of strings that represent words, and produces the total number of vowels—the letters a, e, i, o, and uacross all the words. You may assume every letter in every word is lowercase.

  • all-shorter-than? :: Number List-of-strings -> Boolean

    Consumes a number and a list of strings that represent words. Returns #true if every word in the list has strictly fewer letters than the given number, and #false otherwise.

  • initials :: List-of-strings -> String

    Consumes a list of strings that represent words, and produces a string made up of the first letter of each word, in the same order as the words. For example, given a list with "hello" followed by "world", it produces "hw". You may assume every word has at least one letter.

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.