您的位置首页百科知识

定义复数类型存放实部和虚部

定义复数类型存放实部和虚部

//---------------------------------------------------------------------------#include class ccomplex{ public: double real,imag; ccomplex():real(0),imag(0){} void get_data(void) { std::cout<<"real part:"; std::cin>>real; std::cout<<"imaginary part:"; std::cin>>imag; } ccomplex operator+(const ccomplex& a) { ccomplex c(a); c.real+=real; c.imag+=imag; return c; } void print(void) const { std::cout<