Structure Problems

Before we tackle lists, we'll get used to simply building and and manipulating structured data. Remember to follow the Design Recipe for structures.

  1. Provide a datatype definition for a structure called a pit, representing points in time since midnight. A point in time consists of three numbers: hours, minutes, and seconds.

    Now develop the function time-diff. It consumes two pits, t1 and t2, and returns the number of seconds from t1 to t2. 

    For example:
    (time-diff (make-pit 1 2 3) (make-pit 4 5 6)) 

    should yield 10983. If you would like, I have written up a complete solution, which may give you a sense for what I think a full solution looks like.

  2. Provide a structure definition and a data definition for a game-score. A game-score is characterized by two pieces of information: a symbol representing the name of the team and a number representing the points-scored by that team.

  3. Develop a function that consumes two game-scores from a particular game and returns the name of the team that won or 'tie if the scores were equal. 

  4. Develop a datatype definition for a position in two-dimensional space called a posn. A posn should have an x and a y coordinate. 

  5. Provide a datatype definition for shapes. There are three kinds of shapes:
    1. A circle has a center (center isa posn?) and a radius (radius isa number?)
    2. A square has an upper-left corner (corner isa posn?) and a length (length isa number?)
    3. A rectangle has an upper-left corner (corner isa posn?), width (width isa number?), and height (height isa number?

    In each case, remember to provide a clear comment regarding the structure along with its definition.

  6. Develop the function area that consumes a shape and computes its area.

  7. Develop the function in-shape? that consumes a shape and a posn, and returns true if that posn is within the shape, false otherwise.