#include <iostream>using namespace std;class Complex{public:Complex();//此函数必须定义Complex(double r,double i);friend Complex operator+(Complex &c1,Complex &c2);void display();private:double real,imag;};Complex::Complex(){}Complex::Complex(double r,double i){real=r;imag=i;}Complex operator+(Complex &c1,Complex &c2){return Complex(c1.real+c2.real,c1.imag+c2.imag);}void Complex::display(){cout<<'('<<real<<','<<imag<<"i)"<<endl;}int main(){double cr1,ci1,cr2,ci2;cin>>cr1>>ci1>>cr2>>ci2;Complex c1(cr1,ci1),c2(cr2,ci2),c3;c3=c1+c2;c3.display();return 0;}
1200字范文,内容丰富有趣,写作的好帮手!