Question: C++ Create a templated class called Set that will use ArrayBag as a data member to be a as a implementation (use inheritance>. The Set

C++

Create a templated class called Set that will use ArrayBag as a data member to be a as a implementation (use inheritance>. The Set will have the following public functions:

bool add(const ItemType& newEntry)

The above Set functions will invoke the data member ArrayBag. Note: there are no duplicates in the sets so the Set add should not allow duplicates (do NOT change the ArrayBag code). Also add to Set the following overloaded operator:

Set operator+(const Set&) // do a union

Set operator-(const Set&) // do an intersection

friend ostream& operator<<(ostream&, const Set&) // print the set

Put the class definition in Set.h, implementation in Set.cpp, and a main 3 files all together. Have main create 3 Set objects that are unsigned integers then create a menu like so:

  1. add elements to set1
  2. add elements to set2
  3. remove an element from set1
  4. remove an element from set2
  5. do a union of set1 and set2 into set3
  6. do an intersection of set1 and set2 into set3
  7. print set1, set2, and set3
  8. quit

Have the add elements loop and add positive integers until you enter a 0. You can create extra functions (separate from the Set class) to make it easier.

Printing would look like:

Which set to print? 1

Set 1 has 3 elements of:

11

5

33

With the overloaded operators, you should be able to do something like:

set3 = set1 + set2;

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!