## 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

• To make sure you can define structs
• To make sure you can write functions using conditions, structs, and nested structs

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:
• the title of the film
• the film's genre (drama, comedy, family, etc.)
• the film's rating. A rating can be one of G, PG, PG-13, R, NC-17, NR.
• the running time of the film, in minutes
• the date the film opened at the theater (it should include the month, day, and year)
• the total box office receipts collected so far for the film (in millions of dollars)

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.