求c++复数计算器1)所设计的复数计算器可以进行+ - * += -= *= ++ -- >= =
求c++复数计算器1)所设计的复数计算器可以进行+ - * += -= *= ++ -- >= =
class Complex
{
public:
Complex(){
re=0.0f;
im=0.0f;
}
Complex(float _re,float _im)
{
re = _re;
im = _im;
}
Complex(const Complex &complex)
{
*this = complex;
}
// operators:
Complex &operator=(const Complex &c)
{
re = c.re;
im = c.im;
return *this;
}
Complex operator+(const Complex &c)
{
return Complex(re+c.re,im+c.im);
}
Complex operator-(const Complex &c)
{
return Complex(re-c.re,im-c.im);
}
Complex operator*(const Complex &c)
{
return Complex(re*c.re - im*c.im,re*c.im + im*c.re);
}
Complex operator+=(const Complex &c)
{
*this = *this+c;
return *this;
}
Complex operator-=(const Complex &c)
{
*this = *this-c;
return *this;
}
Complex operator*=(const Complex &c)
{
*this = *this*c;
return *this;
}
//++ ,虚实都各加1
//前置
Complex &operator++(void)
{
return *this = *this+Complex(1,1);
}
Complex &operator--(void)
{
return *this = *this-Complex(1,1);
}
//后置
Complex operator++(int t)
{
t =0;
Complex temp = *this;
++*this;
return temp;
}
Complex operator--(int t)
{
t =0;
Complex temp = *this;
--*this;
return temp;
}
bool operator==(const Complex &c)
{
return (re==c.re && im==c.im);
}
bool operator!=(const Complex &c)
{
return !(*this==c);
}
//模比较?下面的都是
bool operator>(const Complex &c)
{
return ((re*2+im*2) > (c.re*2+c.im*2));
}
bool operator=(const Complex &c)
{
return !(*thisb)
a=Complex(1,1);
if(a=b)
a=Complex(1,1);
if(a