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). You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
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 feet->inches which takes a number of feet and converts it to a number of inches.
Develop a function named total-inches which takes a number of feet and a number of inches and converts it to a number of inches. For example, 4 feet 3 inches is 51 inches. Hint: re-use an old function you've already written!
Develop a function named c->k
which
takes in a temperature in Celsius and returns the corresponding number of
degrees Kelvin. (A Kelvin degree is the same size as a Celsius degree, but
Kelvin's 0 is the same as -273.15 Celsius, so 0 Celsius is 273.15
Kelvin.)
Develop a function named f->k
which
takes in a temperature in Fahrenheit and returns the corresponding number of
degrees Kelvin. (For example, 32 degrees Fahrenheit is the same as
273.15 degrees Kelvin.)
Hint: re-use old functions!
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 |
---|---|---|---|---|
feet->inches |
/5 | /5 | /10 | /5 |
total-inches |
/5 | /5 | /10 | /5 |
c->k |
/5 | /5 | /10 | /5 |
f->k |
/5 | /5 | /10 | /5 |
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 |