题目
求c++复数计算器1)所设计的复数计算器可以进行+ - * += -= *= ++ -- >= =
提问时间:2020-12-24
答案
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
{
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
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点
- 1偶尔,依赖,优雅,模仿的近义词
- 2赤道是与南北两极距离()且与()
- 313分之1加13分之2加13分之3这样一直加到13分之11为止,等于多少
- 4今年的产量比去年增加三成五,也可以说今年的产量比去年_,也就是今年是去年的_%.
- 5木兰诗中:开我东阁门,坐我西阁床.脱我战时袍,著我旧时裳
- 6函数y=f(x)在(-∞,0)上为减函数,又f(x)为偶函数,则f(-3)与f(2.5)的大小关系是( ) A.f(-3)>f(2.5) B.f(-3)<f(2.5) C.f(-3)=f(2.5)
- 7it look the workmen only two hours to finish ____ my car
- 8下列词语中加点字读音完全相同的一项是( )
- 9一群鸽子落在树上和树下,树上有几只,树下有几只?(已知条件在“补充说明”内)
- 10判断题:圆周率的值是3.14()