#include
using namespace std;
class Complex
{
float Real,Image;
public:
Complex()
{
Real=0;
Image=0;
}
Complex(float r,float i)
{
Real=r;
Image=i;
}
void Print()
{
cout<
if(Image>0)
{
cout<<'+';
}
if(Image!=0)
{
cout<<Image<<'i';
}
cout<<endl;
}
Complex operator +(Complex c){
Real=Real+c.Real;
Image=Image+c.Image;
return c;
}
};
/*aa run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
Complex c1(20,40),c2(200,-400),c3;
c3=c1+c2;
c1.Print();
c2.Print();
c3.Print();
return 0;
}
解析一下输出谢谢大神