Question
Write a class ++ IntSet for modeling sets of integers in the range 0 through 99. A set should be represented internally as an array
Write a class ++ IntSet for modeling sets of integers in the range 0 through 99. A set should be represented internally as an array of type bool: The ith array element will be true whenever integer i is in the set and will be false whenever integer i is not in the set. Include a no-argument constructor that initializes a set to the so-called empty set, i.e., a set whose array representation contains all false values. The class should include the following overloaded operators:
+ to perform the union of two set (the union of sets A and B is the set that contains all
elements of set A or set B, or both).
* to perform the intersection of two sets (the intersection of sets A and B is the set that
contains all elements in both set A and set B.)
- to form the difference of two sets (the difference of sets A and B is the set containing those elements that are in A but not in B)
+= to add an integer into a set.
-= to delete an integer from a set.
== to determine if two sets are equal.
! to form the complement of a set (the complement of set A, denoted , is the set containing all the elements in the universal set that are not in A - the universal set for this problem is the set containing all integers between 0 and 99)
<= to determine if one set is a subset of another set (set A is a subset of set B means that for any element x in A, x is also an element of set B).
<< to display a set in roster notation (for example, {2, 3, 5, 9})
Requirement: The overloaded += and -= operators should check for valid integer input (in the range 0-99), or if an add-item is already in the set, or if a delete-item is not in the set. An error message for invalid input should be generated.
Then, write a C++ program that uses the new IntSet class. The program should allow the user to repeatedly select from these options:
add numbers to a set
remove numbers from a set
form the union of two sets
form the intersection of two sets
form the difference of two sets
determine if two sets are equal
form the complement of an set
determine if one set is a subset of another set
display a set
The program should allow for up to ten sets to be created during a given program run. Use any stand-alone functions you feel necessary.
Here is output from a sample run of the program (user input in bold):
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
1
Add numbers to which sets (A, B,C, D, E, F, G, H, I, J)? :A
Enter number to add: 1
Add another (y or n): y
Enter number to add: 3
Add another (y or n): y
Enter number to add: 8
Add another (y or n): n
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
9
Display set (A, B, C, D, E, F, G, H, I, J)? :A
{1, 3, 8}
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
1
Add numbers to which sets (A, B,C, D, E, F, G, H, I, J)? :B
Enter number to add: 2
Add another (y or n): y
Enter number to add: 3
Add another (y or n): y
Enter number to add: 7
Add another (y or n): n
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
2
Remove numbers from which set (A, B, C, D, E, F, G, H, I, J)? :A
Enter number to remove: 1
Remove another (y or n): n
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
3
Sets union specify sets to use:
First set: (A, B, C, D, E, F, G, H, I, J)? :A
Second set: (A, B, C, D, E, F, G, H, I, J)? :B
Result set: (A, B, C, D, E, F, G, H, I, J)? :C
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
4
Set intersection specify sets to use:
First set: (A, B, C, D, E, F, G, H, I, J)? :A
Second set: (A, B, C, D, E, F, G, H, I, J)? :B
Result set: (A, B, C, D, E, F, G, H, I, J)? :D
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
5
Set difference specify sets to use:
First set: (A, B, C, D, E, F, G, H, I, J)? :A
Second set: (A, B, C, D, E, F, G, H, I, J)? :B
Result set: (A, B, C, D, E, F, G, H, I, J)? :E
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
6
Set equality specify sets to compare:
First set: (A, B, C, D, E, F, G, H, I, J)? :A
Second set: (A, B, C, D, E, F, G, H, I, J)? :B
These sets are not equal
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
7
Set complement specify sets to use:
Complement set: (A, B, C, D, E, F, G, H, I, J)? :A
Result set: (A, B, C, D, E, F, G, H, I, J)? :F
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
8
Subsets specify sets to compare:
First set: (A, B, C, D, E, F, G, H, I, J)? :A
Second set: (A, B, C, D, E, F, G, H, I, J)? :B
The first set is not a subset of the second
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
9
Display set (A, B, C, D, E, F, G, H, I, J)? :B
{2, 3, 7}
Select an option:
- add numbers to a set
- remove numbers from a set
- form the union of two sets
- form the intersection of two sets
- form the difference of two sets
- determine if two sets are equal
- form the complement of an set
- determine if one set is a subset of another set
- display a set
Exit
10
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