For all the programming assignments, be sure to follow the design recipe. Write your function contract, examples, and function definition in the Definitions Window, save it to a file, and send me this file. Also test your program: since you've already included examples in the Definitions window, you should be able to hit the Execute button and see all the results (along with what you said they "should be"). Save the resulting Interactions window to a text file and send me this file too. Be sure to choose meaningful names for functions and parameters, and watch for opportunities to re-use functions you (or the textbook) have already written.
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).
This assignment is to be done in pairs, just like previous homeworks (but with a different partner).
Develop a function all-over-10?
that
takes in a list of numbers and tells whether all of them are
greater than 10. Hint: the base case may not be what
you expect!
Develop a function convert-digits
that takes in a list of digits (i.e. numbers in the range 0..9) and
returns the number they form in base 10. The least-significant digit
(the "ones" place) will be first, and the most-significant digit last.
(This actually makes the problem easier.)
Example:
(convert-digits (cons 3 (cons 0 (cons 5 (cons 1 empty))))) "should be" 1503
Develop a function stack-images
that
takes a list of images and returns a single image with all of them arranged
vertically with the first one at the top, the last at the bottom.
Hint: for the base case, use a 1x1 white rectangle, which
is basically invisible.
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 cube-each
that
takes a list of numbers and returns a list the same length, containing
the cubes of the respective numbers.
Example:
(cube-each (cons 3 (cons 5 (cons -2 empty)))) "should be" (cons 27 (cons 125 (cons -8 empty)))
Develop a function stutter-t
that
takes a list of strings and produces a list of strings in which all
occurrences of the string "t" are repeated.
Example:
(stutter-t (cons "b" (cons "a" (cons "t" (cons "s" empty)))))
"should be" (cons "b" (cons "a" (cons "t" (cons "t" (cons "s" empty)))))
Develop a function recall
that
takes a string and a list of strings and returns the same list with all
occurrences of the given string removed.
Example:
(recall "bat" (cons "doll" (cons "bat" (cons "bat" (cons "nintendo" (cons "bat" (cons "ball" empty))))))) "should be" (cons "doll" (cons "nintendo" (cons "ball" empty)))
Develop a function remove-first
that
takes a string and a list of strings and returns the same list with
the first occurrence (if there are any) of the given string
removed.
Example:
(remove-first "bat" (cons "doll" (cons "bat" (cons "bat" (cons "nintendo" (cons "bat" (cons "ball" empty))))))) "should be" (cons "doll" (cons "bat" (cons "nintendo" (cons "bat" (cons "ball" empty)))))
Develop a function replace
that takes two strings (referred to as old
and new
)
and a list of strings,
and returns a list of strings with old
replaced
throughout by new
.
Example:
(replace "bat" "ball" (cons "doll" (cons "bat" (cons "bat" (cons "nintendo" (cons "bat" (cons "ball" empty))))))) "should be" (cons "doll" (cons "ball" (cons "ball" (cons "nintendo" (cons "ball" (cons "ball" empty))))))
Error log: /30
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
all-over-10? | /5 | /5 | /10 | /5 |
convert-digits | /5 | /5 | /10 | /5 |
stack-images | /5 | /5 | /10 | /5 |
count-matches | /5 | /5 | /10 | /5 |
cube-each | /5 | /5 | /10 | /5 |
stutter-t | /5 | /5 | /10 | /5 |
recall | /5 | /5 | /10 | /5 |
remove-first | /5 | /5 | /10 | /5 |
replace | /5 | /5 | /10 | /5 |
Following directions | /20 |
Writing contracts from word problems | /20 |
Choosing examples | /20 |
Choosing names | /20 |
Coding | /20 |
Code re-use and choice of auxiliaries | /20 |