-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2.cpp
More file actions
158 lines (156 loc) · 2.33 KB
/
Q2.cpp
File metadata and controls
158 lines (156 loc) · 2.33 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
#include<iostream>
#include<stdio.h>
using namespace std;
class SET
{
int e, size1, size2;
int* A;
int* B;
public:
void input()
{
cout<<"Enter the number of elements in each set: ";
cin>>size1>>size2;
cout<<"Enter the elements of the two sets:"<<endl
<<"Set A:";
A = new int[size1];
for (int i = 0; i<size1; i++)
{
cin>>e;
A[i] = e;
}
cout<<"Set B:"<<endl;
B = new int[size2];
for (int i = 0; i<size2; i++)
{
cin>>e;
B[i] = e;
}
}
void subset()
{
int flag = 0;
if (size1 < size2)
{
for (int i = 0; i<size1 ; i++)
{
for(int j = 0; j<size2; j++)
{
if (A[i] == B[j])
flag++;
}
}
if (flag>0)
cout<<"SET A is subset of SET B"<<endl;
}
else if (size1 > size2)
{
for (int i = 0; i<size2 ; i++)
{
for(int j = 0; j<size1; j++)
{
if (B[i] == A[j])
flag++;
}
}
if (flag>0)
cout<<"SET B is subset of SET A"<<endl;
}
else
{
for (int i = 0; i<size1 ; i++)
{
for(int j = 0; j<size2; j++)
{
if (A[i] == B[j])
flag++;
}
}
if (flag>0)
cout<<"SET A is equal to SET B"<<endl;
}
}
void Union()
{
cout<<"{ ";
for (int i = 0; i<size1; i++)
cout<<A[i]<<", ";
int flag = 0;
for (int j = 0; j<size2; j++)
{
flag=0;
for (int k = 0; k < size1; k++)
{
if (B[j]==A[k])
flag++;
}
if (flag > 0)
continue;
else cout<<B[j]<<", ";
}
cout<<"}"<<endl;
}
void Inter()
{
cout<<"{ ";
if (size1 < size2)
{
for (int i = 0; i<size1 ; i++)
{
for(int j = 0; j<size2; j++)
{
if (A[i] == B[j])
cout<<A[i]<<", ";
}
}
}
else if (size2 < size1)
{
for (int i = 0; i<size2 ; i++)
{
for(int j = 0; j<size1; j++)
{
if (B[i] == A[j])
cout<<B[i]<<", ";
}
}
}
else
{
for (int i = 0; i<size1 ; i++)
{
for(int j = 0; j<size2; j++)
{
if (B[i] == A[j])
cout<<B[i]<<", ";
}
}
}
cout<<" }"<<endl;
}
void Cart()
{
cout<<"{ ";
for (int i = 0; i<size1 ; i++)
{
cout<<" ";
for (int j = 0; j<size2; j++)
cout<<"("<<A[i]<<","<<B[j]<<"),";
}
cout<<" }"<<endl;
}
};
int main()
{
SET a;
a.input();
cout<<"Subset: "<<endl;
a.subset();
cout<<"UNION: "<<endl;
a.Union();
cout<<"INTERSECTION: "<<endl;
a.Inter();
cout<<"CARTESIAN PRODUCT: "<<endl;
a.Cart();
return 0;
}