Home > Back-end >  For bosses to see how to adjust
For bosses to see how to adjust

Time:11-30

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;

}

return true;

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
SET 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;

}

return true;


But the compiler cannot return always convert parameter 1 from 'const bool' to 'const class SET & amp; '

CodePudding user response:

You are not to judge whether is equal? Should use a Boolean value

CodePudding user response:

reference 3 floor is Simple - Soft reply:
you are not to judge whether is equal? Should use the Boolean value o


But is SET, the returned object should be

CodePudding user response:

reference 4 floor INAVERknow response:
Quote: Simple reference 3 floor - Soft reply:

You are not to judge whether is equal? Should use the Boolean value o


But is SET, the returned object should be


Not like that, it is==, it's not=assignment

CodePudding user response:

Basically what exception handling algorithm design techniques are useless (lazy)
Lz write it,,,
I guess this should mean,,,
As follows:
 
#include
#include
using namespace std;

//note: used only for refactoring
//note: please complete by oneself, the only realized demand
The class set_my//note: please to const object adapter
{
Public:
Friend ostream& Operator<(ostream& , set_my);

Set_my (int * data, int size_s) {
Data_point=new int [size_s];
Copy (data, data + size_s data_point);
Size=size_s;
Havedone=true;
};
~ set_my ()=default;

{int operator [] (size_t point_where)
Cando ();
Return data_point [point_where];
};
{int the at (size_t point_where)
Cando ();
If (point_where & gt; The size) throw out_of_range (subscript crossing the line "");
Return data_point [point_where];
};

Boolean operator==(set_my Rvaluey) {
Cando ();
For (size_t I=0; i {
If (the at (I)! Return 0=Rvaluey. At (I));
}
return 1;
};

Set_my & amp; Operator=(set_my Rvaluey) {
Cando ();
Rvaluey. ~ set_my ();
Rvaluey. Build (data_point, size);
Return Rvaluey;
}

Void the print () {
Cando ();
For (size_t I=0; i {
Cout & lt; }
};

Private:
Int * data_point;//note please use smart Pointers (fear of you don't understand the useless)
Int size;
Bool havedone=0;
Void cando () {
if (! Havedone) throw runtime_error (" uninitialized ");
};
Void build (int * data, int size_s) {
Data_point=new int [size_s];
Copy (data, data + size_s data_point);
Size=size_s;
Havedone=true;
};
};
Ostream& Operator<(ostream& nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related