Chapter 10: Problem 8
\( \quad\) (Integerset Class) Create class IntegerSet for which each object can hold integers in the range 0 through \(100 .\) Represent the set internally as a vector of bool values. Element a \([\mathrm{i}]\) is true if integer \(i\) is in the set. Element a \([j]\) is \(f\) alse if integer \(j\) is not in the set. The default constructor initializes a set to the so-called "empty set," i.e., a set for which all elements contain false. Provide member functions for the common set operations. For example, provide a unionofSets member function that creates a third set that is the set-theoretic union of two existing sets (i.e., an element of the result is set to true if that element is true in either or both of the existing sets, and an element of the result is set to false if that element is false in each of the existing sets). Provide an intersectionofsets member function which creates a third set which is the settheoretic intersection of two existing sets (i.e., an element of the result is set to false if that element is \(f\) al se in either or both of the existing sets, and an element of the result is set to true if that element is true in each of the existing sets). Provide an insertE7ement member function that places a new integer \(k\) into a set by setting \(\mathrm{a}[\mathrm{k}]\) to true. Provide a de 7 ete \(\mathrm{E}\) 1 ement member function that deletes integer \(m\) by setting a \([\mathrm{m}]\) to false. Provide a printset member function that prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e., their position in the vector has a value of true). Print \(--\) for an empty set. Provide an isEqualTo member function that determines whether two sets are equal. Provide an additional constructor that receives an array of integers and the size of that array and uses the array to initialize a set object. Now write a driver program to test your Integerset class. Instantiate several Integerset objects. Test that all your member functions work properly.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.