[an error occurred while processing this directive] [an error occurred while processing this directive]
![]() |
|
Problem 1: The following is the labbie pay rate at the CS Department.
Write a function that produces the pay rate given the number of years of experience.
The main data in this problem are numbers representing the years of experience. It is partitioned into two parts:
To process this data, we need to have a way to check for the range in which the input data belongs. In Scheme, we use what is called a "cond." Here is the Scheme function that computes the above pay rate.
;;contract: pay-rate number->number
;;header: (define (pay-rate years)...)
;;purpose: (pay-rate years) returns 10 if years<1, 11 otherwise
;;examples:
;;(= (pay-rate .5) 10)
;;(= (pay-rate 1) 11)
;;(= (pay-rate 2) 11)
;;definition:
(define (pay-rate years)
(cond
[(< years 1) 10]
[(>= years 1) 11]))
The syntax for cond is as follows.
(cond [booleanExpr1 returnValue1] [booleanExpr2 returnValue2] etc... [else catchAllReturnValue])
In the above, booleanExpr1, booleanExpr2 denote what is called "boolean expressions." A boolean expression is something that represents true or false. Scheme has two atomic expressions, true and false, to represent the notion of truth and falsity.
The semantic for cond in the above is as follows.
Boolean algebra (named in honor of the mathematician George Boole who invented a pure logic math "game" just for the fun of it) deals with the formal computation of true/false. There are three operations on true/false: AND, OR, NOT. Here are the rules describing these operations. They are displayed in the form of "truth tables."
| x | y | x AND y |
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
| x | y | x OR y |
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
| x | NOT x |
| T | F |
| F | T |
All logical expressions can written in terms of the above three operations! Actually, we only need AND/NOT or OR/NOT. Electrical engineers use boolean algebra as the tool to design electronic circuitries. They build what is called "logic gates" that correspond to the boolean operations AND, OR, NOT, and from there, the digital computers!

Given two boolean expressions x, y, we define "if x then y" to be the boolean expression (NOT x) OR y.
Example (from Principles of Computer Science by Cullen Schaffer, Prentice Hall 1988):
Solution (to be discussed in class)

In class exercises; We will the Logical functions in EXCEL to set up truth tables for all the exercises done in the above.
Click here to download the solution.
© Dung X. Nguyen
Last revised 08/26/2007 12:00 AM