#include <iostream>
using namespace std;
class Complex
{
private:
	double real;                                //定义复数的实部
	double imag;                               //定义复数的虚部
public:
	Complex();                                //声明构造函数
	Complex(double r,double i);				  //声明函数的重载
	Complex complex_add(Complex &t1); 		  //声明实现复数相加的函数
	void display();
};
int main()
{
	Complex t1(1,2);                            //定义对象t1
	Complex t2(3,4);			   //定义对象t2
	Complex t3;                               //定义对象t3
	t3=t1.complex_add(t2);                    //调用complex_add函数，使复数相加
	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::complex_add(Complex &t1)       //定义复数相加的函数complex_add
{
	Complex t;                                 //定义Complex类的对象t
	t.real=this->real+t1.real;                      //使两个复数的实部相加
	t.imag=this->imag+t1.imag;                   //使两个复数的虚部相加
	return t;
}
void Complex::display() 
{
	cout<<"("<<real<<","<<imag<<"i)"<<endl;      //输出结果
}

