0% found this document useful (0 votes)
19 views

Important Note:: Total-Dur

1. The lab defines data structures for events, cards, and clocks and provides tasks to work with lists of these structures. 2. The tasks include creating functions to calculate the total duration of a list of events, filter a list of cards by suit to get values, update a list of clocks by a number of minutes, find the maximum value card in a list, and calculate the average duration of events of a given type. 3. Proper list processing using cond and empty?, first, and rest is required to solve the problems.

Uploaded by

AndrewChan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Important Note:: Total-Dur

1. The lab defines data structures for events, cards, and clocks and provides tasks to work with lists of these structures. 2. The tasks include creating functions to calculate the total duration of a list of events, filter a list of cards by suit to get values, update a list of clocks by a number of minutes, find the maximum value card in a list, and calculate the average duration of events of a given type. 3. Proper list processing using cond and empty?, first, and rest is required to solve the problems.

Uploaded by

AndrewChan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 8

IMPORTANT NOTE:
The template for processing a list:
(define (fn-list-name alist)
(cond
[(empty? alist) ]
[else ... (first alist) ...(fn-list-name (rest alist)) ...]))

This lab makes use of the following structure and data definitions:
(define-struct event (type dur))
;; An event is a structure (make-event t d), where
;; * t is a symbol (the type of event) and
;; * d is a positive integer (the duration in minutes).

(define-struct card (value suit))


;; A card is a structure (make-card v s), where
;; * v is an integer in the range from 1 to 10 and
;; * s is a symbols from the set hearts, diamonds,
;; spades, and clubs.

(define-struct clock (hours mins))


;; A clock is a structure (make-clock h m), where
;; * h is an integer in the range from 0 to 23 and
;; * m is an integer in the range from 0 to 59.

1. Create a function total-dur that consumes a list of events and produces the total duration
in minutes.
2. Create a function values that consumes a symbol (a suit) and a list of distinct cards and
produces a list of numbers, that is values of cards from the original list that have the
specified suit.
3. Create a function update-times that consumes a list of clocks and a natural number m (a
number of minutes) and produces a list of updated clocks, each m minutes later on the same
day (you can assume none of the new times go past midnight to the next day).
4. Create a function max-card that consumes a nonempty list of cards and produces a card
with the maximum value of any card in the list (if there is more than one, the one appearing
closest to the end of the list).
5. Create a function average-length that consumes a list of events and a
symbol (the
type of the event) and produces the average duration of events of that type.
If a list is
empty or there are no events of a particular type, the average will be zero.
Be careful
not to divide by zero!

You might also like