编写一个Complex类,需要完成的运算符重载有:+ :重载+,用来完成两个复数的加法编写一个Complex类,需要完成的运算符重载有:(1) + :重载+,用来完成两个复数的加法;(2) - :重载 - ,用来完成

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/08 10:21:11
编写一个Complex类,需要完成的运算符重载有:+ :重载+,用来完成两个复数的加法编写一个Complex类,需要完成的运算符重载有:(1) + :重载+,用来完成两个复数的加法;(2) - :重载 - ,用来完成
xKKQǿʅ@X>\ǩEI.0))}yʯtN3j mܹ;gx=ϜKU[kjncie}+{s+[;췫4νŀݪ՜zɭWhD,`fL{1`r,FI]!4~$S?߱I\V,A Jgz.#K(.k 6D(!&)b>R+ '&qXT. c@6E#L hp x$`VPV ;+5jPa5l75E)xƇ{ǹ8ʹ,%:TS;+

编写一个Complex类,需要完成的运算符重载有:+ :重载+,用来完成两个复数的加法编写一个Complex类,需要完成的运算符重载有:(1) + :重载+,用来完成两个复数的加法;(2) - :重载 - ,用来完成
编写一个Complex类,需要完成的运算符重载有:+ :重载+,用来完成两个复数的加法
编写一个Complex类,需要完成的运算符重载有:
(1) + :重载+,用来完成两个复数的加法;
(2) - :重载 - ,用来完成两个复数的减法;
(3) *:重载*,用来完成两个复数的乘法;
(4)

编写一个Complex类,需要完成的运算符重载有:+ :重载+,用来完成两个复数的加法编写一个Complex类,需要完成的运算符重载有:(1) + :重载+,用来完成两个复数的加法;(2) - :重载 - ,用来完成
#include
#include
class Complex
{
public:
Complex(float a,float b)
:m_real(a)
,m_imaginary(b)
{
}
Complex()
:m_real(0)
,m_imaginary(0)
{
}
const Complex operator+(const Complex& other)
{
Complex c(m_real+other.m_real,m_imaginary+other.m_imaginary);
return c;
}
const Complex operator-(const Complex& other)
{
Complex c(m_real-other.m_real,m_imaginary-other.m_imaginary);
return c;
}
const Complex operator*(const Complex& other)
{
Complex c(m_real*other.m_real-m_imaginary*other.m_imaginary,m_imaginary*other.m_real+m_real*other.m_imaginary);
return c;
}
float m_real,m_imaginary;
};
std::ostream& operator