#include<iostream.h>
class Complex //定义一个Complex类
{
private:
double real; //实部
double imag; //虚部
public:
Complex(){} //定义构造函数
Complex(double r,double i) //重载构造函数
{
real=r;
imag=i;
}
void display()
{
cout<<"("<<real<<","<<imag<<")"<<endl;
}
Complex operator+(Complex i2) //重载加法运算符
{
Complex a;
a.real=this->real+i2.real;
a.imag=this->imag+i2.imag;
return a;
}
Complex operator-(Complex i2) //重载减法运算符
{
Complex b;
b.real=this->real-i2.real;
b.imag=this->imag-i2.imag;
return b;
}
Complex operator*(Complex i2) //重载乘法运算符
{
Complex c;
c.real=this->real*i2.real;
c.imag=this->imag*i2.imag;
return c;
}
Complex operator/(Complex i2) //重载除法运算符
{
Complex d;
d.real=this->real/i2.real;
d.imag=this->imag/i2.imag;
return d;
}
};
void main()
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
Complex a,b,c,d,i1(x1,y1),i2(x2,y2);
a=i1+i2; // 利用重载后的运算符求c1,c2的和
b=i1-i2; // 利用重载后的运算符求c1,c2的差
c=i1*i2; // 利用重载后的运算符求c1,c2的积
d=i1/i2; // 利用重载后的运算符求c1,c2相除
cout<<"i1=";i1.display();
cout<<"i2=";i2.display();
cout<<"i1+i2=";a.display();
cout<<"i1-i2=";b.display();
cout<<"i1*i2=";c.display();
cout<<"i1/i2=";d.display();
}