Last updated: Fri, 23 Jan 2015 17:43:09 -0500
The Program Design Recipe, sections 1-5
Style Guide Familiarize yourself with the design recipe style expectations.
Understand how the "shape" of a compound or itemization data definitions dictates the shape of a function that processes that kind of data (via the template).
- Representing Time: Use BSL to implement these exercises. For some of the exercises, the remainder and quotient functions may be useful.
Come up with a data definition named Time that represents the number of seconds ellapsed since (the last) midnight. Then implement the following functions:
- Implement the following function, where Time.v2 can be either equivalent to your previous Time data definition or a completely new data definition:
Did a particular time representation make it easier to write some of the functions and harder to write some others?
Can you think of any other Time representations? How does it affect your function implementations?
Luggage Scanner: Come up with a solution to the luggage scanner problem.
; Time Data Definition 1: ; A Time is a Natural, representing seconds since midnight.
; Time Data Definition 2: (define HOURS/DAY 24) (define MINS/HOUR 60) (define SECS/MIN 60) ; An Hours is a Natural in the interval [0,HOURS/DAY) ; A Minutes is a Natural in the interval [0,MINS/HOUR) ; A Seconds is a Natural in the interval [0,SECS/MIN) ; ; A Time is a (make-time Hours Minutes Seconds) ; Interp: represents a time of day, in 24hr format (define-struct time (hr min sec))
; Time Data Definition 3: ; A Time is a String, representing a time of day, ; WHERE: the string has the format: HH:MM:SS, ; where HH is a number in [0,24) representing hours ; MM is a number in [0,60) representing minutes ; and SS is a number in [0,60) representing seconds