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:
- add elements to set1
- add elements to set2
- remove an element from set1
- remove an element from set2
- do a union of set1 and set2 into set3
- do an intersection of set1 and set2 into set3
- print set1, set2, and set3
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started