CS 1101 - Cterm 12

Homework 2 - Nested Structs, Unions, Basic Lists

Due: Tuesday, January 31 at 5pm

Read the expectations on homework.

Assignment Goals


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.
  1. 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.

  2. Define a function called earlier-date that consumes two dates and returns the one that occurs earlier.

  3. 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

  1. 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.

  2. Provide a data definition for a student, which can be either a student record or a grad record.

  3. Provide the template(s) for functions over students.

  4. 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.

  5. 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

  1. Write the data definition for list-of-string. Make at least three examples of lists of strings.

  2. Write the template for a function over a list-of-string.

  3. 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.

  4. 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).

  5. 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.