#include <iostream>
using namespace std;
class Complex
{
private:
	double real;                                //定义实部
	double imag;                               //定义虚部
public:
	Complex();                                //声明构造函数
	Complex(double r,double i);		 //声明重载构造函数
	Complex operator + (Complex &t1);       //重载运算符“+”
	void display();              
};
int main()
{
	Complex t1(1,2);                           //定义对象t1，并赋值
	Complex t2(3,4);			 //定义对象t2，并赋值
	Complex t3;                              //定义对象t3
	t3=t1+t2;                                //运用重载运算符使两对象相加
	cout<<"t1="<<ends;
	t1.display();                               
	cout<<"t2="<<ends;
	t2.display();
	cout<<"t1+t2="<<ends;
	t3.display();
	return 0;
}
Complex::Complex()                            //定义构造函数
{
	real=0;
	imag=0;
}
Complex::Complex(double r,double i)              //定义重载构造函数

{
	real=r;
	imag=i;
}
Complex Complex::operator + (Complex &t1)        //定义运算符重载
{
	Complex t;                                //定义对象t
	t.real=this->real+t1.real;                   //两实部相加
	t.imag=this->imag+t1.imag;                  //两虚部相加
	return t;
}
void Complex::display() 
{
	cout<<"("<<real<<","<<imag<<"i)"<<endl;    
}





