Quiz 1
Instructions
- The quiz consists of five questions and one image.
- Read all the questions thoroughly before you begin. It is worth your time to plan ahead!
- The quiz is worth 60 points. Each question is worth twelve points.
- Partial credit will be given where possible, so show your work.
- The quiz lasts thirty (30) minutes. It is due at 1:45 PM.
Problem 1
Write brief answers for each of the following items (two sentences each, max).
- One of the three things that every programming language has is a means of abstraction. We have used two means of abstraction in Racket. List both of them.
- List the other two things that every programming language has. Give an example of each from Racket.
- Explain the distinction in Racket between a function and special form. Give an example of each from Racket.
- What does it mean to say that we curry a function?
Problem 2
Answer each of these questions about the structure of Racket lists.
-
Draw a box-and-pointer diagram that shows the structure
of this Racket list:
(cons (cons 1 2) (cons 3 (list 4 5)))
- Write the Racket literal corresponding to the list shown in this box-and-pointer diagram.
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.