Homework 4 Csc309.

Due Monday April 24, 2006 by 11:59pm.

Problem 1

(25 Points)

Add the following member functions to IntegerSet started in the class. You must demonstrate that these functions work by adding test cases to main. See review of sets at the end of this document

bool remove(int e)
If the element was in the set, remove it then return true
If the element is not in the set return false.

bool empty()
Returns true if the set is empty, false if the set has at least one element.

IntegerSet myUnion(IntegerSet set)
Returns an IntegerSet object that is the union of the two sets.

IntegerSet s3 = s1.myUnion(s2);

IntegerSet intersection(IntegerSet set );
Returns an IntegerSet object that is the intersection of the two sets.

bool subset(IntegerSet set );
Returns true if the calling object is a subset of the parameter object,
false otherwise.

IntegerSet complement()
Returns the complement of the set.
	           
IntegerSet difference(IntegerSet set)
Returns the difference of the two sets

bool equals(IntegerSet set)
Returns true if the sets have the same elements.

Work incrementally, that is after you write a method test it.


Extra Credit

(2 percent)

I suggest doing the extra credit. That is 2 percent applied to your overall percent.

Write a program that reads a text file of integers in the range [1,10] and prints out a frequency distribution of the values.

You must use at least one user defined class. The class you must define will keep track of the frequency for each integer. I would map the integer being counted to the cell of an array. Also your object should return as a string the frequency of each number. Recall the use of ostringstream class

For Example

Suppose your class was named FreqCount

FreqCount counter;     // creates object
counter.increment(1);  // would increase the count for 1.
counter.increment(2);  // would increase the count for 2.
counter.increment(2);        :
counter.increment(2);        :
counter.increment(3);        :
counter.increment(3);  // would increase the count for 3.
   :
   :

counter.toString()    // would return something like this.
                      //  1  -->  1
                      //  2  -->  3
                      //  3  -->  2
                        etc.

You can format the output anyway you like.

Turn in Instructions

Upload each problem to COL


Sets

Let A and B be sets where, A = { 3, 6, 8, 10 } , B = { 2, 5, 6, 8, 13}
and the Universe is the integers between 0 and 15 inclusive.

Sets can be created from other sets using the following operators.