1.重载和实现复数相除
#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 &c2);
void display();
private:
double real;
double imag;
};
complex complex:: operator / (complex &c2)
{
complex c;
c.real = (realc2.real + imag * c2.imag) / ((c2, real + c2.imag)(C2, real + c2.imag));
c.imag = (inagc2.real 一realc2 imag) / ((c2, real + c2.imag)*(c2, real + c2.inag));
return c;
}
void complex : : disp1ay()
{
cout << “(”<< real <<","<< imag << “i)” << endl ;
}
int main()
{
complex c1(3,9), c2(6, 4),c3;
c3 = c1