按要求调试下列程序并回答相关问题。程序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; do
答案: ⑴ 程序的输出结果为: 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( ) 的作用是获取复数的模长。
⑶ 将main()函数中的语句行“ cout <<A.get_real()<<endl ;”改为“cout <<A. real<<endl;”,重新编译程序,将出现编译错误,其原因是real是complex类的私有成员变量,不能直接访问。
原文地址: https://www.cveoy.top/t/topic/bPFR 著作权归作者所有。请勿转载和采集!