【问题描述】定义复数类的加法与减法,使之能够执行下列运算:
Complex a(2,5), b(7, 8), c(0, 0);
c=a+b;
c=4.1+a;
c=b-5.6;
【输入形式】无
【输出形式】各复数运算结果
【样例输入】无
【样例输出】
9+i13
6.1+i5
1.4+i8
【样例说明】
【评分标准】 1个评分点
#include <iostream>
using namespace std;
//定义复数类
class Complex {
private:
double real;
double imag;
public:
//构造函数初值为0
Complex(double r = 0.0, double i = 0.0) {
this->real = r;
this->imag = i;
}
//对+进行重载
Complex operator+(const Complex& c) const {
return Complex(real + c.real, imag + c.imag);
}
//对-进行重载
Complex operator-(const Complex& c)