Programming 1, 2021-22
Week 8: 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.

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

5. Grep

The well-known utility 'grep' prints all lines in a file that contain a given string:

$ grep world ulysses
Gleams that untravell'd world whose margin fades 
'T is not too late to seek a newer world.
$

If you include the '-i' option, it matches lines without regard to case:

$ grep -i achilles ulysses
And see the great Achilles, whom we knew.

Write 'grep' in Python:

$ python3 grep.py -i achilles ulysses
And see the great Achilles, whom we knew.