程序1exp_101cpp#include iostream#include mathhusing namespace std;class complex private double real; double imag; public void set_complexdouble rdouble i real=r;imag=i; double get_real retu
⑴ 输出结果为:
real of complex A=3 imag of complex A=4 abs of complex A= 5
⑵ set_complex(double r,double i)方法的作用是设置实部和虚部的值;get_real()方法的作用是返回实部的值;get_imag()方法的作用是返回虚部的值;get_abs()方法的作用是返回该复数的模长。
⑶ 改为“cout <<A.real<<endl;”后会出现编译错误,因为real是complex类中的私有成员变量,无法直接访问。
原文地址: https://www.cveoy.top/t/topic/bPFz 著作权归作者所有。请勿转载和采集!