Requirements are overloaded operators==, judge #include using namespace std; The class SET two sets are equal {public: Int a, [5]. int len;
SET (int * p, int n); Int operator==(int); Friend int operator==(the SET & amp; S1, SET & amp; S2); Void the print (); ~ the SET () {} }; SET: : SET (int p [5], int n) { int i; for(i=0; i{ [I] a [I]=p; } Len=n; } Int the SET: : operator==(int) b {int I; for(i=0; i{ If (a [I]==b) return 1; } } SET the operator==(the SET & amp; S1, SET & amp; S2) {int I, j, k=0; for(i=0; i<5; I++) {the for (j=0; J<5; J++) If (s1) a [I]==s2) a [j]) k++; }
} Void the SET: : print () { int i; for(i=0; i{ Cout}
} Int main () { Int a [5], b [5], c [5], [5] d; int i; for(i=0; i<5; I++) {cin> A, [I]. } for(i=0; i<5; I++) {cin> B [I]; }
for(i=0; i<5; I++) {cin> C [I]; } for(i=0; i<5; I++) {cin> D [I]; } The SET of a1 (a, 5); The SET b1 (b, 5); The SET c1 (c, 5); The SET d1 (d, 5);
Cout<" A={"; A1. Print (); Cout<" B={"; B1. The print (); If (a==b) {cout<" The same "& lt; } The else {cout<" Not the same;" } Cout<" A={"; A1. Print (); Cout<" B={"; C1. Print (); If (a==c) { Cout<" The same "; } The else {cout<" Not the same;" } Cout<" A={"; A1. Print (); Cout<" D={"; D1. Print (); If (a==d) {cout<" The same "; } The else { Cout<" Not the same;" } return 0; }
CodePudding user response:
SET the operator==(the SET & amp; S1, SET & amp; S2) {int I, j, k=0; for(i=0; i<5; I++) {the for (j=0; J<5; J++) If (s1) a [I]==s2) a [j]) k++; } This implementation is too complex, Can some simple for(int i=0; i<5; I++) { If (a [I]! B=[I]) return false;