Quiz 1

Instructions

Problem 1

Write brief answers for each of the following items (two sentences each, max).

Problem 2

Answer each of these questions about the structure of Racket lists.

Problem 3

At UNI, a student's charge for a semester is the sum of tuition and fees. Tuition is a product of the number of credits taken times the current cost per credit.

Write a Racket function named total-ubill that takes three arguments, all numbers: the number of credits taken, the cost per credit, and the fees for the term.

total-ubill returns the student's total u-bill: the number of credits taken times the cost per credit, plus the fees for the term. For example:

> (total-ubill 12 100 100)       ; 12 * $100 + $100
1300

> (total-ubill 6 500 1000)       ; 6 * $500 + $1000
4000

Problem 4

For Problem 3 on Homework 3, you worked with lists of pairs. Each pair contained a height in inches and a weight in pounds. (76 . 195) and (79 . 225) are examples of such pairs.

Write a Racket function named max-height that takes one argument, a height n.

max-height returns a function as its value. That function takes one argument, a height-weight pair, and returns whether the height is no more than n. For example:

> ( (max-height 76) '(76 . 195) )
#t
> ( (max-height 76) '(81 . 212) )
#f
> (define 6-6-or-less? (max-height 78))
> (6-6-or-less? '(79 . 225))
#f

Problem 5

For Problem 5 on Homework 3, you worked with a list containing spreadsheet data: a header row followed by one row for each course, with names, capacities, and enrollments.

'(("Dept" "Number" "Section" "Class Nbr" "Capacity" "Enrollment")
  ("CS" "1000" "1" "11546" "30" "30")
  ("CS" "1025" "1" "11547" "30" "30")
  ("CS" "1120" "1" "11557" "30" "14")
  ("CS" "1130" "1" "11548" "30" "18"))   ; any number of items

Write a Racket function named total-enrollment that takes such a list as its only argument.

total-enrollment returns the total enrollment across all sections. For example:

> (define example '(...))          ; the data shown above
> (total-enrollment example)
92                                 ; 30 + 30 + 14 + 18

Remember: Racket has a function named sixth!

You may write other helper functions if you like, but you do not have to. No recursion or looping are allowed. Use functional programming.