#include<iostream>
using namespace std;
class Complex {
private:
double real;
double imag;
public:
Complex();
Complex(double a, double b);
Complex operator + (Complex& t1);
friend istream& operator >>(istream&, Complex&);
friend ostream& operator <<(ostream&, Complex&);
Complex operator=(Complex& t);
};
Complex::Complex() {
real = 0;
imag = 0;
}
Complex::Complex(double a, double b) {
real = a;
imag = b;
}
Complex Complex::operator+(Complex& t1) {
Complex t;
t.real = this->real + t1.real;
t.imag = this->real + t1.imag;
return t;
}
Complex Complex::operator=(Complex& t) {
Complex t1;
t1.real = t.real;
t1.imag = t.imag;
return t1;
}
ostream& operator<<(ostream& output, Complex& t) {
output << "(" << t.real << "+" << t.imag << "i)" << endl;
return output;
}
istream& operator>>(istream& input, Complex& t) {
cout << "请输入2个数:" << endl;
input >> t.real >> t.imag;
return input;
}
int main() {
Complex t1, t2, t3, t4;
cin >> t1 >> t2;
cout << "t1=" << t1;
cout << "t2=" << t2;
t3 = t1+t2;
t4 = t3;
cout << "t3=" << t3;
cout << "t4=" << t4;
system("pause");
return 0;
}