CS 1101 - A-term 12

Homework 2 - Cond and Structs

Due: Tuesday, Sept 4 at 5pm

Read the expectations on homework. You will be doing this homework and all subsequent homeworks with your homework partner.

Assignment Goals

The material you need to know to complete this homework assignment will be covered in class on Thursday, Aug. 30

The Assignment

Programming with Cond and Structs

The website for a movie theater contains information about each of the films currently being shown in the theater. The following information is stored for a film:

Your solutions to the following problems should use helper functions in place of repeated code. You may also introduce helper functions to improve the readability of your code.

Remember to include a contract, purpose, and test cases for every function you write.

  1. Provide data definitions for both a film and a date. Include both the define-structs and at least three examples for each data definition. (You should define a date with the idea in mind that you will want to write functions that are capable of comparing dates. See problem 6, below.)

  2. In a comment in the Defintions Window, state the contracts of all the operators that are created by DrRacket for your film struct.

  3. Write a program suitable-for-children? which consumes a film and returns true if the rating of the film is G, PG, or PG-13, and returns false otherwise.

  4. Write a program difference-in-receipts. The program consumes two films and produces a number. The number produced is the difference between the box office receipts for the two films (the result should be a non-negative number).

  5. Write a program modify-rating which consumes a film and a symbol, and produces a film. The film that is produced is the same as the original except that the film's rating has been replaced by the given rating. (Your function may consume a film and a string instead of a film and a symbol, if you chose to represent the rating as a string.)

  6. Write a program opens-before?, which consumes a film and a date, and produces a boolean. The function produces true if the given film opens before the given date, and returns false otherwise.


Here is the grading rubric that the graders will use for Homework 2.

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 for homework files. In addition, BOTH partners' names and wpi ccc usernames MUST be listed in a comment at the top of your file (you will lose points if these rules are not followed). Programs are due at 5pm on Tuesday, September 4. Late programs will be accepted until 5pm on Wednesday, September 5. Programs will not be accepted for submission after 5pm on Wednesday, September 5. No exceptions.