Answered step by step
Verified Expert Solution
Question
1 Approved Answer
create a cpp class and h class. Create the abstract data type ( ADT ) for an integer set called IntSet One IntSet object represents
create a cpp class and h class. Create the abstract data type ADT for an integer set called IntSet
One IntSet object represents one mathematical set of nonnegative integers includes zero One set keeps track
of unique integers, whether integers are in the set or not. That ADT includes standard math set operations.
Implement the internal representation as follows:
An IntSet object is implemented as a bool array internally, containing true and false. For example, if you call the
array set, then setnum is true if the integer num is in the set, false if num is not in the set. Use "new" to
dynamically allocate memory for the array. One objects array stores one math sets values.
Develop a full class with the following operations:
operator: returns the union of two sets, the set of elements that are contained in either or both sets.
Note do not call any identifiers union as that is a keyword in C
operator: returns the intersection of two sets, the set of all elements that are common to both sets.
operator: returns the difference of two sets, say AB which is the set of all elements that are in set A
but not in set BEg A B then AB is
operator: assignment operator: assign one set to another. The righthand side replaces lefthand side.
operators
: the union, intersection, difference assignment.
operators : bool equality and inequality. A B if the mathematical sets contain the same elements.
insert: insert an element into a set, has bool return value,, eg bool success Ainsert;
Note: ignore invalid integers, return false, eg bool success Ainsert;
If a value is already in the set and is inserted, return true
remove: remove an element from a set, bool return value, eg bool success Aremove;
Note: ignore invalid integers, return false, eg bool success Aremove;
isEmpty: determine if a set is empty or not, bool return value, eg if AisEmpty
isInSet: determine if an integer is in the set or not,
eg if AisInSetNote: returns false for invalid integers
operator: Display to represent the set containing the integers
and The empty set is displayed exactly as:
Output exactly as shown, inside curly braces with one blank before each number;
output no other blanks. Note that operator should not do an endl.
operator: to input an entire set. Note: This is a simple loop to take integers; terminate at
some sentinel value, say Ignore invalid integers. Zero is valid as it is nonnegative.
All proper constructor and destructor functions; constructors initialize a set to
The "empty set" a set which has no elements or
A set that can take up to five values to be inserted into the set
eg IntSet A B C D
E
F;
IntSet XD; X is an exact copy of D
Set A is the empty set. For implementation, you could use nullptr, but using an array of one element keeps it
cleaner. While A is currently the empty set, after the operator operator etc. is used, the set could
contain many values. Set B initially holds Set C has a current largest value of also contains the value
The constructor for D will ignore the but is initialized to contain and E is F is
X is a deep copy of D is You must initially size the arrays by the parameters, eg As array is
size Bs array is size Cs array is size etc. Later, after operations, the size may change. You may need to
make arrays larger for operations later eg A B;; but since new and delete are costly operations,
typically, for efficiency reasons, you dont shrink arrays if less space is needed. One component of this
assignment is to be efficient, to minimize unnecessary new and delete operations.
Often, when more memory is needed for an array, applications will double the array size to minimize the number
of new and delete operations. Do not do that in your program. This is about practicing memory management
proper memory allocation and deallocation Having a larger than needed array initially can mask errors.
As always expected when programming, comment clearly and thoroughly. Comments in the class definition file
should describe the ADT in the beginning comment block of the class definition Additionally, clearly state any
assumptions and implementation details you make. See the Rational class and List class for sample comments.
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