Lab 5

Remember:

Review

What does a structure definition do?
What does a data definition do?

(define-struct stage (is-below))
;; An LV is one of:
;; -- 'capsule
;; -- (make-stage LV)

Exercise 1: Write down some examples of LVs.

Exercise 2: Write the template for LV.


Quiz


Lists

Exercise 3: Write a function called count that takes a list of symbols and produces the length of the list. Run the function on a couple examples of different sizes, and use the Stepper to see the steps that evaluation takes. For each step, decide what kind of step it is: primitive, conditional, or plug-in.

Exercise 4: Design a function that takes a list of symbols and a symbol and returns a list like the original list but with the given symbol added to the end.

Exercise 5: Design a function that takes a list of numbers and a number n and returns a list of all the numbers larger than n.

Here is a data definition for a list of bills:
;; A list-of-bills is one of:
;; -- empty
;; -- (cons (make-bill string number) list-of-bills)
(define-struct bill (customer amount))

Write down some examples of lists of bills. Then write the template for functions consuming a list of bills.

Exercise 6: Design a function that takes a list of bills and computes the sum of all the bill amounts.

Exercise 7: Design a function that takes a list of bills and computes the average amount owed.

Exercise 8: Design a function that takes a list of bills and produces a list of all the customer names.

Here is the data definition for a list of stock trades:
;; A list-of-trades is one of:
;; -- empty
;; -- (cons (make-stock-sale symbol number number) list-of-trades)
;; -- (cons (make-stock-purchase symbol number number) list-of-trades)
(define-struct stock-sale (company shares price-per-share))
(define-struct stock-purchase (company shares price-per-share))

Exercise 9: Design a function that takes a list of stock trades and returns a list of the traded companies (that is, their stock symbols).

Exercise 10: Design a function that takes a list of stock trades and a symbol and returns the total value of shares of that stock traded.

Here are some data definitions for weather reports:
;; A weather-report is (make-weather-report date number)
(define-struct weather-report (date avg-temp))
;; A date is (make-date number number number)
(define-struct date (year month day))

Exercise 11: Design a function that takes a list of weather reports, a number low, and a number high, and produces a list of dates with average temperatures between low and high.

Exercise 12: Design a function that takes a list of weather reports and returns the average temperatures.

Exercise 13: Design a function that takes a list of weather reports and two dates and produces a list of all the weather reports with dates between those two dates.