复数类代码如下
class complex
{ private:
double real_part, imaginary_part;
public:
void set(double rp,double ip)
{ real_part=rp;
imaginary_part=ip;}
void display()
{ if(imaginary_part>0)
cout<<real_part<<"+"<<imaginary_part<<"i"<<endl;
else if(imaginary_part<0)
cout<<real_part<<imaginary_part<<"i"<<endl;
else
cout<<real_part<<endl;}