📄 complexcz.cpp
字号:
#include<iostream.h>
#include<math.h>
#include"complexcz.h"
Complex::Complex(double rl,double im)
{
real=rl;
image=im;
}
Complex operator+(Complex c1,Complex c2)
{
return Complex(c1.real+c2.real,c1.image+c2.image);
}
Complex operator-(Complex c1,Complex c2)
{
return Complex(c1.real-c2.real,c1.image-c2.image);
}
Complex operator*(Complex c1,Complex c2)
{
return Complex(c1.real*c2.real-c1.image*c2.image,c1.real*c2.image+c1.image*c2.real);
}
Complex operator/(Complex c1,Complex c2)
{
Complex temp ;
double c;
c=c2.real*c2.real+c2.image*c2.image;
c2.image=-c2.image;
temp=c1*c2;
temp.real/=c;
temp.image/=c;
return temp;
}
Complex & Complex::operator+=(Complex a)
{
*this=*this+a;
return *this;
}
Complex & Complex::operator-=(Complex a)
{
*this=*this-a;
return *this;
}
ostream & operator<<(ostream & dest,Complex source)
{
char sign='+';
if(source.image<0)
sign='-';
dest<<" "<<source.real<<sign<<fabs(source.image)<<"i";
dest<<endl;
return dest;
}
Complex & Complex::operator++()
{
real++;
image++;
return *this;
}
Complex Complex::operator++(int)
{
Complex temp=*this;
real++;
image++;
return temp;
}
Complex & Complex::operator--()
{
real--;
image--;
return *this;
}
Complex Complex::operator--(int)
{
Complex temp=*this;
real--;
image--;
return temp;
}
Complex & Complex::operator=( const Complex c1)
{
if(this==&c1)
return *this;
else
this->real=c1.real;
this->image=c1.image;
return *this;
}
/*void Complex::display()
{
char sign='+';
if(image<0)
sign='-';
cout<<real<<sign<<fabs(image)<<"i";
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -