-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInclusion_Exclusion.cpp
More file actions
173 lines (138 loc) · 4.54 KB
/
Inclusion_Exclusion.cpp
File metadata and controls
173 lines (138 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//Name - Mohit Jaiswal
//Principle of Inclusion and Exclusion
#include <iostream>
#define max 30
using namespace std;
class sport
{
public:
int cricket[max];
int basketball[max];
int kabaddi[max];
int c,b,k;
void getData();
void displayData();
};
void sport::getData()
{
cout<<"\nCRICKET";
cout<<"\nEnter the number of player in cricket team - "<<endl;
cin>>c;
cout<<"Enter the roll number of student in cricket team -"<<endl;
for(int i=0;i<c;i++)
{
cin>>cricket[i];
}
cout<<"\nBASKETBALL";
cout<<"\nEnter the number of player in basketball team - "<<endl;
cin>>b;
cout<<"Eneter the roll number of student in basketball team -"<<endl;
for(int i=0;i<b;i++)
{
cin>>basketball[i];
}
cout<<"\nKABBADI";
cout<<"\nEnter the number of player in kabaddi team -"<<endl;
cin>>k;
cout<<"Enter the roll number of student in kabaddi team -"<<endl;
for(int i=0;i<k;i++)
{
cin>>kabaddi[i];
}
}
void sport::displayData()
{
cout<<"\n\n****Cricket Team*****"<<endl;
cout<<"\nNumber of player in cricket team = ";
cout<<c<<endl;
cout<<"Roll number of student in cricket team -"<<endl;
for(int i=0;i<c;i++)
{
cout<<cricket[i]<<endl;
}
cout<<"\n\n****Basketball Team*****"<<endl;
cout<<"Number of player in basketball team = ";
cout<<b<<endl;
cout<<"Roll number of student in basketball team -"<<endl;
for(int i=0;i<b;i++)
{
cout<<basketball[i]<<endl;
}
cout<<"\n\n****Kabaddi Team*****"<<endl;
cout<<"Number of player in kabaddi team = ";
cout<<k<<endl;
cout<<"Roll number of student in kabaddi team -"<<endl;
for(int i=0;i<k;i++)
{
cout<<kabaddi[i]<<endl;
}
}
class intersection
{
public:
int intersection_2set(int array1[],int array2[],int a,int b); //Intersection of 2 sets
int intersection_3set(int array1[],int array2[],int array3[],int a,int b,int c); //Intersection of 3 sets
};
int intersection::intersection_2set(int array1[],int array2[],int a,int b)
{
int result=0;
for(int i=0; i<a; i++)
{
for(int j=0; j<b; j++)
{
if(array1[i]==array2[j])
{
result++;
}
}
}
return result;
}
int intersection::intersection_3set(int array1[],int array2[],int array3[],int a,int b,int c)
{
int result=0;
for(int i=0; i<a; i++)
{
for(int j=0; j<b; j++)
{
for(int k=0; k<c; k++)
{
if(array1[i]==array2[j] && array1[i] ==array3[k])
{
result++;
}
}
}
}
return result;
}
int main()
{
int intersect_1,intersect_2,intersect_3,intersect_4;
int Union;
sport s;
intersection i;
s.getData();
s.displayData();
intersect_1=i.intersection_2set(s.cricket, s.basketball, s.c, s.b); //Intersection of cricket and basketball
intersect_2=i.intersection_2set(s.basketball , s.kabaddi, s.b, s.k); //Intersection of kabaddi and basketball
intersect_3=i.intersection_2set(s.cricket , s.kabaddi, s.c, s.k); //Intersection of cricket and kabaddi
intersect_4=i.intersection_3set(s.cricket , s.basketball, s.kabaddi,s.c, s.b,s.k); //Intersection of all 3 games
cout<<"\n----------------------------------------------------------"<<endl;
cout<<"\n";
cout<<"No. of Students playing both Criket and basketball -"<<endl;
cout<<">>Intersection of Set cricket and Set basketball ="<<intersect_2<<endl;
cout<<"\nNo. of Students playing both basketball and kabaddi -"<<endl;
cout<<">>Intersection of Set basketball and Set kabaddi = "<<intersect_2<<endl;
cout<<"\nNo. of Students playing both cricket and kabaddi -"<<endl;
cout<<">>Intersection of Set cricket and Set kabaddi = "<<intersect_3<<endl;
cout<<"\nNo. of Students playing all sports -"<<endl;
cout<<">>Intersection of Set Cricket, Set Basketball and Set Kabaddi = "<<intersect_4<<endl;
cout<<"\n-----------------------------------------------------------"<<endl;
//Union of sets
Union=s.c+s.b+s.k-(intersect_1+intersect_2+intersect_3)+intersect_4;
cout<<"\nNumber of student who play any of the game -"<<endl;
cout<<"\n>>UNION of set Cricket, set Basketball and set Kabaddi = "<<Union<<endl;
cout<<"\n-----------------------------------------------------------"<<endl;
return 0;
}