正在加载图片...
例32 #include <iostream.h> #include <math. h> class complex( private: d hubie re al, imag? public void init(double r, double i real=r; imag=i;) double realcomplexo i return real; 3 double imagcomplexo( return imag double abscomplexo i double t; t=real*real+imag *imag; return sgrt(t; void main( i complex A; Aini(1.1,2.2) cout<“复数A的实部=“<A. realcomplex0<end; cout<<s 复数A的实部=“<< A. imagcomplexo<end; cout<“复数A的绝对值=“<A. abscomplexo<<endl;5 例 3.2 #include <iostream.h> #include <math.h> class complex{ private: double real, imag; public: void init (double r, double i) { real=r; imag=i; } double realcomplex() { return real;} double imagcomplex() { return imag;} double abscomplex() { double t; t=real*real+imag*imag; return sqrt(t); } }; void main( ) { complex A; A.init(1.1,2.2); cout<<“复数A的实部= “<<A.realcomplex()<<endl; cout<<“复数A的实部= “<<A.imagcomplex()<<endl; cout<<“复数A的绝对值= “<<A.abscomplex()<<endl; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有