Csc 1302, Honors Principles of Computer Science II (Fall 2023)

Week 3 (8 September 2023)

Clone tuple; Check membership of tuple in relation; and the Union, Intersect, and Minus Operators

During this week you will write the following methods:
  1. (Tuple.py) Clone a tuple object:
    	def clone(self, attr):
    		pass
    
    This method creates a new copy of the tuple with the attributes set to attr and returns it.
  2. (Relation.py) Check membership:
    	def member(self, t):
    		pass
    
    This method returns True if tuple t is present in relation and False otherwise.
  3. (Relation.py) Union operator:
    	def union(self, r2):
    		pass
    
    This method returns the union of two relations (self and r2); It should remove duplicates before returning. Clone the tuples from the input relations and then add to output.
  4. (Relation.py) intersect operator:
    	def intersect(self, r2):
    		pass
    
    This method returns the intersection of two relations (self and r2); Clone the tuples from the input relations and then add to output.
  5. (Relation.py) minus operator:
    	def minus(self,r2):
    		pass
    
    This method returns the difference of two relations (self and r2); Clone the tuples from the input relations and then add to output.

Download the Driver Programs and implement all the methods in this assignment. Compile and run the driver programs. You should see the following output when you run Driver.py:

[raj@tinman w3]$ python3 Driver.py
REL1(COL1:INTEGER,COL2:VARCHAR)
Number of tuples: 5

1111:Robert Adams:
1112:Charles Bailey:
1114:Richard Johnson:
1115:Graham Gooch:
1116:John Miller:

REL2(COL1:INTEGER,COL2:VARCHAR)
Number of tuples: 5

1113:John Smith:
1112:Charles Bailey:
1115:Graham Gooch:
1116:John Miller:
1117:Hugh Howell:

REL1_UNION_REL2(COL1:INTEGER,COL2:VARCHAR)
Number of tuples: 7

1111:Robert Adams:
1112:Charles Bailey:
1114:Richard Johnson:
1115:Graham Gooch:
1116:John Miller:
1113:John Smith:
1117:Hugh Howell:

REL1_INTERSECT_REL2(COL1:INTEGER,COL2:VARCHAR)
Number of tuples: 3

1112:Charles Bailey:
1115:Graham Gooch:
1116:John Miller:

REL1_MINUS_REL2(COL1:INTEGER,COL2:VARCHAR)
Number of tuples: 2

1111:Robert Adams:
1114:Richard Johnson: