1.定义复数Complex类,使用友元,完成复数的加法、减法、乘法和除法运算,以及对复数的输出.

1个回答

  • #pragma once

    #include

    using namespace std;

    class Complex

    {

    public:

    Complex(double re=0.,double im=0.)

    {

    real=re;

    imag=im;

    }

    void setreal(const double r);

    void setimag(const double i);

    friend Complex operator-(const Complex &);

    friend istream& operator>>(istream &in,Complex &c);

    friend ostream& operator(istream &in,Complex &c)

    {

    return in>>c.real>>c.imag;

    }

    ostream& operato