to the MS Word document

advertisement
Comp200 – Elements of Computer Science MOCK EXAM #1
Rice University - Instructor: Dung Nguyen
October 5, 2005
NAME & ID#: _________________
Instructions
1. This is an open-notes, open-book (except “Turing”) exam.
2. You are free to use any materials that were given to you in the lectures.
3. You are free to use DrScheme and EXCEL and any on-line help materials that these software provide.
4. When you are done, upload all of your work to the “Exam1” assignment on the course WEBCT.
Please write and sign the Rice Honor Pledge here:
1
2
3
4
Total
1. The following is the labbie pay rate at the CS Department.

$10 for labbies with less than one year of experience

$11 for labbies with a year or more of experience.
Design an EXCEL spreadsheet that produces the pay rate given the number of years of experience. The spreadsheet
should clearly has cells containing problem constants, cells containing all the variables of the problem and cells
containing all relevant formulas. All the cells must be clearly labeled. Use the IF function.
See the payrate sheet of mockExam1Sol.xls for the EXCEL solution.
2. Consider the logic word problem done in class:

Ed will go to the party if and only if Dan or Carol goes.

Dan will go if and only if Ann goes and Bob does not.

Ann and Carol and Bob have decided not to go.

What will Ed do?
Solve the problem by writing a Scheme Boolean function with the following contract, header and purpose. Define
and use auxiliary functions whenever appropriate.
; Contract:
; ed_goes: Boolean Boolean Boolean  Boolean
; Header:
; (define (ed_goes ann bob carol) …)
; Purpose:
; (ed_goes ann_goes bob_goes carol_goes) returns true or false depending
;on whether or not ann_goes, bob_goes, carol_goes, based on the assumptions
;of the problem.
2/6/2016
1 of 3
Comp200 – Elements of Computer Science MOCK EXAM #1
Rice University - Instructor: Dung Nguyen
October 5, 2005
NAME & ID#: _________________
; Contract:
; ed_goes: Boolean Boolean Boolean -> Boolean
; Header:
; (define (ed_goes ann bob carol) …)
; Purpose:
; (ed_goes ann_goes bob_goes carol_goes) returns true or false
; depending on whether or not ann_goes, bob_goes, carol_goes,
; based on the assumptions of the problem.
; Examples:
; Since we have solved the problem using EXCEL, we can use the
; results from the EXCEL spreadsheet as examples here.
; (ed_goes false false false) is false
; (ed_goes false false true) is true)
; NOTE: What if we do not know any of the answers and want to write a
; program that will give us some answers?
; Definition:
(define (ed_goes ann bob carol)
;Ed will go to the party if and only if Dan or Carol goes.
(or (dan_goes ann bob) carol))
; Contract
; dan_goes: Boolean Boolean -> Boolean
; Header
; (define (dan_goes ann bob) ...)
; Purpose
; (dan_goes ann bob) returns true iff ann is true (i.e. ann goes)
; and (not bob) is true (i.e. bob does not go).
; Examples:
; (dan_goes false false) is false)
; (dan_goes true false) is true)
; Definition:
(define (dan_goes ann bob)
(and ann (not bob)))
; Test:
(dan_goes false false) ; is false
(dan_goes true false) ; is true)
3. Design a logic circuit to represent the following sentence.
Ann makes dinner if and only if
 John washes the dishes and
 Mary sets the table and
 there is food in the refrigerator.
Use EXCEL to set up the truth table for the above.
Solution: Let A = Ann makes dinner, J = John washes the dishes, M = Mary sets the table, F = there is food in the
refrigerator. Then the above sentence can be written as A = (J AND M) AND F.
The corresponding logic circuit looks like the following
2/6/2016
2 of 3
Comp200 – Elements of Computer Science MOCK EXAM #1
Rice University - Instructor: Dung Nguyen
October 5, 2005
NAME & ID#: _________________
J
M
A
F
See the makesdinner sheet of mockExam1Sol.xls for the truth table.
4. Write the Boolean expression for the logic circuit below. Use EXCEL to set up its truth table. Write an
equivalent Scheme Boolean function.
Solution:
See majority sheet of mockExam1sol.xls for the EXCEL truth table.
Scheme Boolean functions:
; x = a AND b
(define (x a b)
(and a b))
; y = a OR b
(define (y a b)
(or a b))
; z = y AND c
(define (z a b c)
(and (y a b) c))
; w = x OR z
(define (w a b c)
(or (x a b) (z a b c)))
A
X = A AND B
W = X OR Z
B
Y = A OR B
Z = Y AND C
2/6/2016
C
3 of 3
Download