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 ofostringstream
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}
- A set is a collection into a whole of objects.
- The elements of a set are listed once.
- The elements of a set are drawn from some universe. The universe should be understood from the context of the problem domain.
and the Universe is the integers between 0 and 15 inclusive.Sets can be created from other sets using the following operators.
- Union A U B = { 2, 3, 5, 6, 8, 10, 13 }
This is the set containing elements from A, B or both.- Intersection A ∩ B = { 6, 8 }
The set containing elements that are in both A and B.- Complement A c = { 0,1,2,4,5,7,9,11,12,13,14,15 }
The set consisting of elements from the universe that are not in A.- Difference A - B = { 3, 10 }
The set consisting of elements in A that are NOT in B- Subset A is not a subset of B.
A is a subset of B, if every element of A is also in B>