CS 1101 - Cterm 12
Homework 2 - Nested Structs, Unions, Basic Lists
Due: Tuesday, January 31 at 5pm
Read the expectations on homework.
Assignment Goals
- To be able to define data using nested structs
- To be able to define unions of data
- To be able to define lists
- To be able to develop templates for structs, unions, and lists
- To make sure you can write programs over nested structs, unions, and
basic lists
The Assignment
Make sure you provide an adequate set of test cases for
each function you develop (including helper functions).
Nested Structs
In this part of the assignment you will modify the student record struct that you defined in Homework 1 so that a
student record also contains the student's date of matriculation. The date
itself should be a struct.
- Develop a data definition for a date,
where each date consists of a month, day, and year, all of which are represented
by numbers. Develop a data definition for a student record, where each student record
consists of the student's name, ID number, year of graduation, grade point
average, number of credits earned so far, and date of matriculation. Provide
at least 2 examples of each kind of data.
- Define a function called
earlier-date
that consumes two
dates and returns the one that occurs earlier.
- Define a function called
matriculated-before?
that consumes
a student record and a date and returns true if the student's date of matriculation
occurred before the given date.
Unions
- A student record for a grad student is different from a student
record for an undergrad. Develop a data definition for a grad record,
which consists of the following information: name of student, ID number,
type of financial support (one of "TA" for teaching assistant, "RA" for research
assistant, "Fellow" for fellowship, or "None"), number of credits earned
so far, and the name of the student's advisor. Provide at least 2 examples of
grad records.
- Provide a data definition for a student, which can be either
a student record or a grad record.
-
Provide the template(s) for functions over students.
-
Define a function called
supported-student?
that consumes a
student and returns a boolean. The function returns true if the student
is a grad student supported as a TA, RA, or fellowship. The function returns
false if the student is an undergrad or is a grad with no financial support.
- Define a function called
add-credits
that consumes a student
and a number of credits and produces a student the same as the original,
except that the given number of credits have been added to the
student's total.
Basic Lists
- Write the data definition for list-of-string. Make at least three examples
of lists of strings.
- Write the template for a function over a list-of-string.
- Write a function
got-word?
that consumes a list of strings
and a string and produces true if the given string occurs at least once
in the list.
- Write a function
all-strings?
that consumes a
list of strings and a string and produces true if every string in the list matches the given string. The function produces false otherwise. (Hint: the
empty case should produce true).
- Write a function
small-strings
that consumes a
list of strings and a number. The function produces a list of only those
strings that have fewer than the given number of characters.
What to Turn In
Here is the grading rubric that the TAs will
use when they grade Homework 2.
Using web-based turnin,
turn in a single file containing
all code and documentation for this assignment.
Name your file according to the
naming conventions for files. Put both partners' names
and wpi login names in a comment at the top of the file.