F08-CS135-mt2 - Warning The content of 08135 changes from...

Info icon This preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Warning The content of 08135 changes from term t This exam may Ora gym] not correspond toth fluent content of t \course and thus may diffe_r\___s___I__ ificantly from the exam you will be expected to write. This document is for the exclusive use of x8wen. This document is for the exclusive use of x8wen. UNIVERSITY OF Waterloo University of Waterloo Midterm Examination #2 Term: Fall Year: 2008 Student Name UW Student ID Number Course Abbreviation and Number Course Title Section(s) Instructors (Please circle your instructors name!)( 2D CS 135 Designing Euze%lam Pro 001 —011 my Vasiga @911" ecker, Ian Goldberg, Brad Lu shman, Time Period ) Date of Exam Duration Number of Exam Pages (including this cover sheet) Exam Type Additional Material Allowed (”October 27, 2008 Start time: 7:00 pm End time: 9:00 pm 120 minutes 12 pages Closed Book UW—Approved Calculators This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: Marking Scheme (for graders’ use only): Question Maximum Score 1 7 6 15 (r \\ - MaxicmquBB S ore: 82 Some important notes: HH/ 0 Regarding design recipes: ) — For functions that we ask you to write, you must include a contract but are not required to include the purpose, examples, or tests, unless otherwise specified. — For helper functions you create, you must include contract and purpose but are not required to include examples or tests. — You do not need to write out data analysis or templates unless we specifically ask for it. 0 Functions you write may call: — Any function you have written in another part of the same question — Any function we asked you to write for a previous part of the same question (even if you didn’t do that part) — Any other built-in function discussed in class (with the exception of reverse and append) CS 135 Page 2 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: 1. (7 points) Draw “box-and-pointer” pictures corresponding to the following structures: (a) (2 points) (cons 3 (cons 4 (cons ”blue empty))) (b) (5 points) (list (list ‘I 2) (list 3 (list 4) empty 5)) Q 2. (6 points) For each of the following four constant defi 'tions, (-_wylin alternate (but equivalent) definition that does not use cons or empty: \ (a) (1 point) (define 0 empty) _ \ < )- (b) (1 point) (define b (con-s. em\_1_ty emp ) / (c) (2 points) (define c (cons (cons 1 empty) (cons (cons 2 empty) empty))) (d) (2 points) (define d (cons (cons 4 (cans "four" (cons ’four empty))) empty)) CS 135 Page 3 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: 3. (7 points) Write the function max3 lists which consumes three lists of numbers (all with the same length) and produces a list where the number at position i is the maximum of the numbers at position i of the consumed lists. For example, (maxj’lists (list '1 '10 100) (list 4 ‘I 99) (list 3 9 ‘I 01)) should produce (list 4 10 101). If the lists are not the same length, you should evaluate (error ’max3lists “Inputs are not same length“). CS 135 Page 4 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: 4. (27 points) A note is a structure (make-note pitch dur), where pitch is a symbol and dur (for “duration”) is a positive number. A silence is a structure (make-silence dur), where dur is a positive number. A melody is a non-empty list of notes and silences which ends with a note. (a) (5 points) Write structure definitions for note and silence, and a data definition for melody. 3\ (b) (5 points) Write a template for a function th\t\con umes a melody - \ Q __\__ _ ) CS 135 Page 5 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: (c) (7' points) Write a scheme function count-silence which consumes a melody and produces the sum of the durations of all the silences in the melody. CS 135 Page 6 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: (d) (10 points) A melody is called “monotone” if every note in the melody has the same pitch. Write a predicate function monotone? which consumes a melody and produces true if and only if the melody :9 ( \ J O -\\ \ " C )/._ This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: 5. (20 points) A natural number n is called a perfect number if the sum of the distinct positive factors of to (not including to itself) is equal to n. For example, 28 is a perfect number because its factors are l, 2, 4, 7, and 14, which sum to 28. Some other perfect numbers are 6, 496, and 8128. (a) (6 Points) Write a function factors<=i which consumes two natural numbers, n and 3', and produces a list of all the factors of n, which are at least 1 and less than or equal to 3'. The list can be in any order but should not have any duplicates. CS 135 Page 8 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: (b) (7' Points) Write a function perfect? which consumes a natural number n 2 2 and produces true if n is a perfect number and false otherwise. Include a contract of perfect?, and both a contract and a purpose (but not examples or tests) for any helper functions. CS 135 Page 9 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: (c) (7' Points) Although every known perfect number is even, an odd perfect number might still exist. Computers are useful to search for such things. Write a function odd-perfecr-search which consumes two odd positive integers a. and b and produces the smallest odd perfect number in the range from a. to b (inclusive), or false if none exists. You should include a data definition for odd positive integers. (d) (10300 Points Bonus) Give an example of an odd perfect number. CS 135 Page 10 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: 6. (15 points) Write a function list-lisI-pick which consumes a list of lists of numbers and a natural number n, 2 1 and produces the nth number in the list of lists (counting each number in each list), or false if there aren’t enough numbers in the list of lists. For example, the function call (list-list-pick (list (list 4 2O 3) (list 16 82 29 8)) 5) should produce the value 82. CS 135 Page 11 of 12 This document is for the exclusive use of x8wen. CS 135 Midterm Examination #2 Fall 2008 ID Number: (Extra space for any questions, if needed) CS 135 Page 12 of 12 This document is for the exclusive use of x8wen. ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern