forked from CO18325/HackTheOctober-HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsets.cpp
264 lines (240 loc) · 6.49 KB
/
sets.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include<iostream>
#include<set>
#include<iomanip>
using namespace std;
void sets_generator()
{
int n1,x,n2,y,n;
set<int>:: iterator l;
int choice;
set<int> set1;
cout << "\nEnter no. of elements for 1st Set : " ;
cin >> n1 ;
for (int i = 0; i < n1; i++)
{
cin >> x;
set1.insert(x);
}
set <int> ::iterator g;
cout << "\nElements for Set-1 : " ;
cout << "{ ";
for ( g = set1.begin(); g != set1.end(); g++)
{
cout << *g << " " ;
}
cout << "}";
set<int>set2 ;
cout << "\n\nEnter no. of elements for 2nd Set : " ;
cin >> n2 ;
for (int i = 0; i < n2; i++)
{
cin >> y;
set2.insert(y);
}
set <int> ::iterator k;
cout << "\nElements for Set-2 : " ;
cout << "{ ";
for ( k = set2.begin(); k!= set2.end(); k++)
{
cout << *k << " " ;
}
cout << "}";
conditions:
set<int> Set3;
cout << "\n\n Which operation you want to use ? " << endl;
cout << setw(5) << "1. Union of 2 Sets" << endl;
cout << setw(5) << "2. Intersection of 2 Sets " << endl;
cout << setw(5) << "3. Difference between 2 Sets " << endl;
cout << setw(5) << "4. Cartesian product of 2 Sets " << endl;
cout << setw(5) << "5. Compliment of a Set" << endl;
cin >> choice;
if (choice == 1)
{
system("CLS");
cout << "\nUnion of Set 1 and Set 2 is : ";
for ( g = set1.begin(); g != set1.end(); g++)
{
Set3.insert(*g);
}
for ( k = set2.begin(); k != set2.end(); k++)
{
Set3.insert(*k);
}
set<int>:: iterator l;
cout << "{ ";
for(l = Set3.begin(); l != Set3.end() ; l++)
{
cout << *l << " " ;
}
cout << "}";
cout << "\n" ;
goto conditions;
}
if(choice == 2)
{
Set3.clear();
for ( g = set1.begin(); g != set1.end(); g++)
{
for ( k = set2.begin(); k != set2.end(); k++)
{
if (*g == *k)
{
Set3.insert(*g);
}
}
}
system("CLS");
cout <<"\nIntersection of A and B : ";
cout << "{ ";
for (l = Set3.begin(); l != Set3.end(); l++)
{
cout << *l << " ";
}
cout << "}";
goto conditions;
}
if(choice == 3)
{
int choose;
set <int> :: iterator itr;
cout << "\n 1. For Set 1 - Set 2 " ;
cout << "\n 2. For Set 2 - Set 1 " ;
cout << "\n\n Enter your choice : " ;
cin >> choose;
switch (choose)
{
case (1):
for ( itr = set2.begin() ; itr != set2.end(); itr++)
{
set1.erase(*itr);
}
cout << "\nDifference of Set 1 - Set 2 is : ";
cout << "{ ";
for ( itr = set1.begin() ; itr != set1.end(); itr++)
{
cout << *itr << " ";
}
cout << "}";
goto conditions;
break;
case (2):
for (itr= set1.begin(); itr != set1.end() ; itr++)
{
set2.erase(*itr);
}
cout << "\nDifference of Set 2 - Set 1 is : ";
cout << "{ ";
for ( itr = set2.begin() ; itr != set2.end(); itr++)
{
cout << *itr << " ";
}
cout << "}";
goto conditions;
break;
default:
cout << "\nERROR !!!";
goto conditions;
break;
}
}
if (choice == 4)
{
system("CLS");
cout << "Press 1 for A X B ";
cout << "\nPress 2 for B X A ";
cout << "\n " << endl;
int choose2;
cin >> choose2;
switch (choose2)
{
case (1):
cout << "{ ";
for ( g = set1.begin(); g != set1.end(); g++)
{
for ( k = set2.begin(); k != set2.end(); k++)
{
cout << "(" << *g << "," << *k << ")";
}
}cout << " }";
goto conditions;
break;
case (2):
cout << "{ ";
for ( k = set2.begin(); k != set2.end(); k++)
{
for ( g = set1.begin(); g != set1.end(); g++)
{
cout << "(" << *k << "," << *g << ")";
}
}
cout << " }";
goto conditions;
break;
default:
cout << "\nERROR !!!";
goto conditions;
break;
}
}
if(choice = 5)
{
system("CLS");
cout << "\nSet limit of the Universal Set : ";
int limit;
cin >> limit;
set<int> setU;
set<int>:: iterator U;
for (int i = 1; i <= limit; i++)
{
setU.insert(i) ;
}
cout << "{";
for ( U = setU.begin(); U != setU.end(); U++)
{
cout << *U << " ";
}
cout << "}";
cout << "\nWhich Set's Compliment you want to show ? ";
cout << "\nPress 1 for A or 2 for B ";
int comp;
cin >> comp;
switch (comp)
{
case (1):
for ( U = set1.begin(); U != set1.end(); U++)
{
setU.erase(*U);
}
cout << "\nA's Compliment is :";
cout << "\n{";
for ( U = setU.begin(); U != setU.end(); U++)
{
cout << *U << " ";
}
cout << "}";
goto conditions;
break;
case(2):
for ( U = set2.begin(); U != set2.end(); U++)
{
setU.erase(*U);
}
cout << "\nB's Compliment is :";
cout << "\n{";
for ( U = setU.begin(); U != setU.end(); U++)
{
cout << *U << " ";
}
cout << "}";
goto conditions;
break;
default:
break;
}
}
}
int main()
{
sets_generator();
return 0;
}