for(int c = 0; c
result.Add(B.m_pSet[c]);
}
return result;
}
Set Set::operator-(Set B) {
Set A = *(this);
Set G = A*B;
for(int c = 0; c < G.m_nCount; c++) {
if(A.Remove(G.m_pSet[c]))
A.m_nCount--;
}
Set result;
result.m_pSet = new int [A.m_nCount];
for(int c = 0; c < A.m_nCount; c++) {
result.Add(m_pSet[c]);
}
result.m_nCount = A.m_nCount;
return Set(result);
}
Set Set::operator*(Set B) {
int min;
int* resultList = nullptr;
if(this->m_nCount > B.m_nCount) {
min = B.m_nCount;
}
else {
min = this->m_nCount;
}
int *G = new int[min];
int Glength = 0;
for(int c = 0; cm_nCount; c++) {
if(B.Remove(this->m_pSet[c])) {
G[Glength] = this->m_pSet[c];
Glength++;
}
}
if(Glength) {
resultList = new int [Glength];
for(int c = 0; c
resultList[c] = G[c];
}
Set result;
result.m_nCount = Glength;
result.m_pSet = resultList;
return Set(result);
}
Set Set::operator=(Set another) {
m_pSet = another.m_pSet;
m_nCount = another.m_nCount;
return *(this);
}
Set operator +=(Set one, Set another) {
Set result = one + another;
return Set(result);
}
Set operator-=(Set one, Set another) {
Set result = one - another;
return result;
}
Set operator*=(Set one, Set another) {
Set result = one * another;
return Set(result);
}
Set::Set() {
m_pSet = nullptr;
m_nCount = 0;
}
Set::Set(const Set &data) {
m_pSet = data.m_pSet; // Again. 오류 예상 1
m_nCount = data.m_nCount; // Again. 오류 예상 2
}
int main () {
Set A;
A.Add(1);
A.Add(2);
A.Add(4);
A.Add(9);
A.print();
Set B;
B.Add(3);
B.Add(2);
B.Add(7);
B.Add(8);
B.print();
Set C;
C = A+B;
C.print();
Set D;
D = A-B;
D.print();
Set E;
E = A*B;
E.print();
Set F(A) ;
F += B;
F.print();
Set G(A) ;
G -= B;
G.print();
Set H(A) ;
H *= B;
H.print();
return 0;
}