标签:splay logs friend com add names out private pre
#include <iostream> using namespace std; class Complex{ private: int i, j; public: Complex(int ii=0, int jj=0){ i=ii; j=jj; } Complex(Complex &c){ i=c.i; j=c.j; } void Display(){ cout<<i; if(j>=0) cout<<"+"; cout<<j<<"i"<<endl; } friend Complex AddComplex(Complex c3, Complex c4){ c3.i+=c4.i; c3.j+=c4.j; return c3; } }; int main(){ int x,y; cin>>x>>y; Complex c0(x,y); Complex c1(c0); cout<<"c1 is: "; c1.Display(); cin>>x>>y; Complex c2(x,y); cout<<"c2 is: "; c2.Display(); Complex c3; c3 = AddComplex(c1,c2); cout<<"c3 is: "; c3.Display(); return 0; }
标签:splay logs friend com add names out private pre
原文地址:http://www.cnblogs.com/ur10ser/p/7736395.html