-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sets_Badminton_Cricket.cpp
182 lines (162 loc) · 3.51 KB
/
Sets_Badminton_Cricket.cpp
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
174
175
176
177
178
179
180
181
182
#include <iostream>
using namespace std;
class game {
int c, b, m, i, j, k, cnt;
int setA[10], setB[10], setC[20], setD[20], setAB[20];
public:
game() {
c = b = m = 0;
i = j = k = 0;
cnt = 0;
}
void getdata();
void show();
void uni();
void ninor();
void common();
void onlycrick();
void onlybadminton();
};
void game::getdata() {
cout << "\nHow many students are in SE Comp? : ";
cin >> m;
cout << "\nEnter count of student who plays cricket: ";
cin >> c;
for (i = 0; i < c; i++) {
cout << "\nEnter the roll no: ";
cin >> setA[i];
}
cout << "\nEnter count of student who plays badminton: ";
cin >> b;
for (i = 0; i < b; i++) {
cout << "\nEnter the roll no: ";
cin >> setB[i];
}
}
void game::uni() {
int flag = 0;
for (i = 0; i < c; i++) {
setC[k] = setA[i];
k++;
}
for (j = 0; j < b; j++) {
for (i = 0; i < c; i++) {
if (setB[j] == setA[i]) {
flag = 1;
}
}
if (flag == 0) {
setC[k] = setB[j];
k++;
}
flag = 0;
}
cout << "\nStudent who plays either Cricket or Badminton:\n";
for (i = 0; i < k; i++) {
cout << "\t" << setC[i];
}
}
void game::common() {
for (i = 0; i < c; i++) {
setC[k] = setA[i];
k++;
}
cout << "\nStudent who plays both:\n";
for (j = 0; j < b; j++) {
for (i = 0; i < c; i++) {
if (setB[j] == setA[i]) {
cout << "\t" << setA[i];
}
}
}
}
void game::ninor() {
int z;
int flag = 0;
for (i = 0; i < c; i++) {
setC[k] = setA[i];
k++;
}
for (j = 0; j < b; j++) {
for (i = 0; i < c; i++) {
if (setB[j] == setA[i]) {
flag = 1;
}
}
if (flag == 0) {
setC[k] = setB[j];
k++;
}
flag = 0;
}
for (i = 0; i < k; i++) {
setD[cnt] = setC[i];
cnt++;
}
cout << "\nStudent who plays neither cricket nor badminton:\n";
flag = 0;
for (i = 1; i <= m; i++) {
for (j = 0; j < cnt; j++) {
if (setD[j] == i) {
flag = 1;
}
}
if (flag == 0) {
setAB[z] = i;
cout << "\t" << i;
z++;
}
flag = 0;
}
}
void game::onlycrick() {
int flag = 0;
cout << "\nStudent only plays cricket:\n";
for (i = 0; i < c; i++) {
for (j = 0; j < b; j++) {
if (setA[i] == setB[j]) {
flag = 1;
}
}
if (flag == 0) {
cout << "\t" << setA[i];
}
flag = 0;
}
}
void game::onlybadminton() {
int flag = 0;
cout << "\nStudent only plays badminton:\n";
for (j = 0; j < b; j++) {
for (i = 0; i < c; i++) {
if (setB[j] == setA[i]) {
flag = 1;
}
}
if (flag == 0) {
cout << "\t" << setB[j];
}
flag = 0;
}
}
void game::show() {
cout << "\nStudents who plays cricket:\n";
for (i = 0; i < c; i++) {
cout << "\t" << setA[i];
}
cout << "\nStudents who plays badminton:\n";
for (j = 0; j < b; j++) {
cout << "\t" << setB[j];
}
}
int main() {
game g;
g.getdata();
g.show();
g.uni();
g.ninor();
g.common();
g.onlycrick();
g.onlybadminton();
return 0;
}