CSci 1301: Problem Set 2

Due: Wednesday, September 23 at 11:59pm by e-mail

Please test all your programs carefully and include all the test cases with your program. You should have at least 3 tests for each function, except the ones that produce an image or a scene.
Every function must have a contract.

Problem 1 (6 points)

Recall the function first-letter-A? that we wrote in class. Here is our code:

;; (first-letter-A? str) -> boolean
;; str: string
;; consumes a string, returns  true 
;; if this string starts with a capital A, otherwise returns false
(define (first-letter-A? str)
  (string=? (string-ith str 0) "A"))

(check-expect (first-letter-A? "AbC") #true)
(check-expect (first-letter-A? "abC") #false)
(check-expect (first-letter-A? "bcde") #false)
;(check-expect (first-letter-A? "") #false)
(check-expect (first-letter-A? "aaAAaaaa") #false)
Working from this example, perform the following steps:
  1. Add the case to handle the empty string in the function (it must return #false for it, as the commented out test case indicates). You can use cond or if or (better!) combine your conditions using boolean operations, such as and, or, not (either approach will get full credit if works correctly).
  2. Write a function first-letter-a-or-A? that returns #true if this string starts with "A" or "a" and false otherwise. It must return false for an empty string. Make sure to write test cases and the description (contract) for your function.

Problem 2

Exercises 37 (3 points), 38 (4 points, assume that the image is a square of image-height by image-width), 39 (3 points), and 40 (3 points) in Section 3.2.

CSci 1301 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.