CS 1101 - Cterm 10

Homework 2 - Defining Structs

Due: Tuesday, January 26 at 5:00pm

Read the expectations on homework. You should do this and all subsequent homework assignments with your homework partner.

Assignment Goals


The Assignment

The Housing Office at a local college maintains a database of student dorm rooms. In this assignment, you will develop data definitions and functions for dorm rooms.

Remember that all functions should have a contract and a purpose, and should be tested using check-expect.

Problems

The Housing Office maintains the following information for every dorm room on campus: the name of the building in which the dorm room is located, the kind of building (for example, co-ed, quiet, substance-free, handicapped-accessible), the room number, whether or not the room is part of a suite, the maximum suggested capacity for the room, the actual number of students currently living in the room, the cost for the university to maintain the room per semester, and the Resident Advisor (RA) who oversees the room. The Resident Advisor information includes the RA's name, email address, and date of hire.
  1. Develop a data definition for a date. Remember that a data definition consists of the define-struct needed to model the definition, and the accompanying documentation. Provide three examples of dates. (Hint: think carefully about how you want to represent a date. Choose a representation that will make it easy to compare two dates, as in Problem 4, below).

  2. Develop a data definition for an RA. Provide three examples of RAs.

  3. Develop a data definition for a dorm room. Provide three examples of dorm rooms.

  4. Write a function earlier? that consumes two dates, and returns true if the first date occurs earlier than the second date. The function returns false otherwise.

  5. Write a function hired-before-date? that consumes an RA and a date. The function returns true if the RA was hired before the given date, and returns false otherwise.

  6. Write a function allocate-room which consumes a room and produces a room. The produced room is the same as the original, except that the current capacity of the room number of students currently living in the room is increased by one.

  7. The Housing Office is found to be in violation of city fire codes by indiscriminately adding additional students to a room over and above the maximum capacity. Write a function allocate-if-safe that consumes a room and produces a room. If adding an additional student to the room would exceed the maximum capacity of the room, the room is returned unchanged. Otherwise, the room that is returned is the same as the original, except that the current capacity number of students currently living in the room has been increased by one.

  8. Write a function room-charge that consumes a room. The function calculates the semester housing charge assessed to a student. The housing charge is calculated by adding 20% to the cost of maintaining the room, adding a surcharge of $300 if the room is part of a suite, and dividing by the number of current occupants in the room.

  9. Write a function match? that consumes a room, the kind of building a student wants to reside in, and a string that indicates whether the student wants to live in a "single", "double", or "triple". The room matches the student's criteria if the kind of building the student wants is the same as the kind of building the dorm room is in, and if the maximum capacity of the dorm room is the same as the capacity requested by the student (for a single, the maximum capacity should be 1, for a double, 2, and for a triple, 3). The function returns true if the given room matches the student's request, and returns false otherwise.

What to Turn In

Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Follow the naming conventions when naming your file. Both partners' names and login names must appear in a comment at the top of the file.