#include<iostream>
using namespace std;
class Sports
{
public:
int tennis;
int badminton;
int cricket;
int setA[20],setB[20],setC[20];
int ab[20],bc[20],ca[20],abc[20];
int n1,n2,n3,n4=0,total;
void accept(); // method for accept the input
void intersection(); //method for calculate intersection
void display(); //method for display intersections
};
void Sports :: accept()
{
cout<<"Enter the total number of players who play Tennis: "<<endl;
cin>>tennis;
cout<<"Enter the student roll no who play Tennis "<<endl;
for(int i=0; i<tennis; i++)
cin>>setA[i];
cout<<"Enter the total number of players who play Badminton: "<<endl;
cin>>badminton;
cout<<"Enter the student roll no who play Badminton "<<endl;
for(int i=0; i<badminton; i++)
cin>>setB[i];
cout<<"Enter the total number of players who play cricket: "<<endl;
cin>>cricket;
cout<<"Enter the student roll no who play cricket "<<endl;
for(int i=0; i<cricket; i++)
cin>>setC[i];
}
void Sports :: intersection()
{
// Logic for intersection SET-A and SET-B
for(int i=0;i<cricket;i++)
{
for(int j=0;j<badminton;j++)
{
if(setA[i]==setB[j])
{
ab[n1]=setA[i];
n1++;
}
}
}
// Logic for intersection SET-B and SET-C
for(int i=0;i<badminton;i++)
{
for(int j=0;j<cricket;j++)
{
if(setB[i]==setC[j])
{
bc[n2]=setB[i];
n2++;
}
}
}
// Logic for intersection SET-C and SET-A
for(int i=0;i<cricket;i++)
{
for(int j=0;j<tennis;j++)
{
if(setC[i]==setA[j])
{
ca[n3]=setC[i];
n3++;
}
}
}
//logic for A union B union C
for(int i=0;i<tennis;i++)
{
for(int j=0;j<badminton;j++)
{
for(int k=0;k<cricket; k++)
{
if(setA[i]==setB[j] && setA[i]==setC[k])
{
abc[n4]=setA[i];
n4++;
}
}
}
}
total=tennis+badminton+cricket-n1-n2-n3+n4;
}
void Sports :: display()
{
//logic for print intersection of tennis and Badminton
cout<<"\nIntersection of SET-A and SET-B: ";
for(int i=0; i<n1; i++)
cout<<ab[i]<<" ";
//logic for print intersection of Badminton and Cricket
cout<<"\nIntersection of SET-B and SET-C: ";
for(int i=0; i<n2; i++)
cout<<bc[i]<<" ";
//logic for print intersection of Cricket and Tennis
cout<<"\nIntersection of SET-C and SET-A: ";
for(int i=0; i<n3; i++)
cout<<ca[i]<<" ";
// logic for print intersection of Tennis and Badminton and Cricket
cout<<"\nIntersection of SET-A and SET-B and SET-C: ";
for(int i=0; i<n4; i++)
cout<<abc[i]<<" ";
// logic for print total number of students in a class
cout<<"\nTotal number of students in class are : "<<total;
}
int main()
{
Sports s;
s.accept();
s.intersection();
s.display();
return 0;
}