UNB/ CS/ David Bremner/ teaching/ cs2613/ assignments/ CS2613 Assignment 1

What to hand in, and how to hand it in, and when

Marking

Questions

Solve the following (Exercise 8 from FICS) using #lang htdp/bsl

Part 1

Using the clock struct defined by:

    (define-struct clock (hours mins secs))

to represent 24-hour time (midnight is 00:00:00, one second before is 23:59:59), write the function tick that consumes a clock struct c and produces the clock struct representing the time one second after the time represented by c. Use modular arithmetic (i.e. the functions modulo, remainder, and/or quotient)

Here are some test cases to help explain how the function should work

(check-expect (tick (make-clock 23 59 59))
              (make-clock 0 0 0))
(check-expect (tick (make-clock 23 58 59))
              (make-clock 23 59 0))
(check-expect (tick (tick (make-clock 23 59 58)))
              (make-clock 0 0 0))

Part 2

Define a second function tick* that does the same thing (in particular passes all of the same tests) as tick, but does not use modular arithmetic.