Functional Problem Solving (CSC 151 2015S) : Assignments
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Assigned: Wednesday, 3 February 2015
Due: The due dates for various tasks are as follows.
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.
This examination has a prologue that must be completed by the Friday evening before the exam is due. The prologue is intended to help you get started thinking about the examination. The prologue is required. Failure to fill in the prologue by the designated time will incur a penalty of five points on the examination.
This examination has an epilogue that must be completed by the evening after the exam is due. The epilogue is intended to help you reflect carefully on the examination. The epilogue is required. Failure to fill in the epilogue will incur a penalty of five points on the exam.
There are seven problems on this examination. Each problem is worth the same number of 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 four hours, depending on how well you've learned the topics and how fast you work. You should not work more than five hours on this exam. Stop at five hours and write “There's more to life than CS” on the cover sheet of the examination and you will earn at least the equivalent of 70% on this exam, provided you recorded the time spent on each problem, filled in the prologue by the specified deadline, filled in the epilogue, and arranged for a meeting with me within one week of receiving your graded exam. You may count the time you spend on the prologue toward those five hours, but not the time you spend on the epilogue.. With such evidence of serious intent, your score will be the maximum of (1) your actual score or (2) the equivalent of 70%. The bonus points for errors and recording time are not usually applied in the second situation, but penalties (e.g., for failing to number pages) usually are.
You should not count time reviewing readings, laboratories, or assignments toward the amount of time you spend on the exam or on individual problems.
We 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 for the exam. Because we worry about the amount of time our exams take, we will give two points of extra credit to the first two people who honestly report that they have completed the exam in four hours or less or have spent at least four hours on the exam. In the latter case, they should also report on what work they've completed in the four hours. After receiving such notices, we 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 as well as any students who worked with you. 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, via IRC, 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.” 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 write, 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.
Exams can be stressful. Don't let the stress of the exam lead you to make decisions that you will later regret.
You must present your exam to me in two forms: both physically and electronically.
For the physical copy, you must write all of your answers using the computer, print them out, number the pages, staple them together (except for the cover sheet), and hand me the printed copy. For your benefit and for ours, we are doing blind grading on this examination, so you have been assigned a number to use on your exam. Please make sure that your number appears at the top of every page. You should turn in a separate cover sheet along with your stapled and printed answers. The cover sheet should include (1) the two hand-written academic honesty statements (individually signed and dated, if it is appropriate for you to sign each), (2) your name, and (3) your assigned number. If you choose to invoke the “there's more to life than computer science” option, then you must indicate that option on the cover sheet, and you should indicate it only on the cover sheet.
The code and comments in your printed copy must use a fixed-width (a.k.a., monospaced or fixed-pitch) font; depending on what platform you use, viable candidates include Monospace, Courier, Courier New, Monaco, DejaVu Sans Mono, Free Mono, Liberation Mono, and Lucida Sans Typewriter. Failure to format your code with a monospace font will result in a penalty. You may read the instructions on printing for more details on how to create readable output.
You must also submit the code for your examination at http://bit.ly/151-2015S-exam1. Ideally, you would put all of the code
for the exam in a single Racket file. However, if you have created
separate files for the separate parts of the exam, you can just
paste them one after another when you submit, provided you put a
clear separator, such as ; PROBLEM 2, between sections.
In both cases (physical and electronic), you should put your answers in the same order as the problems. Failure to number the printed pages will lead to a penalty. Failure to turn in both versions may lead to a much worse penalty.
While your electronic version is due at 10:30 p.m. Tuesday, your physical copy will be submitted in class on Wednesday. It is presumed the physical copy matches the electronic copy. Any discrepancies (other than formatting) will be considered a misrepresentation of your work and referred to the Committee on Academic Standing.
In many problems, we ask you to write code. Unless we specify otherwise in a problem, you should write working code and include examples that show that you've tested the code informally (by looking at what value you get for various inputs) or formally (by using the Rackunit testing framework). In addition to the examples provided in the exam, you should also provide additional examples. Do not include resulting images; we should be able to regenerate those.
Unless we tell you otherwise, you should assume that you need to document every primary procedure with the six Ps. If you write helper procedures (and it's often a good idea to write helper procedures), you need only document those with a sentence or two that gives their purpose. (We would prefer that you use the 6P style, but won't require it.)
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. Because we should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify in the preliminaries and problems on this exam. We will limit that form of extra credit to five points.
We will give partial credit for partially correct answers. We are 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 (8am-10pm), feel free to try to call me (cell phone (text only) - 641-990-2947).
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: Numeric computation, Rounding
Increasingly, restaurants include recommended tips on the bill. Surprisingly, their calculations of percentages are not always correct. While we might just use the calculated tip that now appears on many bills, a surprising number of the systems that calculate those tips do so incorrectly, and certainly inexactly. And, even when they do calculate correctly, they aren't universally available. Hence, we might write a procedure to compute a tip for us.
Write, but do not document, a procedure (,
that computes the tip and presents it in a reasonable form.
tip
cost percent)
>(tip 100 17)17.0>(tip 100 18)18.0>(tip 99 17)16.83>(tip 0.99 17)0.17>(* .99 .17)0.1683>(tip 21.50 17)3.66>(* 21.50 .17)3.6550000000000002
As many examples suggest, you'll sometimes need to do a bit more than just multiply by the percent divided by 100.
Topics: Documentation
Document the tip procedure from the previous
problem. Make sure to use the 6P documentation style.
Topics: Drawing as values, Image basics, Side effects
A designer or artist might call attention to part of an image by obscuring other parts of the image, covering them with a sheet or with a simple color wash.
Write, but do not document, a procedure,
(, that takes a simple approach to
obscuring images: It puts a rectangle of half the width and half the
height of the image in the lower-left corner of the image and another
rectangle of the same size in the upper-right corner.
image-obscure! image
color)
For example,
|
(define kitten (image-load "/home/rebelsky/Desktop/kitten.jpg"))
|
|
(image-obscure! kitten "teal")
|
Topics: Drawing as values, Image basics, Side effects, File basics
Write, but do not document, a procedure, (, that does the following:
obscure-image
infile outfile
color)
infile,
image-obscure! you wrote in the previous
problem, and
outfile.
Once such a procedure is available, one can more quickly process an image, without even bothering to show it in GIMP. For example, we used it to generate the second image for the previous exercise with a command like the following.
> (obscure-image "/home/rebelsky/Desktop/kitten.jpg"
"/home/rebelsky/Desktop/teal-kitten.jpg"
"teal")
Topics: Drawings as values, Unit testing
In a recent assignment, we centered one drawing on another drawing. Let's now consider a variant of centering in which we make one drawing the same size and position as another drawing, which might allow us to substitute one for the other in a larger diagram. We'll call this transformation “re-forming” a drawing (which is not the same as “reforming”).
Here's some 6P-style documentation for the re-form
procedure.
;;; Procedure: ;;; re-form ;;; Parameters: ;;; source, a drawing ;;; target, a drawing ;;; Purpose: ;;; Shift and scale source so that it occupies the same location ;;; and dimensions as target. ;;; Produces: ;;; result, a drawing ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; (drawing-left result) = (drawing-left target) ;;; (drawing-top result) = (drawing-top target) ;;; (drawing-right result) = (drawing-right target) ;;; (drawing-bottom result) = (drawing-bottom target) ;;; result looks like source - same colors, same collection of ;;; shapes
Here's the start of a test-suite for re-form.
;;; Name:
;;; target1
;;; Type:
;;; drawing
;;; Value:
;;; A 20x10 rectangle with left edge at 15 and top edge at -5.
(define target1
(hshift-drawing
25
(hscale-drawing
20
(vscale-drawing
10
drawing-unit-square))))
;;; Name:
;;; red-unit-circle
;;; Type:
;;; drawing
;;; Value:
;;; The unit circle, recolored red (diameter 1, top 0, left 0)
(define red-unit-circle
(hshift-drawing 0.5
(vshift-drawing 0.5
(recolor-drawing "red" drawing-unit-circle))))
;;; Name:
;;; re-form-test
;;; Type:
;;; Rackunit test suite.
;;; Value:
;;; A test suite for the re-form method.
(define re-form-test
(test-suite
"Tests of re-form"
(test-case "Maintain color and shape, scaling unit circle"
(check-equal? (drawing-color (re-form red-unit-circle target1))
(drawing-color red-unit-circle))
(check-equal? (drawing-type (re-form red-unit-circle target1))
'ellipse))
(test-case "Appropriate size and position, scaling unit circle"
(check-= (drawing-left (re-form red-unit-circle target1))
(drawing-left target1)
0.01)
(check-= (drawing-top (re-form red-unit-circle target1))
(drawing-top target1)
0.01)
(check-= (drawing-right (re-form red-unit-circle target1))
(drawing-right target1)
0.01)
(check-= (drawing-bottom (re-form red-unit-circle target1))
(drawing-bottom target1)
0.01))))
Here's a valiant, but incorrect definition of re-form.
(Amazingly, this definition passes our test suite, which suggests
a particularly good incorrect definition, an incomplete test suite,
or both.)
(define re-form
(lambda (source target)
(hshift-drawing
(drawing-left target)
(vshift-drawing
(drawing-top target)
(hscale-drawing
(drawing-width target)
(vscale-drawing
(drawing-height target)
source))))))
Write a more comprehensive test suite that would help us determine
whether or not a definition of re-form is correct.
You should make sure that you test different positions, sizes, and
shapes (and relative shapes and sizes) for both source and target.
You should be confident that a procedure that passes your tests is likely to correctly handle any pair of valid drawings, and that any procedure that can correctly handle any pair of valid drawings will pass your tests.
Topics: Drawings as values
Write, but do not further document, the re-form
procedure described in the previous problem. Ideally, your procedure
would pass all of your tests (and all of our tests).
Topics: Drawings as values, Code reading, Documentation, Code formatting
Consider the following procedure, which is not only poorly named, but also has poorly-named parameters.
(define whatever (lambda (x y color d) (image-show (drawing->image (drawing-group (hscale-drawing (max color (drawing-right y)) (vscale-drawing (max d (drawing-bottom y)) (hshift-drawing 0.5 (vshift-drawing 0.5 (recolor-drawing x drawing-unit-square))))) y) (max (drawing-right y) color) (max (drawing-bottom y) d)))))
Make this procedure definition easier to read as follows.
First, reformat the procedure so that the indentation properly demonstrates nesting. That is, you should choose appropriate points to put in spaces and carriage returns. Remember that DrRacket will re-indent for you after you put in those returns, as long as you select the text and type Tab.
Then, figure out what the procedure does. You might analyze the code to understand it. You might run it and look at the results. You might do a combination of the two.
After you understand what the procedure does and what roles the parameters play, change the names in the procedure to clarify the roles of various things. You should certainly rename the procedure and the parameters; both the procedure and the parameters should have clear names that the average reader would understand.
Finally, write introductory comments (the six Ps) to explain
the purpose (and the other Ps) of your improved version of the
procedure formerly named whatever.
When you format your exam, please put the introductory comments before the revised procedure definition.
At the end of fall 2014, I asked my 151 students for advice they would give to future 151 students. Here are some of their comments.
Here we will post answers to questions of general interest. Please check here before emailing your questions!
; PROBLEM 216.830000000000002
rather than 16.83. What's going wrong?
2015-02-06
exact->inexact and
inexact->exact procedures to get it in the
form you'd like. Do the computation in exact form. That means
that all the numbers you write explicitly should be exact (e.g.,
1/100 rather than .01) and that you will need to convert the inputs
to exact form. Once you've done the computation in the exact world,
you can convert back to inexact form for output.
exact->inexact.
(obscure-image "/home/rebelsky/Desktop/kitten.jpg"
"/home/rebelsky/Desktop/teal-kitten.jpg"
"teal")
Can you explain why?
2015-02-09
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. (And no, we don't count errors in the errata section or the question and answer sections.)
image-obscure procedure is supposed
to havethree parameters, but only two are presented in the
example. [NR, 1 point]
f rather
than whatever. [ZB, 1 point]
y values should
probably be drawing-unit-square. [EE, 1 point]
Some of the problems on this exam are based on (and at times copied from) problems on previous exams for the course. Those exams were written by Janet Davis, Rhys Price Jones, Samuel A. Rebelsky, John David Stone, Henry Walker, and Jerod Weinman. Many were written collaboratively, or were themselves based upon prior examinations, so precise credit is difficult, if not impossible.
Some problems on this exam were inspired by conversations with our students. We thank our students for that inspiration. Usually, a combination of questions or discussions inspired a problem, so it is difficult and inappropriate to credit individual students.
The advice on taking this exam was written by students in the fall 2014 section of CSC 151 and edited by SamR.
The photograph of the kitten was released for public use at
http://public-photo.net/displayimage-2485.html.
It appears that site is now down.