CSci 1301: Problem Set 2

Due: Wednesday, September 18 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.

Problem 1 (10 points)

Recall the function first-letter-A? that we wrote in class. Here is our code (with slightly modified test cases):

;; (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=? (substring str 0 1) "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. Write a function A? that consumes a string and returns true if this string is "A" and false otherwise. Use the tests we've written in class to test your function. Don't forget to write test cases for your function.
  2. Change first-letter-A? to use A? as a helper function instead of directly checking that the substring is "A". first-letter-A? should work exactly as before (pass all the same check-expect tests).
  3. 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).
    Before you start changing first-letter-A? for this question, make a copy of your solution for question 2 and comment it out. This way you can always go back if you get to it (and I cajn grade it separately from your answer to this question).
  4. Write a function a-or-A? that consumes a string and returns true if this string is "A" or "a" and false otherwise.
  5. Write a function first-letter-a-or-A? that works according to its name.

Problem 2 (2 points)

Modify the version 5 of the landing rocket example (figure 4 in Prologue so that when the width of the scene is changed, the rocket is placed in the middle of the new scene.

Problem 3

Exercises 24 (5 points) and 25 (5 points) in Section 2.2.


CSci 1301 course web site.