On this page:
Review Problems
Before You Go...

Lab 7 Exam Review


Purpose: The purpose of this lab is to practice what you have learned in the course thus far.

Review Problems

Exercise 1 U.A. High School needs a way to keep track of all the students who are training to become heroes. Each student has a name, a year, and a Quirk (a special hero ability). There are only 3 years of high school at this school so your data design should not allow for other years to be recorded. Design data to represent a HeroStudent. Be sure to follow all the steps of the data design recipe.

Exercise 2 Obviously there is more than one student at U.A. High School. Design data to represent a ClassRoster: an arbitrary number of HeroStudents. Be sure to follow all the steps of the data design recipe.

Exercise 3 Design the function graduating-class which takes a ClassRoster and returns only the students who are in year 3 of high school.

Exercise 4 Take a look at the following function which checks if a string is longer than a certain length. Find 3 problems with the function’s design and fix them.
; longer? : String Nat -> Boolean
; Takes a string and a number and returns a boolean which is true if the string is longer
; than the number
(check-expect (longer? "hello" 3) #t)
(define (longer? str n)
  (if (> (string-length str) n) #t #f))

Exercise 5 Consider the following data definitions:
(define-struct student [name age gpa])
; A Student is a (make-student String Nat PositiveNumber)
; and represents a student with a name, age (in years), and GPA
; NOTE: This data definition is not as restrictive as it should be but we have simplified for
; the sake of time
(define-struct parent [name phone kids])
; A Parent is a (make-parent String Nat [List-of Student])
; and represents a parent with a name, phone number, and some students they are the parent of
(define-struct call [one others])
; A CallList is one of:
; - "nobody"
; - (make-call Parent CallList)
; and represents a list of parents to call in an emergency
Finish the steps of the data design recipe for the above definitions.

Exercise 6 The school district needs to know which parents to call for a particular school. Design the function parents-of-age which takes a CallList and two positive integers representing the minimum and maximum age at a particular school. The function returns a CallList of parents who have at least one child in the given age range.

Before You Go...

If you had trouble finishing any of the exercises in the lab or homework, or just feel like you’re struggling with any of the class material, please feel free to come to office hours and talk to a TA or tutor for additional assistance.