forked from JayeshShelar/DSA-Practicals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAss2_Sets.cpp
187 lines (146 loc) · 2.55 KB
/
Ass2_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
#include<iostream>
using namespace std;
class student
{
static int total;
int count;
int roll[99];
public:
student()
{
count=0;
}
void accept()
{
cout<<"\nEnter the value of count: ";
cin>>count;
if((total+count)<=60)
{
l1:
cout<<"\nNow enter the set: ";
for(int i=0;i<count;i++)
{
cin>>roll[i];
total++;
}
for(int i=0;i<count;i++)
{
for(int j=i+1;j<count;j++)
{
if(roll[i]==roll[j])
{
cout<<"\nThe set contains duplicate elements please re-enter the set";
goto l1;
}
}
}
}
else
{
cout<<"Sorry!! You cannot enter data of more than 60 students!!!!!!";
exit(0);
}
}
void display()
{
cout<<"\nThe set is: ";
for(int i=0;i<count;i++)
{
cout<<roll[i]<<" ";
}
}
void set_union(student s1,student s2)
{
int flag;
for(int i=0;i<s1.count;i++)
{
roll[i]=s1.roll[i];
count++;
}
for(int i=0;i<s2.count;i++)
{
flag=0;
for(int j=0;j<s1.count;j++)
{
if(s2.roll[i]==s1.roll[j])
{
flag=1;
break;
}
}
if(flag==0)
{
roll[count]=s2.roll[i];
count++;
}
}
cout<<"\n*****Union set is:***** ";
}
void set_intersection(student s1,student s2)
{
int flag;
for(int i=0;i<s2.count;i++)
{
flag=0;
for(int j=0;j<s1.count;j++)
{
if(s2.roll[i]==s1.roll[j])
{
flag=1;
break;
}
}
if(flag==1)
{
roll[count]=s2.roll[i];
count++;
}
}
cout<<"\n*****Intersection set is:***** ";
}
void set_difference(student union_set,student s2)
{
int flag;
for(int i=0;i<union_set.count;i++)
{
flag=0;
for(int j=0;j<s2.count;j++)
{
if(s2.roll[j]==union_set.roll[i])
{
flag=1;
break;
}
}
if(flag==0)
{
roll[count]=union_set.roll[i];
count++;
}
}
cout<<"\n*****Difference set is:***** ";
}
void no_sports(student s)
{
cout<<"\n\nTotal Students who does not play any sport are: "<<60-s.count;
}
};
int student::total=0;
int main()
{
student s_cricket,s_badminton,s_union,s_intersection,s_diff_cricket,s_diff_badminton,s;
s_cricket.accept();
s_cricket.display();
s_badminton.accept();
s_badminton.display();
s_union.set_union(s_cricket,s_badminton);
s_union.display();
s_intersection.set_intersection(s_cricket,s_badminton);
s_intersection.display();
s_diff_cricket.set_difference(s_union,s_cricket);
s_diff_cricket.display();
s_diff_badminton.set_difference(s_union,s_badminton);
s_diff_badminton.display();
s.no_sports(s_union);
return 0;
}