Re-read the adages page,
and choose one (or several closely-related) adages, or
one
longer article, that mean more to you than they did in January.
Write an essay of one or more well-structured
paragraphs: what does it really mean in practice?
Do you agree or disagree?
Support your claims with specific examples from your own
programming experience.
As always, 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).
Develop a function add-dots
which
takes in an image and a list of posns, and returns the image with dots at
each of those positions. For example,
(define SIDE 100) (define box (move-pinhole (rectangle SIDE SIDE "outline" "black") -50 -50)) ... (add-dots box (list (make-posn 15 12) (make-posn 25 47)))
Type the following struct definition into your definitions window:
(define-struct employee [name salary id])(Recall that I used this definition to write
total-salary
in class. Review this function and its examples before going on.)
We'll be working with lists of employees; call this the
"employee-list" data type.
Develop the following functions:
count-over-100K
, which takes a list of employees and
tells how many of them have a salary over $100,000.fire-highly-paid
, which takes a number and a list of
employees and returns a new list of employees, leaving out the ones who
earned over the specified amount. (Note that this is a generalization
of fire-over-100K
.)sort-by-salary
, which takes a list of employees and
returns a list of the same employees sorted by salary, from lowest-paid
to highest-paid.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.
Recall the
random-posn
function from homework 4.
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.
add-dots
.
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.
For the next few problems, you'll need to set DrScheme to at least the "Intermediate Student" language level.
Review the function sort
, discussed
in class on 19 April.
Develop a generalized function
general-sort
which takes a non-empty list of X's (where X is
any data type) and a function (let's call it
beats?
)
with the contract "X X -> boolean", and returns a list of the
same objects, sorted in order so that each element "beats?"
the one after it. For example,
(general-sort < (list 5 2 4 6 3)) "should be" (list 2 3 4 5 6) (general-sort > (list 5 2 4 6 3)) "should be" (list 6 5 4 3 2)Note: You'll need an auxiliary function. For full credit, put this auxiliary function inside a local definition.
Re-write sort-by-salary
using
general-sort
. Your new definition should fit on four or
five reasonably short lines.
Error log: /30
Essay: /75
Function name | Contract | Examples | Definition | Test results |
---|---|---|---|---|
add-dots | /5 | /5 | /10 | /5 |
count-over-100K | /5 | /5 | /10 | /5 |
fire-highly-paid | /5 | /5 | /10 | /5 |
sort-by-salary | /10 | /10 | /20 | /10 |
table-of-squares | /5 | /5 | /10 | /5 |
table-of-squares XC | /5 | /5 | /10 | /5 |
12.4.2 XC | /15 | /15 | /30 | /15 |
general-sort | /10 | /10 | /20 | /10 |
new sort-by-salary | /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 |