Assigned: Wednesday, 15 September 2010
Due: Beginning of class, Wednesday, 22 September 2010
This is a take-home examination. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date.
There are 10 problems on this examination. Each problem is worth 10 points, for a total of 100 points. Although each problem is worth the same amount, problems are not necessarily of equal difficulty.
Read the entire exam before you begin.
We expect that someone who has mastered the material and works at a moderate rate should have little trouble completing the exam in a reasonable amount of time. In particular, this exam is likely to take you about two to three hours, depending on how well you've learned the topics and how fast you work. You should not work more than four hours on this exam. Stop at four hours and write “There's more to life than CS” and you will earn at least a 80 on this exam.
I would also appreciate it if you would write down the amount of time each problem takes. Each person who does so will earn two points of extra credit. Since I worry about the amount of time my exams take, I will give two points of extra credit to the first two people who honestly report that they have completed the exam in three hours or less or have spent at least three hours on the exam. In the latter case, they should also report on what work they've completed in the three hours. After receiving such notices, I may change the exam.
This examination is open book, open notes, open mind, open computer, open Web. However, it is closed person. That means you should not talk to other people about the exam. Other than as restricted by that limitation, you should feel free to use all reasonable resources available to you.
As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately. If you use code that you wrote for a previous lab or homework, cite that lab or homework and the other members of your group. If you use code that you found on the course Web site, be sure to cite that code. You need not cite the code provided in the body of the examination.
Although you may use the Web for this exam, you may not post your answers to this examination on the Web. And, in case it's not clear, you may not ask others (in person, via email, via IM, by posting a please help message, or in any other way) to put answers on the Web.
Because different students may be taking the exam at different times, you are not permitted to discuss the exam with anyone until after I have returned it. If you must say something about the exam, you are allowed to say “This is among the hardest exams I have ever taken. If you don't start it early, you will have no chance of finishing the exam.” You may also summarize these policies. You may not tell other students which problems you've finished. You may not tell other students how long you've spent on the exam.
You must include both of the following statements on the cover sheet of the examination.
Please sign and date each statement. Note that the statements must be true; if you are unable to sign either statement, please talk to me at your earliest convenience. You need not reveal the particulars of the dishonesty, simply that it happened. Note also that inappropriate assistance is assistance from (or to) anyone other than Professor Weinman (that's me) or Professor Davis.
You must present your exam to me in two forms: both physically and electronically. That is, you must write all of your answers using the computer, print them out, number the pages, put your name on the top of every page, and hand me the printed copy. You must also email me a copy of your exam. You should create the emailed version by copying the various parts of your exam and pasting them into an email message. In both cases, you should put your answers in the same order as the problems. Failure to name and number the printed pages will lead to a penalty of two points. Failure to turn in both versions may lead to a much worse penalty.
In many problems, I ask you to write code. Unless I specify otherwise in a problem, you should write working code and include examples that show that you've tested the code. Do not include images; I should be able to regenerate those.
Unless I explicitly ask you to document your procedures, you need not write introductory comments.
Just as you should be careful and precise when you write code and documentation, so should you be careful and precise when you write prose. Please check your spelling and grammar. Since I should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify on this exam. I will limit that form of extra credit to five points.
I will give partial credit for partially correct answers. I am best able to give such partial credit if you include a clear set of work that shows how you derived your answer. You ensure the best possible grade for yourself by clearly indicating what part of your answer is work and what part is your final answer.
I may not be available at the time you take the exam. If you feel that a question is badly worded or impossible to answer, note the problem you have observed and attempt to reword the question in such a way that it is answerable. If it's a reasonable hour (7 a.m. - 6 p.m.), feel free to try to call me in the office (269-9812).
I will also reserve time at the start of each class before the exam is due to discuss any general questions you have on the exam.
Topics: Drawings as values, numeric calculations, procedures
The procedure drawing-left finds the left edge of a
drawing and the procedure drawing-width finds the
width of a drawing. Similarly, the procedure drawing-top
finds the top edge of a drawing and the procedure
drawing-height finds the height of a drawing.
Write two procedures, drawing-center-x and
drawing-center-y, that find the x and y coordinates of
the center of a drawing.
Topics: Drawings as values, Conciseness.
Consider the flag of Colombia: two horizontal stripes of equal size,
colored red and blue, below one horizontal stripe twice as tall,
colored gold.
(See Flags of the
World - Colombia.) Write a program (that is, a sequence of
expressions) that (a) uses drawings-as-values to
define co-flag as a drawing of the flag of Colombia and
(b) renders that flag in a new image. Make your code as concise as
you can.
Topics: Drawings as values, procedures.
a. Write a procedure, ( that creates a compound
drawing with four copies of diagonal
drawing)drawing
(one unshifted, one shifted right and down once, one
shifted right and down twice, and one
shifted right and down thrice).
This new, compound drawing should be scaled by 25%,
so that it is the same width and height as the original.
b. Using diagonal, build a "sawtooth" (a series of
two diagonals) of some interesting drawing.
For example:
(image-show (drawing->image flag 32 20))
|
![]() |
(image-show (drawing->image (diagonal flag) 32 20))
|
![]() |
(image-show (drawing->image sawtooth 64 20))
|
![]() |
Topics: Procedures, drawings as values, generalization.
The following code creates a drawing similar to that used by Color Matters on their color theory page to illustrate different readings of the same color.
(define yellowgreen-context-drawing
(drawing-hscale
(drawing-vscale
(drawing-hshift
(drawing-vshift
(drawing-group (drawing-recolor drawing-unit-square "green")
(drawing-hshift (drawing-recolor drawing-unit-square "yellow") 1)
(drawing-hshift
(drawing-vscale
(drawing-recolor drawing-unit-square "greenyellow")
0.25)
0.5))
0.5)
0.5)
50)
200))
|
![]() |
a. Define a procedure called drawing-color-in-context
that generalizes the code as much as possible. That is, you must
imagine what things someone who calls your procedure might want to
vary or customize.
b. Write a short statement explaining what parameters your procedure has and why. In addition, explain parameters you chose not to use.
Topics: Procedures, raster graphics, generalization.
A quincunx is a formation of four items in a square or rectangle, plus a fifth in the center, such as on the side of a standard die with five dots.
Write a procedure (
that changes the pixels in the four corners and the center
of image-quincunx!
image rgb-color)image to rgb-color.
Topics: RGB colors, Procedures, Numbers
Sometimes we want to take two RGB colors and blend them in some way. For example, we might blend colors “smoothly” by taking an average over their components. At other times we may want more drastic combinations. For example, we might want to use only the more intense or the less intense of each color component.
Write a
procedure, (,
that takes two RGB colors, and creates a new RGB color where each
component (red, green, and blue) is the smaller of the corresponding
component of the two colors.
rgb-min-blend
color1 color2)
>(rgb->rgb-list (rgb-min-blend (color-name->rgb "white") (color-name->rgb "black")))(0 0 0)>(color->rgb-list "mistyrose")(255 228 225)>(color->rgb-list "lemonchiffon")(255 250 205)>(rgb->rgb-list (rgb-min-blend (color-name->rgb "mistyrose") (color-name->rgb "lemonchiffon")))(255 228 205)>(color->rgb-list "springgreen")(0 255 127)>(color->rgb-list "bisque")(255 228 196)>(rgb->rgb-list (rgb-min-blend (color-name->rgb "springgreen") (color-name->rgb "bisque")))(0 228 127)
Topics: Numbers, Numeric Operations, Procedures
Consider using a compass oriented to the east. When you are facing the following directions, you get the following compass readings:
Write a procedure, (, according to the
following documentation.
turn
start-angle
amount-to-turn)
;;; Procedure: ;;; turn ;;; Parameters: ;;; start-angle, an integer ;;; amount-to-turn, an integer ;;; Purpose: ;;; Computes a final orientation after turning by amount-to-turn ;;; degrees, given start-angle in degrees. ;;; Produces: ;;; final-angle, an integer ;;; Preconditions: ;;; 0 <= start-angle < 360 ;;; Postconditions: ;;; 0 <= final-angle < 360
Consider the following procedure.
(define fun
(lambda (a b c)
(min (max (min a b) c) (max (min b c) a))))
a. In your own words, describe what
fun computes.
b. In your own words, explain how
fun works.
Images are often represented, not in colors, but simply as brightness values. Casually called black-and-white, these images are usually referred to as "grayscale," because each pixel contains a single number representing the brightness on a "gray scale" from black to white. Like color components, brightness values are represented on a scale from 0 to 255.
A common operation is to threshold such an image to convert it into a "binary" representation that contains only two values, black and white (represented by zero and 255, respectively), so that any brightness at or above the threshold becomes white, and any value below becomes black.
Write a procedure (
that takes a brightness brightness-threshold
gray-value thresh)gray-value and a corresponding
threshold thresh, returning 0
if gray-value is less
than thresh, and 255 otherwise.
Note: Your solution should only use numeric operations, such as those found in the lab on numeric values.
Write the 6-P documentation for
your brightness-threshold procedure.
Here we will post answers to questions of general interest. Please check here before emailing your questions!
gray-val is between 0 and
255?
Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to a point of extra credit for everyone. We usually limit such extra credit to five points. However, if we make an astoundingly large number of errors, then we will provide more extra credit.