Answered step by step
Verified Expert Solution
Link Copied!

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 non-negative 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 set[num] 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:
1. 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++.)
2. operator*: returns the intersection of two sets, the set of all elements that are common to both sets.
3. operator-: returns the difference of two sets, say A-B, which is the set of all elements that are in set A
but not in set B.(E.g., A ={23530}, B ={351040}, then A-B is {230})
4. operator=: assignment operator: assign one set to another. The righthand side replaces lefthand side.
5. operators (+=,*=,
-=): the union, intersection, difference assignment.
6. operators (==,!=): bool equality and inequality. A == B if the mathematical sets contain the same elements.
7. insert: insert an element into a set, has bool return value,, e.g., bool success = A.insert(5);
(Note: ignore invalid integers, return false, e.g., bool success = A.insert(-10);
If a value is already in the set and is inserted, return true).
8. remove: remove an element from a set, bool return value, e.g., bool success = A.remove(10);
(Note: ignore invalid integers, return false, e.g., bool success = A.remove(-10); ).
9. isEmpty: determine if a set is empty or not, bool return value, e.g., if (A.isEmpty())...
10. isInSet: determine if an integer is in the set or not,
e.g., if (A.isInSet(5))...(Note: returns false for invalid integers).
11. operator<<: Display {510122025100} to represent the set containing the integers
5,10,12,20,25, and 100. 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.)
12. operator>>: to input an entire set. (Note: This is a simple loop to take integers; terminate at
some sentinel value, say -1. Ignore invalid integers. Zero is valid as it is non-negative.)
13. All proper constructor and destructor functions; constructor(s) initialize a set to
(1) The "empty set" (a set which has no elements) or,
(2) A set that can take up to five values to be inserted into the set
e.g., IntSet A, B(3), C(12,5,5), D(5,
-10,12), E(100,2,
-5,45), F(1,2,3,4,5);
IntSet X(D); // 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 3. Set C has a current largest value of 12, also contains the value 5.
The constructor for D will ignore the -10 but is initialized to contain 5 and 12. E is {245100}. F is {123
45}. X is a deep copy of D, is {512}. You must initially size the arrays by the parameters, e.g., A's array is
size 1, B's array is size 4, C's array is size 13, etc. Later, after operations, the size may change. You may need to
make arrays larger for operations later (e.g., 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

ISBN: 0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago