Question
USING C++ Set Class (required): A set class is used to represent sets of integers. It supports most of the standard set operations. Write a
USING C++
Set Class (required):
A set class is used to represent sets of
integers. It supports most of the standard set operations.
Write a template-based class that implements a set of items. A set is collection of items in
which no item occurs more than once. Internally, you may represent the set using the data
structure of your choice (list, vector, arrays, etc.). However, the class should externally
support the following functions:
Set data structure:
A set is a collection of objects need not to be in any particular order. Elements
Sample class declaration:
-
You class should have all of the followings.
-
Can be defined as friend functions
class
Set {
public
:
//default constructor
Set();
//add element to set
void
addElement (
int
element);
//remove element from set
void
removeElement(
int
element);
//check for membership
-
bool
isMember(
int
element);
//set union, modifies curremtn set
void
Union (Set s);
//set difference modifiers current set
void
difference (Set s);
//size of set
int
size();
//get element i
int
getElement (
int
i);
//Return a pointer to a dynamically created array containing each item in the set.
//The caller of this function is responsible for deallocating the memory.
private
:
...
...
...
};
Test your class by creating different sets of different data types (for examples, strings,, integers,
or other classes). If you add objects to your set, then you may need to overload the = = and !=
operators for the objects class so your template-based set class can properly determine
membership.
?
A suitable overloading of the quality operator ==
?
A suitable overloading of the inquality operator !=
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