level 2
klc19921111
楼主
class CComplex
{
double real,imag;
friend CComplex add_complex(CComplex &,CComplex &);
public:
CComplex(double r){real=r;imag=0;}
void assign(double r,double I){real=r;imag=I;}
void show()
{cout<<real<<"+"<<imag<<"i"<<endl;}
};
重载运算符“+”和“—”实现两复数的加、减运算。
void main( )
{
CComplex com1(3);
com1.show();
CComplex com2(5);
com2.show();
com2.assign(5,9);
com2.show();
(com1,com2).show(); //输出为8+9i
(com1,com2).show(); //输出为-2-9i
}
2014年04月27日 05点04分
1
{
double real,imag;
friend CComplex add_complex(CComplex &,CComplex &);
public:
CComplex(double r){real=r;imag=0;}
void assign(double r,double I){real=r;imag=I;}
void show()
{cout<<real<<"+"<<imag<<"i"<<endl;}
};
重载运算符“+”和“—”实现两复数的加、减运算。
void main( )
{
CComplex com1(3);
com1.show();
CComplex com2(5);
com2.show();
com2.assign(5,9);
com2.show();
(com1,com2).show(); //输出为8+9i
(com1,com2).show(); //输出为-2-9i
}