求c++复数计算器1)所设计的复数计算器可以进行+ - * += -= *= ++ -- >= =

长草公主 1年前 已收到1个回答 举报

linwenzuan 幼苗

共回答了23个问题采纳率:87% 举报

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

1年前

5
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.037 s. - webmaster@yulucn.com