标签:des blog http io os ar sp div art
2 3 3 5 10
5+8i 12+3i 12+3i
这一题跟前面这题差不多就不写注释了。http://blog.csdn.net/u013634961/article/details/40189475
#include <iostream> using namespace std; class Complex { private: int real; int imag; public: Complex() { real=0; imag=0; } Complex(int x,int y) { real=x; imag=y; } Complex operator+( Complex r); Complex operator+(int r); friend Complex operator+(int , Complex ); friend ostream &operator <<(ostream &, Complex &); }; Complex Complex :: operator+( Complex r) { Complex d; d.real=real+r.real; d.imag=imag+r.imag; return d; } Complex Complex :: operator+(int r) { Complex d; d.real=real+r; d.imag=imag; return d; } Complex operator+(int x, Complex r) { Complex d; d.real=x+r.real; d.imag=r.imag; return d; } ostream&operator<<(ostream&output, Complex &c) { output<<c.real<<"+"<<c.imag<<"i"; return output; } int main() { int a,b,c,d,e; cin>>a>>b>>c>>d>>e; Complex r1(a,b); Complex r2(c,d); Complex r3; r3=r1+r2; cout<<r3<<endl; r3=r1+e; cout<<r3<<endl; r3=e+r1; cout<<r3<<endl; return 0; }
标签:des blog http io os ar sp div art
原文地址:http://blog.csdn.net/u013634961/article/details/40211941