1. List of Numbers

You can use the data definition of List of Numbers from our lecture to answer the following questions

Practise Exercises
  • 1) Desing a function that takes a list of numbers and returns their product, i.e., multiplies all the numbers together.

  • 2) Design a function that takes a list of number and returns the same list of numbers but with the last element removed

    • ex. (remove-last (cons 1 (cons 2 (cons 3 empty)))) ⇒ (cons 1 (cons 2 empty))

  • 3) Design a function called occurrences that given a List of Numbers and a Number n returns the number of times n appears in the list.

  • 4) Design the functions all-even? that given a list of numbers, returns true if all elements of the list are even and false otherwise

2. List of Letter Grades

Recall our definition of a letter grade (one of 'A, 'A- etc.).

Practise Exercises
  • 5) Provide a data definition for a list of letter grades LoLG

  • 6) Design a program that given a LoLG will return a list of number grades. Your program must use the following mapping of letter grade to number grade

    Letter Grade

    Number Grade

    'A

    100

    'A-

    95

    'B+

    90

    'B

    85

    'B-

    80

    'C+

    75

    'C

    70

    'C-

    65

    'D

    50

    'E

    0

    HINT: You might want to create a data definition for a list of number grades

  • 7) Design a program that takes a list of number grades and returns a list with the corresponding letter grade. Your program must use the following ranges for translating a number grade to a letter grade.

    Letter Grade

    Number Grade Range

    'A

    [100, 96]

    'A-

    [95, 91]

    'B+

    [90, 86]

    'B

    [85, 81]

    'B-

    [80, 76]

    'C+

    [75, 71]

    'C

    [70, 66]

    'C-

    [65, 51]

    'D

    [50, 30]

    'E

    [29, 0]

  • 8) Design a function called passing that given a LoLG returns a list of all the passing grades. A passing grade is greater or equal to 60.

  • 9) Design a function called curve that takes a LoLG and the number of points to add to each grade and returns the updated LoLG.

3. Disks and Scenes

You are working with a team that is building a new game. The game is displayed in a window that has a height and a width. As part of the game there are disks (displayed as circles) that we must display in our window. Here is an incomplete attempt to design part of the game that you inherited.

(define-struct disk (radius center color))
;; A Disk is a (make-disk NonNegInteger Posn String)
;; INTERP: represents a disk with a radius, the center of the disk as a
;;         coordinate and the disk's color name


(define-struct window (width height))
;; A Window is a (make-window NonNegInteger NonNegInteger)
;; INTERP: represents the size of our window with its width and height
Practise Exercises
  • 10) Complete the given data definition(s).

  • 11) Design a function that given 2 disks will return true if the 2 disks overlap and false otherwise. Two disks overlap if the distance between their centers is smaller than the sum of their radii.

  • 12) Design a data definition for a list of disks LoD.

  • 13) Design a program that given a LoD returns the disk with the maximum y-coordinate value. In the case of an empty LoD your function should report an error. To see how you can create an error with an error message lookup the documentation for the function error and check-error for testing errors.

  • 14) Design a function that given a LoD and a Window returns an LoD that contains all the disks whose center is within the window’s area.