Week 6: Exercises

1. Rectangle Class

Write a class Rectangle representing a rectangle in 2 dimensions. The class should support these operations:

2. Circle Class

Write a class Circle representing a circle in 2 dimensions. The class should support these operations:

3. Vector Class

Write a class Vector that represents a vector in n-dimensional space. (We partially implemented this class in the lecture.)

4. Date Class

Write a class Date representing a month and day. The class should support these operations:

5. Matrix Sum

Write a function that computes the sum of two matrices A and B, represented as lists of lists. Assert that the matrices have the same dimensions.

6. Matrix Product

Write a function that computes the product of two matrices A and B, represented as lists of lists. Assert that the matrices have dimensions that are compatible for multiplication.

7. Cycle

Write a function cycle that takes a list of length N representing a permutation of the integers 0, …, N – 1. The function should return True if the permutation is a single cycle. For example: