Fundamentals of Computer Science I (CSC-151.02 2000F)


Exam 2: Intermediate Scheme

Distributed: Friday, October 27, 2000
Due: 11 a.m., Monday, November 6, 2000
In order to turn the exam in after the due date, you must make arrangements by Wednesday, November 1, 2000. I will not necessarily grant extensions, but I realize that some of you have special circumstances.

This page may be found online at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Exams/exam.02.html.

Preliminaries

There are six problems on the exam. Each problem is worth seventeen points. The point value associated with a problem does not necessarily correspond to the complexity of the problem or the time required to solve the problem. If you write down the amount of time you spend on each question, I'll give you three points of extra credit.

This examination is open book, open notes, open mind, open computer, open Web. Feel free to use all reasonable resources available to you except for other people and for exam and homework solutions. 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. Do not use exam or homework solutions you find on the Web.

This is a take-home examination. It is likely to take you about five to ten hours, depending on how well you've learned topics and how fast your work. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date. If you expect to need to turn in the exam late, you must make arrangements by Wednesday, November 1, 2000.

You must include the following statement on the cover sheet of the examination. Please sign and date the statement. Note that the statement must be true; if you are unable to sign the statement, please talk to me at your earliest convenience.

I have neither given nor received help on this examination (other than from Sam Rebelsky). I am not aware of any other students who have given or received help on this examination (other than from Sam Rebelsky).

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'll have no chance of finishing the exam.'' You may also summarize these policies.

Answer all of your questions electronically and turn them in in hardcopy. That is, you must write all of your answers on the computer and print them out. You should also email me a copy of your exam (a plain text file, please). Put your answers in the same order that the problems appear in. If you give an example of one of "Sam's easy to misinterpret scribbles" along with the actual meaning and the interpreted meaning, I'll give you three points of extra credit.

I will give partial credit for partially correct answers. You ensure the best possible grade for yourself by emphasizing your answer and including a clear set of work that you used to derive the 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 yo u 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 classes next week to discuss any general questions you have on the exam.


Problems

Problem 1: Reading Desires

You may recall that we defined the dating desires for each datee in our dating service as something like the following:

Each desire is one of the following: (1) a list consisting of the symbol characteristic and a string; (2) a list consisting of a symbol for one of the base characteristics (such as eyecolor) and an appropriate corresponding value (typically a string or a number); (3) a list consisting of the symbol likes and a string; (4) a list consisting of the symbol agerange and two integers.

Here's a sample list of desires

(define jacks-desires
  '((characteristic "cute")
    (characteristic "smart")
    (eyecolor "blue")
    (eyecolor "hazel")
    (height 70)
    (height 71)
    (height 72)
    (height 73)
    (likes "computer science")
    (likes "voting")))

However, most of us wrote relatively primitive procedures for reading in desires. Now is your chance to remedy that problem. Document, write, and test a procedure, read-desires, that reads in as many desires as the client wishes to enter. Your procedure should return a list of desires.

Hint: You may also want to define a read-one-desire helper.

Problem 2: Do we really need read-person?

Sarah and Steven Schemer suggest that it was just too much effort to write the read-person procedure for homework 3. ``After all,'' they say, ``clients can just enter information about themselves in DrScheme, as in the following.''

> (define me 
    '(("John" "Doe" male both 33
      ((height 66) "handsome" "creative" "smart")
      ("fast cars" "lego" "computer science")
      ((characteristic "cute")
       (characteristic "smart")
       (eyecolor "blue")
       (eyecolor "hazel")
       (height 70)
       (height 71)
       (height 72)
       (height 73)
       (likes "computer science")))))
> (suggest-dates me datees)

Write two or three paragraphs that argue for or against their position.

Problem 3: Where's the if?

Sarah and Steven have encountered the follow procedure that does not meet their model for predicates. In particular, they can't find the if.

;;; Procedure:
;;;   same-person?
;;; Purpose:
;;;   Determine if two people are the same.
;;;   Currently, that the two people have the same name, but that
;;;   may change.
;;; Parameters:
;;;   Two people in the appropriate form.
;;; Returns:
;;;   #t, if they are; #f otherwise.
;;; Preconditions:
;;;   All people are in the approved form.
;;; Postconditions:
;;;   Does not affect the parameters.
(define same-person?
  (lambda (person1 person2)
    (equal? (get-datee-full-name person1)
            (get-datee-full-name person2))))

Explain to Sarah and Steven how this can code can work, even though it lacks an if.

Problem 4: Listing Likes

Believe it or not, but I let my wife play with our dating service (with a cleverly created database that suggests me first. She noted that it would be helpful to see a list of the adjectives that people have already submitted. I'm turning the problem over to you. Write a procedure, list-likes that takes a list of datees as a parameter and returns a list that contains all the likes listed, with no duplicates.

For this problem, any helper procedures should be local to list-likes

Problem 5: Counting Characters

a. Write a procedure, (count-chars pred? string) that counts how many characters in a string match a predicate. For example, (count-chars char-alphabetic? "Hello world.") should return 10.

b. Using count-chars, write a procedure count-punc that counts the number of punctuation characters that appear in a string. Except for count-chars, all helpers must be local. For the purposes of this question, the punctuation characters are apostrophe ('), colon (:), comma (,), quotation mark ("), exclamation point (!), parentheses (( and )), period (.), question mark (?), and semi-colon (;).

Problem 6: Splitting Strings

Write a procedure that takes two strings (a source string and a split string) as parameters and returns a list of strings that correspond to the parts of the source string separated by the split character. For example,

> (split "Hello there you fool" " ")
("Hello" "there" "you "fool")
> (split "alpha,beta,gamma" ",")
("alpha" "beta" "gamma")
> (split "fufie fubar fun" "fu")
("" "fie " "bar " "n")

History

Wednesday, 24 October 2000

Friday, 26 October 200

Monday, 30 October 2000


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Exams/exam.02.html

Source text last modified Mon Oct 30 12:05:18 2000.

This page generated on Mon Oct 30 12:09:05 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu