Bootstrap

C++第四章运算符重载习题-2:成员函数复数加减乘除

#include<iostream>

using namespace std;

class Complex
{
public:
    Complex(){real=0,imag=0;}
    Complex(double r ,double i):real(r),imag(i){}
    Complex operator + (Complex &);
    Complex operator -(Complex&);
    Complex operator *(Complex&);
    Complex operator /(Complex&);
    void display();
private:
    double real;
    double imag;
};

Complex Complex::operator+(Complex &c)
{
    return Complex(real+c.real,imag+c.imag);
}

Complex Complex::operator-(Complex &c)
{
    return Complex(real-c.real,imag-c.imag);
}

Complex Complex::operator*(Complex &c)
{
    return Complex(real*c.real-imag*c.imag,imag*c.real+real*c.imag);
}

Complex Complex::operator/(Complex &c)
{
 

;