write a complete member function in class set defined by you in this code to count number of elements in intersection between 2 sets : the code is ::: using C++ Programming #include using namespace std; class Set { int n,set[10]; public: void create () { cout<<"Enter Number Of Elements:"; cin>>n; int val; cout<<"Enter Elements in set:"<>set[0]; for (int i=1;i>val; for (int j=0;jn) { if (set[x]<(*s2).set[y]) { s3.set[z]=set[x]; x++; z++; } else if (set[x]==(*s2).set[y]) { s3.set[z]=set[x]; x++; y++; z++; } else { s3.set[z]=(*s2).set[y]; y++; z++; } } while (x>Choice; system("CLS"); switch (Choice) { Set s1,s2; case 1: cout<<"Set 1:"<>answer; system("CLS"); } while (answer=='y'); return 0; }
write a complete member function in class set defined by you in this code to count number of elements in intersection between 2 sets
: the code is ::: using C++ Programming
#include <iostream>
using namespace std;
class Set
{
int n,set[10];
public:
void create ()
{
cout<<"Enter Number Of Elements:";
cin>>n;
int val;
cout<<"Enter Elements in set:"<<endl;
cin>>set[0];
for (int i=1;i<n;i++)
{
cin>>val;
for (int j=0;j<i;j++)
{
if (set[j]==val)
{
i--;
break;
}
else
{
set[i]=val;
}
}
}
cout<<"Set Created"<<endl;
}
void display ()
{
for (int i=0;i<n;i++)
{
cout<<set[i]<<" ";
}
cout<<endl;
}
void setUnion (Set *s2)
{
Set s3;
int x=0,y=0,z=0;
while (x<n && y<s2->n)
{
if (set[x]<(*s2).set[y])
{
s3.set[z]=set[x];
x++;
z++;
}
else if (set[x]==(*s2).set[y])
{
s3.set[z]=set[x];
x++;
y++;
z++;
}
else
{
s3.set[z]=(*s2).set[y];
y++;
z++;
}
}
while (x<n)
{
s3.set[z]=set[x];
x++;
z++;
}
while (y<(*s2).n)
{
s3.set[z]=(*s2).set[y];
y++;
z++;
}
s3.n=z;
s3.display ();
}
void setIntersection (Set *s2)
{
Set s3;
int x=0,y=0,z=0;
while (x<n && y<(*s2).n)
{
if (set[x]<(*s2).set[y])
{
x++;
}
else if (set[x]==(*s2).set[y])
{
s3.set[z]=set[x];
x++;
y++;
z++;
}
else
{
y++;
}
}
s3.n=z;
s3.display ();
}
};
int main ()
{
int Choice;
char answer='y';
do
{
cout<<"-_- This Program Just For Two Sets -_-"<<endl;
cout<<"\n";
cout<<"\t -Menu- \t"<<endl;
cout<<"1.Create"<<endl;
cout<<"2.Print"<<endl;
cout<<"3.Union"<<endl;
cout<<"4.Intersection"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter Your Choice:"<<endl;
cin>>Choice;
system("CLS");
switch (Choice)
{
Set s1,s2;
case 1:
cout<<"Set 1:"<<endl;
s1.create ();
cout<<"Set 2:"<<endl;
s2.create ();
break;
case 2:
cout<<"Set 1:"<<endl;
s1.display ();
cout<<"Set 2:"<<endl;
s2.display ();
break;
case 3:
cout<<"Set 1 Union Set 2:"<<endl;
s1.setUnion (&s2);
break;
case 4:
cout<<"Set 1 Intersection Set 2:"<<endl;
s1.setIntersection (&s2);
break;
case 5:
exit (0);
break;
default:
cout<<"Wrong Choice"<<endl;
}
cout<<"Do You Want To Continue (y/n):"<<endl;
cin>>answer;
system("CLS");
}
while (answer=='y');
return 0;
}
Step by step
Solved in 2 steps with 1 images