Assignment 1

CS 146
due February 20, 2001
100 points

Implement a relation class, and test with the main function in the file a1.cpp, obtainable from the class web site.

Your class should support the methods add_pair, clear, size, transitive_closure, and related, as implied by the given main function. The transitive closure function may be a mutator. You should also have a constructor of 0 arguments, and you should overload the << operator to handle relations. You should provide a copy constructor, an assignment operator, and a destructor if necessary.

You needn't optimize your representation to provide the most efficient possible implementation of the transitive_closure relation. We will be discussing this issue later in class.

For full credit, you should provide a class template for relations. For a 10-point penalty, you may instead provide implementations of a version of the relation class for each element type or class given in the main function.

You are encouraged to use inheritance to reduce your workload.