Question: C++ code. I have this code that I must modify based on the instructions following the code. Thank you! #include using namespace std; class set
C++ code. I have this code that I must modify based on the instructions following the code. Thank you!
#include
using namespace std;
class set
{
unsigned int *a;
unsigned int size;
public:
set(unsigned int siz)
{
a=new unsigned int[siz];
size=siz;
}
void addElement(unsigned int pos, unsigned int data)
{
a[pos]=data;
}
unsigned int getsize()
{
return size;
}
unsigned int getelement(unsigned int pos)
{
if(pos<=size)
return a[pos];
return -1;
}
bool issubset(set s)
{
int i,j,there=0;
for(i=0;i { there=0; for(j=0;j { if(a[j]==s.getelement(i)) { there=1; break; } } } if(there==1) return 1; return 0; } bool isproper(set s) { if(size==s.getsize()) return 0; return issubset(s); } void printorderedpairs(set s) { int i,j; for(i=0;i { for(j=0;j { cout< } } } ~set() { delete[] a; } }; int main(int argc, const char * argv[]) { unsigned int n,i,temp; cout<<"How many elements do you have in set 1? "; cin>>n; set s1(n); for(i=0;i { cout<<" Enter element "< cin>>temp; s1.addElement(i,temp); } cout<<"How many elements do you have in set 2? "; cin>>n; set s2(n); for(i=0;i { cout<<" Enter element "< cin>>temp; s2.addElement(i,temp); } if(s1.issubset(s2)) cout<<" s2 is a subset of s1"; else cout<<" s2 is not a subset of s1"; s1.printorderedpairs(s2); return 0; } Instructions: Extend the Sets class. Remember that has sets for positive integers that you will need the following functions: addElement , will take a positive integer and add it to the set Note: you need to change it so that it will not add a duplicate element getElement, will take a position number and return the element at the position (return -1 if bad position) getSize, return the size of the set isSubset, takes a sets object (call it b) and see if the current set (call it a) is a subset of b. If so, return a Boolean true, else return a Boolean false (You can keep other functions in if need be). Add the following functions: unionOps, that takes a Sets object and does a union with the current set intersection, that takes a Sets object and does an intersection with the current set printSet, will print the Sets object contents It is recommended to add a constructor that will take an array and add its elements to the current set. Define a set a with certain values, like 1, 2, 3, 4 and set b with certain values like 3, 4, 5, 6 Have main create three objects: setA with set a, setB with set b, and setC with set a. Print the setA, setB, setC Do an union of setA with setB (setA will be changed) then print setA Do an intersection of setC (setC will be changed) with setB then print setC
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
