CSC151.02 2010S Functional Problem Solving : Exams
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment] [Quiz]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Quizzes] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Assigned: Wednesday, 10 February 2010
Due: Beginning of class, Wednesday, 17 February 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 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.
Find and record two reasonable definitions of functional programming. You might look on the Web, in textbooks (programming languages textbooks are best), or in dictionaries.
For each definition, indicate how the Scheme you've learned to date has and has not matched the definition.
You should make sure to cite the sources you use in appropriate format.
Topics: Numbers, Numeric Operations, Procedures
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.
Suppose we make it our policy to give a tip of as close to 17% as possible on any meal. We will likely find it useful to write a procedure that computes the tip for us.
Write a procedure, (
that computes the tip and presents it in a reasonable form.
tip
cost
),
>
(tip 100)
17.0
>
(tip 99)
16.83
>
(tip 0.99)
0.17
>
(* .17 .99)
0.1683
As the last example suggests, you'll need to do a bit more than just
multiply by 17%. Hint: The round
procedure is
likely to be your friend.
Topics: Procedures, GIMP tools, generalization.
The following code draws a circle with a slash through it, as on “No Smoking” signs.
(context-set-fgcolor! "red") (context-set-brush! "Circle (05)") (image-select-ellipse! canvas REPLACE 0 0 100 100) (image-stroke! canvas) (image-draw-line! canvas 0 0 100 100) (image-select-nothing! canvas) (context-update-displays!)
Write a procedure called image-draw-no-sign!
that
generalizes the code as much as possible.
Note that part of the problem is to decide what the appropriate parameters to this procedure should be.
Write a sequence of instructions using GIMP tools that create the flag of Pakistan.
Note that to create the star, you will need to use a polygonal
selections The MediaScheme
procedure image-select-polygon!
allows you to
do this by giving it a sequence of positions, which are created with
the
procedure (
. For
example, here is a sequence of instructions that adds a triangle to
an image.
position-new
col
row
)
(context-set-bgcolor! "red") (define canvas (image-new 100 100)) (image-select-polygon! canvas REPLACE (position-new 50 0) (position-new 0 75) (position-new 75 75)) (context-set-fgcolor! "black") (image-fill! canvas) |
![]() |
Topics: Drawings as values
Additional topics: Numeric calculations
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.
Some of you have criticized the drawing-scale
procedure
because it scales not only the size of the drawing, but also the
position of the center of the drawing. How can we solve that problem?
For simple drawings (that is, just a rectangle or just an ellipse),
the strategy is pretty simple: Shift the center of the drawing to (0,0),
scale the drawing, and then shift the center back to its old place.
Implement a procedure, (
that resizes a drawing using this strategy. You can assume
that you have working drawing-resize
drawing
factor
)drawing-center-x
and
drawing-center-y
procedures.
As you may know, one of the techniques employed by the painter Andy Warhol was to draw multiple copies of an image, each in a different color or on a different color background.
Write a procedure (
, that makes a 2x2 grid of copies of warhol
drawing
)drawing
, with the copies recolored to red, green, yellow, and blue.
In the previous problem, you considered one form of Warhol painting, one in which the drawing itself is recolored. Another possibility is to recolor the background of the drawing.
Write a procedure (
, that makes a 2x2 grid of copies of andy
drawing
)drawing
, each on a different color background. (You can choose the four colors for the background.)
Topics: RGB colors, Procedures, Numbers
Write a procedure rgb-redder-wrap
that takes an
RGB color and produces a new color that has the red component
increased by 16. If the increase should take the new component value
above 255, the new red component should "wrap around" starting at zero.
>
(rgb-red (rgb-redder-wrap (rgb-new 16 255 128)))
32
>
(rgb-green (rgb-redder-wrap (rgb-new 16 255 128)))
255
>
(rgb-blue (rgb-redder-wrap (rgb-new 16 255 128)))
128
>
(rgb-red (rgb-redder-wrap (rgb-new 128 128 128)))
144
>
(rgb-red (rgb-redder-wrap (rgb-new 239 17 96)))
255
>
(rgb-red (rgb-redder-wrap (rgb-new 240 17 96)))
0
>
(rgb-red (rgb-redder-wrap (rgb-new 245 17 96)))
5
>
(rgb-red (rgb-redder-wrap (rgb-new 255 17 96)))
15
Here we will post answers to questions of general interest. Please check here before emailing your questions!
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.
selection-replace
rather than REPLACE
in code for the “no” sign. [MS & DD, 1 point]
drawing-center-y
in Problem 6. [IY, 1 point]
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment] [Quiz]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Quizzes] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Copyright (c) 2007-10 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.