Part 1

What value is produced by the following functions?

  1. (<= −2 3) produces true.
  2. (>= 4 4) produces true.
  3. (and (< 3 7) (> 4 2)) produces true.
  4. (or (< 2 −5) (> 2 1)) produces true.
  5. (string<? "apple" "apple") produces false.

Part 2

Write a Boolean function for each of the following. Introduce variables as appropriate.

  1. A number is greater than 7 or less than 3.
    (or (> x 7) (< x 3))
  2. A number is between, but not equal to, 1 and 11.
    (and (< 1 x) (< x 11))
  3. A person’s last name is Stock or Roberson.
    (or (string=? last-name "Stock") (string=? last-name "Roberson"))
  4. 3x ≤ 2x − 5
    (<= (* 3 x) (− (* 2 x) 5))

Part 3

Write a function that consumes a bank account number, and produces the account balance, as shown in the following table. If the account number is not in the table, the function should produce −1.

Account numberAccount Balance
107$46.82
108$38.24
109$101.77

(define (account-balance account-number)
  (cond
    [(= account-number 107) 46.82]
    [(= account-number 108) 38.24]
    [(= account-number 109) 101.77]
    [else −1]))

Computer Programming Unit 4 - Answers to Practice Questions for Mini - SA