Develop a function named add-up
that
takes in a list of numbers and returns their total.
Example:
(add-up (cons 3 (cons 10 (cons 2 empty)))) "should be 15"
Develop a function named
any-matches?
that takes a string and a list of strings and
returns whether that string appears in the list.
Example:
(any-matches? "hi" (cons "hey" (cons "ho" empty))) "should be" false (any-matches? "hi" (cons "hey" (cons "hi" empty))) "should be" true
Develop a function count-matches
that takes a string and a list of strings and returns the number of
times that
string occurs in the list.
Example:
(count-matches "hi" (cons "hey" (cons "hi" (cons "hello" (cons "hi" (cons "bye" (cons "hi" (cons "adios" empty)))))))) "should be" 3
Develop a function count-votes-for-name
that takes in a string (the name of a candidate) and a list of strings
(the votes cast by a bunch of voters) and returns how many of the voters
voted for this particular candidate.
Hint: this is really easy by re-using existing functions.
Develop a function convert
which
takes in a list of digits, ones place first (this actually
makes the problem easier), and returns the corresponding number.
Example:
(convert (cons 3 (cons 0 (cons 2 (cons 5 empty))))) "should be 5203"
Develop a function multiply-all
which takes in a list of numbers, and produces the result of multiplying
them all together.
Hint: What is the "right answer" for the empty list? It may not be what you think!
Develop a function
general-bullseye
which takes in a list of numbers,
and produces an image with black rings at those radii.
Hint: Use (circle 1 "solid" "white")
as the answer for the empty case.
Note: If you wish, you may assume that the
numbers are in increasing order, e.g. (cons 3 (cons 7
(cons 12 (cons 15 (cons 29 empty)))))
. If this doesn't help,
forget I said anything.
Develop a function largest
that
takes in a list of numbers and returns the largest one.
Hint: This function doesn't make sense applied to an empty list, so the simplest example should be a one-element list. When you write the function, don't ask whether the list is empty or not, but rather whether it's exactly one element or more than one element.
Develop a function any-over-100K?
that takes in a list of employee
structures (from
worked
exercise 16.2.1) and tells whether any of them earn over $100,000/year.
Develop a function total-votes
that
takes in a list of candidate
structures (from problem 16.3.2)
and returns how many votes were cast in all.
Develop a function add-points
that takes in an image and a list of posn
s, and adds
a dot at each of those locations on the image.
Develop an animation based on Exercise 15.6.3, but every few seconds a dot is added to the screen (in addition to whatever is already there), and if you click on any one of the existing dots, the game ends. (The game will be really easy to win, since nothing ever disappears, and pretty soon the screen fills up with dots so it's difficult not to hit one.)
Hint: Change your model from a posn
to
a list of posn
s.
All of the problems are programming problems. There is one animation; deal with it as you did in the previous few assignments.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). Note that "errors" means not only error messages from DrScheme, but also wrong answers. You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
Error log: /30
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them correctly.)
I sha'n't actually grade all the problems; consider the others "practice". For each function I grade, see the table below, which has columns for each step in the design recipe. You won't turn in a separate skeleton, inventory, and definition, but rather write a skeleton, then add an inventory, then add a body to turn it into a complete definition. However, if you don't get the definition working, comment it out and you'll still get partial credit for a correct skeleton and/or inventory.
Contract | Examples | Skeleton | Inventory | Definition | Choice of model and handlers (for animations) |
Working animation (for animations) |
---|---|---|---|---|---|---|
/5 | /5 | /5 | /5 | /15 | /5 | /5 |
Following directions | /10 |
Writing contracts from word problems | /10 |
Choosing examples | /10 |
Choosing names | /10 |
Coding | /10 |
Code re-use and function composition | /10 |