📄 complex.cpp
字号:
#include <iostream.h>
#include "complex.h"
CComplex& CComplex::operator =(const CComplex& c)
{
// 判断是否自复制
if(this == &c)
return *this;
real = c.real;
image = c.image;
return *this;
}
CComplex CComplex::operator +(const CComplex& c)
{
CComplex temp;
temp.real = real + c.real;
temp.image = image + c.image;
return temp;
}
CComplex CComplex::operator -(const CComplex &c)
{
CComplex temp;
temp.real =this->real - c.real;
temp.image = this->image - c.image;
return temp;
}
CComplex &CComplex::operator ++() //前缀
{
real ++;
image ++;
return *this;
}
CComplex CComplex::operator ++(int a) //后缀
{
CComplex temp;
temp.real = real;
temp.image = image;
real++;
image++;
return temp;
}
ostream& operator<<(ostream& stream, CComplex c)
{
cout<<c.image;
stream<<"("<<c.real<<"+"<<c.image<<"i)"; //以格式(a+bi)显示
return stream;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -