Unformatted text preview:

CS3 Fall 05 – Midterm 1Read and fill in this page nowYour name: ___________________________________Your instructional login (e.g., cs3-ab): ___________________________________Your lab section days and time: ___________________________________Your lab T.A.: ___________________________________Name of the person sitting to your left: ___________________________________Name of the person sitting to your right: ___________________________________Prob 0: Prob 1: Prob 2:Prob 3: Prob 4 (a/b/c):--- --- Prob 5 (a/b/c): Raw Total: /50 Scaled Total: /30You have 70 minutes to finish this test, which should be reasonable; there will be approximately 10 additional minutes of leeway given. Your exam should contain 6 problems (numbered 0-5) on 10 total pages. It includes the code from the case study Difference Between Dates Part II in an appendix at the end.This is an open-book test. You may consult any books, notes, or other paper-based inanimate objects available to you. Read the problems carefully. If you find it hard to understand a problem, ask us to explain it. If you have a question during the test, please come to the front or the side of the room to ask it.Restrict yourself to Scheme constructs covered in chapters 3-6 and 11 of Simply Scheme, the Difference Between Dates case study, parts 1 and 2, and the Roman Numerals case study. You can always use helper procedures, and procedures from other questions you've answered.Please write your answers in the spaces provided in the test; if you need to use the back of a page make sure to clearly tell us so on the front of the page. We believe we have provided more than enough space for your answers, so please don’t try to fill it all up.Partial credit will be awarded where we can, so do try to answer each question.Relax!Instructional Login ________________Problem (1 point, 1 minute)Put your login name on the top of each page. Also make sure you have provided the information requested on the first page.Problem (7 points, 11 minutes). Fill in the blanks.Each of the following parts has a blank that you need to fill in. For parts (1)-(5), the blank follows an ; fill in the result of evaluating the scheme expression that comes before the . If the scheme expression will result in an error, write ERROR in the blank. (word 'go (word 'cal (word 'for (word 'evah (word "")))))  __________________________________________(se 'go (se 'cal (se 'for (se 'evah (se "")))))  __________________________________________(word (sentence 'word 'is 'the 'word))  __________________________________________(sentence (word 'word 'is 'the 'word))  __________________________________________(+ 3 ____________ 5 )  ERRORFor parts (6)-(8), fill in the blank so that the resulting scheme expression evaluates to the result shown. Don't use any parentheses. If it is impossible to do so, write IMPOSSIBLE in the blank. (define (doit x) (cond ((equal? x 'a) 'hah) ((equal? x 'b) 'hab)))(doit ____________________ )  ERROR(or ______________ 'joe 'bob)  'joe(and ______________ 'joe 'bob)  'joe(Page 2)Instructional Login ________________Problem (7 points, 10 minutes). Line-em up and add-em.Write a procedure add-em which takes a sentence as input, and returns a number. The result number should be the sum of the numbers in the input sentence, starting at the beginning and continuing until something other than a positive number is reached.You may use helper procedures.(add-em '(1 4 2 0 934 -3 5))  7(add-em '(3 5 a 8 j 2))  8(add-em '(1 2 3 4))  10(add-em '(fred and sally sitting in a tree))  0(Page 3)Instructional Login ________________Problem (8 points, 12 minutes): Celebrity poker needs programmers like you.Write card-outranks? The procedure takes two cards and returns true if and only if the first card is bigger than second. Cards are represented by a two-character word, where the first character represents the rank (a, k, q, j, 0, 9, 8, 7, 6, 5, 4, 3, and 2), and the second character represents the suit (s, h, d, and c). For instance, 2h is the two of hearts, qc is queen of clubs, 0s is the 10 of spades, etc. For this problem, consider all spades to rank higher than hearts, which all rank higher than diamonds, which all rank higher than clubs.(card-outranks? 'ac '3d)  #f (card-outranks? 'kh 'qh)  #t (card-outranks? '4s '4s)  #fComment all your procedures. Assume you have a working version of outranks?, as you wrote in lab, to use. (Remember, outranks? takes two ranks and returns true if the first is higher than the second.)You need to use proper abstraction. In this case, you will need to define accessors, name them meaningfully, and include comments indicating their purpose. (Page 4)Instructional Login ________________Problem (3/3/12 points, 24 minutes): Can you span this?Part a (3 points). Write days-until-new-year, which takes a date and returns the number of days until the end of the year, inclusive. Remember that you have the procedures in the Difference between Dates case study at your disposal, including the day-span procedure. The answer should fit in the space below!(days-until-new-year '(january 3))  363(days-until-new-year '(december 31))  1Part b (3 points). Write hours-until-new-year, which takes a date and returns the number of hours until the end of the year. (Assume that you need to calculate from noon of the date given). (hours-until-new-year '(january 3))  8700 (hours-until-new-year '(december 29))  60 (hours-until-new-year '(december 31))  12(Page 5)Instructional Login ________________Part c (12 points). The following are buggy versions of the recursive procedure day-sum, defined in the cases study Difference between dates, part II. (The code for the case study is included as an appendix). The bugs result from small changes which are underlined.For each version, note whether the bug creates a problem in the •conditional , •the base case, •making the problem smaller, •calling the function recursively, or •combining the recursive calls.Also briefly describe in English the effect of the bug on the operation of day-span as a whole (not just on day-sum)—this should take between 1 and 2 sentences for each case. You might include an example call to day-span illustrating the problem, although this isn't necessary with a sufficient explanation (and, might be wrong!). Don't


View Full Document

Berkeley COMPSCI 3 - CS3 Midterm

Download CS3 Midterm
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS3 Midterm and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS3 Midterm 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?