#include <iostream>
using namespace std;
class Complex
{public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
double get_real();
double get_imag();
void display();
private:
double real;
double imag;
};
double Complex::get_real()
{return real;}
double Complex::get_imag()
{return imag;}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.get_real()+c2.get_real(),c1.get_imag()+c2.get_imag());
}
int main()
{Complex c1(8,4),c2(2,-9),c3;
c3=c1+c2;
cout<<"c3=";
c3.display();
return 0;
}
07-05
06-06
10-11
07-18
07-18
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交