You need to turn in your source code (the contents of a definitions window), your test runs (the contents of an interactions window after you've executed the definitions), and your error log. If you don't turn in all three of those things, you'll lose points.
You may keep the error log in a text file and e-mail it in, or you may instead use the PSP on-line forms.
For the source code and test runs, you may save each one to a file and e-mail it to me, or you may use the "handin" button in DrScheme.
For all the programming assignments, be sure to follow the design recipe. For functions whose only effect is to draw a picture on a canvas, test them yourself one by one by typing function-calls into the interactions window, but don't bother turning in the interactions file; I'll just test them myself in the same way.
This assignment is to be done in pairs, just like previous homeworks, but with a different partner.
Note: For all the problems in this assignment,
you may use either nested-cons
notation or list
notation, whichever you are more comfortable with.
Develop a function named
"table-of-squares
" which takes in a natural number
n
and produces a list of posn
s, associating each of
the numbers 1...n
with its square. For example,
(table-of-squares 5)
should return
(list (make-posn 5 25) (make-posn 4 16) (make-posn 3 9) (make-posn 2 4) (make-posn 1 1))Note: I've put these in descending order because it's easier to write the function that way. For extra credit, produce the table in increasing order.
Do but don't turn in problem 11.3.1.
Recall the
random-posn
function from homework
5.
Develop a function named
"random-posns
" which takes in a natural number
n
and two other numbers
max-x
and max-y
, and produces a list of that many
posn
s, each randomly chosen as in random-posn
,
above.
Recall the function
plot-points
from homework 8. Now
compose this function with
random-posns
and see what happens.
Recall the function
"keep-in-circle
" from homework 8. Now compose
plot-points
with keep-in-circle
with
random-posns
and see what happens.
Do exercise 11.4.7.
Read section 12.2 in order to do the following:
Develop a function
"sort-candidates
" which takes a list of
candidate
structures (from homeworks 6 and 8)
and sorts them into decreasing order by number of votes, so the candidate
with the most votes is at the beginning of the list, the second-place
winner is second in the list, and so on. Test your
program by composing it with count-all-votes
from homework 8.
Extra credit: do exercise 12.4.2.
Hint: You must read all of section 12.4
leading up to this problem before tackling it; otherwise you'll
misunderstand the question, solve the wrong problem, and get no credit.
Another hint: You'll need at least two auxiliary
functions.
Error log: /15
table-of-squares |
Contract: /5 | Examples: /5 | Definition: /10 | Results: /5 |
random-posns |
Contract: /5 | Examples: /5 | Definition: /10 | Results: /5 |
11.4.7: is-not-divisible-by<=i |
Contract: /5 | Examples: /5 | Definition: /10 | Results: /5 |
11.4.7: prime? |
Contract: /5 | Examples: /5 | Definition: /10 | Results: /5 |
sort-candidates |
Contract: /10 | Examples: /10 | Definition: /20 | Results: /10 |
12.4.2insert-everywhere/in-all-words (extra credit) |
Contract: /15 | Examples: /15 | Definition: /30 | Results: /15 |
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 |