CSC151.01 2009F Functional Problem Solving : Exams
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.02 2009F (Weinman)] [CSC151.02 2009S (Davis)] [CSC151 2008S (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Assigned: Wednesday, 16 September 2009
Due: Beginning of class, Wednesday, 23 September 2009
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 80 points 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 Rebelsky (that's me) or Professor Weinman.
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 (before 10 p.m. and after 8 a.m.), feel free to try to call me in the office (269-4410) or at home (236-7445).
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: Numbers, Numeric Operations, Procedures
As you may recall from the
lab on numeric values, the following expression had an
“interesting” effect on val
, provided
lower
and upper
were already defined.
> (define bounded-val (min (max val lower) upper))
A typical description of this code is that “bounded-val
is
a ‘bounded’ version of val
. That is, if
val
is larger than upper
, bounded-val
is capped at the value of upper
and if val
is
smaller than lower
, bounded-val
is capped at
lower
.”
Turn this expression into a procedure,
(
.
This procedure should have the effect described above.
That is, if bound
val
lower
upper
)val
is greater than
upper
, bound
should
return upper
and if val
is less than lower
, bound
should return lower
.
You may assume that upper
is at least as large
as lower
.
A typical use of bounding is to keep measurements in a particular range. Suppose we are measuring the blue component of a color. As you know, the blue component of a color cannot be less than 0 or more than 255.
Write a procedure, (
that takes a potential blue component
value as input, and returns that value as bounded below by 0 and above by 255.
In writing this procedure, you must call the bound-blue
bc
)bound
procedure you wrote earlier.
How does one measure the blue component of a color? Ideally, by using some cool optical sensors. Of course, optical sensors are expensive, and may be affected by ambient light. Hence, we more frequently just “eyeball it”, as in “Hey, Emerson, how much blue do you think is in this color?”
Many of the ways we estimate blue components (certainly “eyeballing it”, but even using some optical instruments) are, unfortunately, not very accurate. We might get a better estimate by taking multiple measurements (e.g., by asking seven people to estimate the blue component), throw out the lowest estimate and the highest estimate, and then average the remaining estimates.
Write a procedure,
(
, that implements this technique.
estimate-blue
m1
m2
m3
m4
m5
m6
m7
)
Do not call bound-blue
in writing
estimate-blue
.
4. The Morgan & Parker consulting company has suggested combining
bound-blue
and
estimate-blue
to get a better estimate.
However, each suggests a different combination.
(define morgan-estimate (lambda (m1 m2 m3 m4 m5 m6 m7) (estimate-blue (bound-blue m1) (bound-blue m2) (bound-blue m3) (bound-blue m4) (bound-blue m5) (bound-blue m6) (bound-blue m7)))) (define parker-estimate (lambda (m1 m2 m3 m4 m5 m6 m7) (bound-blue (estimate-blue m1 m2 m3 m4 m5 m6 m7))))
a. Are there any values of m1
.. m7
for which these two procedures return different values? If so, give one such set
of values. If not, explain why not.
b. Are there any values of m1
.. m7
for which these two procedures return the same value? If so, give one such set of
values. If not, explain why not.
c. Which of the two procedures do you prefer, and why?
Topics: Procedures, GIMP tools, generalization.
The following code draws a simple window of size 40x30 with a brown
outer frame of width 5 on an image called canvas
(image
11, in this session), with the top-left corner of the window at (100,80)
>
(context-set-fgcolor! "brown")
()
>
(image-select-rectangle! canvas REPLACE 95 75 50 40)
11
>
(image-select-rectangle! canvas SUBTRACT 100 80 40 30)
11
>
(image-fill! canvas)
>
(image-select-nothing! canvas)
11
Define a procedure called (
, that generalizes
the code above.
image-draw-window!
image
left
top
width
height
frame-width
)
The windows that we drew in the previous problem are relatively simple. More often, in representational drawings, we like four-paned windows.
Write a procedure, image-draw-four-paned-window!
that draws a four-paned window. In addition to the parameters above,
this procedure should take as a parameter the width/height of the
crossbar that separates the four panes. (That is, it's the width of
the vertical piece in the crossbar and the height of the horizontal
piece in the crossbar.)
As in the code for the previous problem, you should ensure that anything that would appear behind the “panes” of the window is left unchanged.
Topics: Drawings as values, Code reading, Debugging, Paradigms
The following code is intended to draw the flag of Sweden, a yellow cross on a blue field. (See Flags of the World - Sweden.)
This is not actually what it does. Fix it.
(define field (drawing-vscale (drawing-hscale drawing-unit-square 32) 20)) (drawing-recolor field "blue") (define vcross (drawing-hshift (drawing-hscale (drawing-vscale drawing-unit-square 20) 4) -4)) (define hcross (drawing-hscale (drawing-vscale drawing-unit-square 4) 32)) (drawing-recolor (drawing-group vcross hcross) "yellow") (define se-flag (drawing-group field vcross hcross)) (drawing-hshift se-flag 16) (drawing-vshift se-flag 10) (image-show (drawing->image se-flag 32 20))
Note: You should strive to make your corrections as concise as possible, doing your best to avoid introducing any additional variables.
Topics: Drawings as values, Conciseness.
Now that you've drawn the flag of Sweden, 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, such as the Swedish flag from
Problem 7.
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: 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)
Here we will post answers to questions of general interest. Please check here before emailing your questions!
rgb-bound
built into the circuitry.)
define
statement accomplishes the
task for particular values of val
,
lower
, and upper
. You
are to transform this into a procedure, no tests, conditionals,
or loops are required.
estimate-blue
provides an
exact integer?
(image-show (drawing->image ...))
.
drawing-...
and not the GIMP tools procedures,
such as image-select-rectangle!
.
diagonal
?
diagonal
procedure is
intended to create a drawing, not an image. The
resulting drawing should be the same width and height as
the original drawing. You can determine those with
drawing-width
and
drawing-height
, but scaling by
25% should suffice.
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.
my
appears instead of
m7
. [JD, 1 point]
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.02 2009F (Weinman)] [CSC151.02 2009S (Davis)] [CSC151 2008S (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Copyright (c) 2007-9 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.