程序代写代做代考 DrRacket cisc108-s17-exam1.pages

cisc108-s17-exam1.pages

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Name:_______________________________________

You have 75 minutes to complete the exam. You may have with you a single piece of
paper with notes on both sides. You may have only your sheet of notes, a single
writing implement, and the exam on your desk (e.g., no cell phones, laptops, etc.).

You do not need to show contracts, purposes, templates, or test cases unless
specifically asked. However, they will earn you partial credit if you can not provide a
complete solution.

While you wait, limber up your writing implement by sketching a motivational picture.


Question 0 (20 points)

Question 1 (15 points)

Question 2 (20 points)

Question 3 (25 points)

Question 4 (20 points)

Total (100 points)

Page � of �1 10

James Clause

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Question 0: Terminology (20 points)


Page � of �2 10

;; AppleColor is “red”, “green”, or “yellow”

;; CrispNumber is a number between [1, 10]

(define-struct apple (weight color crunchiness))
;; make-apple: Number AppleColor CrispNumber -> Apple
;; Interpretation:
;; — weight is the weight of the apple in ounces
;; — color is the color of the apple
;; — crunchiness is how crisp the apple is
(define APPLE1 (make-apple 8 “red” 9))
#;
(define (apple-fun anApple)
… (apple-weight anApple) … ; Number
… (apple-color anApple) … ; AppleColor
… (apple-crunchiness anApple) … ; CrispNumber
)

(define-struct banana (weight ripe?))
;; make-banana: PositiveNumber Boolean -> Banana
;; Interpretation:
;; — weight is the weight of the banana in ounces
;; — ripe? is true if the banana is ripe, false otherwise
(define BANANA1 (make-banana 4 true))

;; a Fruit is either an Apple or a Banana
#;
(define (fruit-fun aFruit)
(cond [(apple? aFruit) (apple-fun aFruit)]
[(banana? aFruit) (banana-fun aFruit)]))

;; edible?: Fruit -> Boolean
;; consumes: a fruit
;; produces: true if the given fruit is edible, false otherwise
(define (edible? aFruit)
(cond [(apple? aFruit) (apple-edible? aFruit)]
[(banana? aFruit) (banana-ripe? aFruit)]))

(check-expect (edible? APPLE1) true)

_______ comment

_______ interval

_______ enumeration

_______ itemization

_______ parameter

_______ argument

_______ template

_______ clause

_______ constant

_______ unit test

_______ Fruit

_______ predicate

_______ constructor

_______ selector

_______ structure definition

_______ constant definition

_______ function definition

_______ signature

_______ function call

_______ boolean

Match the term to the letter.
Some terms may not
appear (choose “Z”) or may
appear more than once
(choose any letter).

A

B

D
E

E

F

G

H

I

J

K

L

M

O

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Question 1: Simple Function (15 points)
Design a function rph->mpg that converts rods per hogshead (rph) to miles per gallon
(mpg). Show the signature, purpose statement, test(s), and definition for the function.

Domain specific information:
• 1 hogshead = 63 gallons
• 1 rod = 0.003125 miles
• 40 rph is approximately 0.001984126 mpg

0.001984126 mpg = ((40 rph * 0.003125 miles) / 63 gallons)

Page � of �3 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Page � of �4 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Question 2: Cond (20 points)
The playing cards suits are spades, hearts, diamonds, and clubs. Design a function that
converts suites to their corresponding images (i.e., it consumes a suit and produces the
corresponding image—spades: ♠, hearts: ♥, diamonds: ♦ and clubs: ♣). Remember that
DrRacket supports image literals. Don’t try to try to create the images using image operations
(e.g., circle, overlay, etc.). Just draw them.

Page � of �5 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Page � of �6 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Question 3: Data Definitions and Templates (25 points)
The Dunder Mifflin paper company sells paper in two sizes: Letter and A4 and three
colors: white, yellow, and green. All paper orders are handled in a single unified
interface. An order for letter paper needs to indicate the number of sheets, the paper
color, and whether the sheets are lined. An order for A4 paper needs to indicate the
number of sheets, the paper color, and whether the sheets have holes.
Develop a data definition for a PaperOrder and either a LetterOrder or an A4Order.
Provide additional data definitions for other types, as necessary.


Page � of �7 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Page � of �8 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Question 4: Structures (20 points)
Consider the following definitions:

(define-struct date (day month year))

;; make-date: Number Number Number -> Date

;; interp: day is the day of the date

;; month is the month of the date

;; year is the year of the date


(define-struct post (date content))

;; make-post: Date String -> Post

;; interp: date is the date of the post

;; content is the content of the post

Design a function that accepts a post and a year and produces true if the given post
was made during the given year (i.e., the year of the post’s date is the same as the
given year) and false otherwise.

Page � of �9 10

CISC 108: Introduction to Computer Science I, Spring 2017 Exam 1

Page � of �10 10