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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education