Question: Write a class in C++ called Set that can hold 100 positive integer numbers from 0-99. You may implement this as an array or vector

Write a class in C++ called Set that can hold 100 positive integer numbers from 0-99.

You may implement this as an array or vector of boolean elements.

Add constructor(s), and the following methods:

1. void add( int i ) // add the number i to the set.

2. bool belongs(int i) // return true if i is a member of the set

3. void difference( Set B) // removes B from the set A where A is the current set so A= A-B

4. void union(Set B)// performs A U B // where A is the current set and the result is stored in A

5. void intersect (Set B) // performs A Write a class in C++ called Set that can hold 100 positive B // where A is the current set and the result is stored in A

6. string toString() //displays the set in roster notation {1,2,4} etc.

Write a client that instantiates two sets A and B. A = {2,4,6,8,10} B = {1,2,3,4}

Perform the operations in this order and call (Please include output statements before each call to explain your call as follows)

1. A.toString() //printing A

2. B.toString() //printing B

3. A.add(12) // adding 12 to A

4. A.toString() //printing A

5. A.belongs(4) // does 4 belong to A

6. A.belongs(11) // does 11 belong to A

7. A.difference(B) // remove B from A

8. A.toString() //printing A

9. A.union(B) // union of A and B

10. A.toString() // printing A

11 A.intersect(B) // intersecting A and B

12.A.toString()// printing A

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!