求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
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
- tom borrowed my bike two days ago改为同义句
- 在一个长、宽、高分别为8厘米、6厘米、12厘米长方体玻璃罐中盛有9厘米深的水,现将这个长方体玻璃罐旋转后
- “作文的题目以本学期的口语课的主题为主.共计十个主题:介绍身边的人物;作业;购物;餐桌礼仪;健康食物;保护动物;电影;问路;自然灾害;旅行.”
- 一本字典分上下两册,上册厚2.4厘米,一共256页.下册厚3.6厘米,大约有多少页
- 描写冬天的古诗词
- 上面两个目,中间一个佳,下面一个又.是个什么字?
- 1、△ABC中,∠C=90°,且满足关于x的方程(2sinB+1)x²-2x+sinB=0有两个不同的实数根,则∠A的取值范围是_______.
- 仿照下面的句子,结合语境,另写四行相似的句子.我眷恋秋水,我眷恋长天.
- 纸桥承重,用A4纸若干做桥(⊙o⊙)哦 方法过程细节
- 用一个字表示下面短语
热门考点