1个回答
展开全部
#include<iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i):real(r),imag(i){}
Complex operator+=(Complex &);
void display();
private:
double real;
double imag;
};
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
Complex Complex::operator+=(Complex &c)
{
return Complex(real+=c.real,imag+=c.imag);
}
int main()
{
Complex c1(23,10),c2(4,-8);
c1+=c2;
c1.display();
return 0;
}
另一个就自己搞定吧,道理是一样的,重要的是思想!
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i):real(r),imag(i){}
Complex operator+=(Complex &);
void display();
private:
double real;
double imag;
};
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
Complex Complex::operator+=(Complex &c)
{
return Complex(real+=c.real,imag+=c.imag);
}
int main()
{
Complex c1(23,10),c2(4,-8);
c1+=c2;
c1.display();
return 0;
}
另一个就自己搞定吧,道理是一样的,重要的是思想!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询