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, using the ideas from the "kindergarten" article. Choose a partner ASAP and schedule time to work together on the assignment. When you're finished, turn in one assignment with both names on it. You'll have a different partner for homework 3, so if you don't get along with this partner, remember it's only for a week.
Develop a function named
counterchange
which takes in two images and returns a 2x2
arrangement of them, as shown at right. (Click on the image for a
full-scale view.)
Develop a function named checkerboard
which takes in two colors (e.g. strings) and returns a 2x2 arrangement
of them, as shown at right. Hint: This is extremely
easy if you re-use a previously-written function!
Develop a function named pinwheel
which takes in a picture and returns a 2x2 arrangement in which it
appears in each of its four possible rotations, as shown at
right.
Extra credit: The version of pinwheel
that I originally wrote works nicely for square pictures, but not so
well for pictures that are longer than they are high, or vice versa;
see the picture at right.
Develop a function
smart-pinwheel
that fits things together snugly, as in
the picture at right.
Hint: You'll need to look in the "Help Desk"
documentation for "image.ss"; look in particular for the word
"pinhole", which is how the teachpack lines up one picture with
another.
You may also find it helpful to write one or more
auxiliary functions -- functions that do part of the job, and
are used by the main function. For example, if I had just assigned
add-cubes
out of the blue, you might reasonably have
written cube
first in order to make add-cubes
simpler and easier. Note that auxiliary functions need contracts,
examples, etc. just like any other function you write.
Develop a function named
convert-3-digits
which
takes in three numbers (the hundreds, tens, and ones places of a 3-digit
number, in that order) and returns the 3-digit number. For example,
(convert-3-digits 4 2 5)
should return the number 425. Note that Scheme doesn't have an
operation for "put this number next to that one"; you have to use
arithmetic operations like +, -, *, /.
Next, develop a function named
convert-3-reversed
which takes in the ones, tens, and
hundreds places of a 3-digit number, in that order, and returns the
3-digit number. For example,
(convert-3-reversed 5 7 2)
should return the number 275. Hint: re-use an old
function!
Do (but don't turn in) all the exercises from section 2.4 of the textbook (the ones about errors).
Error log: /15
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them correctly.)
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
counterchange |
/5 | /5 | /10 | /5 |
checkerboard |
/5 | /5 | /10 | /5 |
pinwheel |
/5 | /5 | /10 | /5 |
smart-pinwheel (extra credit) |
/10 | /10 | /20 | /10 |
convert-3-digits |
/5 | /5 | /10 | /5 |
convert-3-reversed |
/5 | /5 | /10 | /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 |