第一题
class Complex
{
public:
Complex():real(0),imag(0) {}
Complex(double r,double i):real(r),imag(i) {}
friend Complex operator + (Complex &,Complex &);
Complex operator - ( Complex &);
Complex operator * ( Complex &);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
Complex Complex::operator - (Complex &c)
{
return Complex(real-c.real,imag-c.imag);
}
Complex Complex::operator * ( Complex &c)
{
Complex temp;
temp.real = real * c.real - imag * c.imag;
temp.imag = real * c.imag + c.real * imag;
return temp;
}
void Complex::display()
{
cout