首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下复数类的声明,请补充完整。 class complex { double real; //实部 double imag; //虚部 public: complex(double x,double y) {
有如下复数类的声明,请补充完整。 class complex { double real; //实部 double imag; //虚部 public: complex(double x,double y) {
admin
2009-06-20
39
问题
有如下复数类的声明,请补充完整。
class complex {
double real; //实部
double imag; //虚部
public:
complex(double x,double y) {
real=x;
imag=y;
}
complex operator +(complex c) { //重载加法运算符"+"
return complex(【 】);
}
};
选项
答案
real+c.real,imag+c.imag或this->real+c.real,this->imag+c.imag,注意:运算符+的数据可交换次序
解析
本题考查的知识点是:运算符重载。根据题目的要求,要实现类complex的重载加法运算符“+”。复数的加法是将其实部与虚部分别相加,因此空处应填入 real+c.real,imag+c.imag,这样就构造出一个临时的complex对象,并且它的实部和虚部分别为自身和形参c的实部与虚部之和,然后通过return语句返回这个结果。
转载请注明原文地址:https://kaotiyun.com/show/lojp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若函数调用时的实参为变量,以下关于函数形参和实参的叙述中正确的是()。
对下列二叉树进行前序遍历的结果为()。
数据结构主要研究的是数据的逻辑结构、数据的运算和()。
在黑盒测试方法中,设计测试用例的主要根据是()。
以下叙述中正确的是()。
有三个关系R、S和T如下:由关系R和S通过运算得到关系T,则所使用的运算为( )。
给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放
在数据库设计中,将E-R图转换成关系数据模型的过程属于()。
以下不正确的转义字符是()。
设某棵树的度为3,其中度为3、2、1的结点个数分别为3、0、4。则该树中的叶子结点数为
随机试题
导致慢性肺源性心脏病最常见的病因是
A.硫糖铝B.氢氧化铝C.西咪替丁D.雷尼替丁E.奥美拉唑目前认为最强的胃酸分泌抑制剂是()。
对药品进行杂质检查应在什么步骤后进行
抑制细菌DNA促螺旋酶的药物抑制细菌依赖DNA的RNA聚合酶(DDRP)的药物
水泥混凝土路面实测混凝土强度大于设计强度的()后,可停止养护。
矩阵型监理组织形式的缺点是()。
企业将自有资产转换为以公允价值模式进行后续计量的投资性房地产时形成的其他综合收益,在投资性房地产处置时,要将其结转到“其他业务收入”科目中。()
你是税务机关的一名人员,一天有一紧急文件需要请示某部门领导,本单位的领导让你去一趟,而且说要马上办。可是你到该部门后,领导正在开会,你怎么办?
下列关于DVD光盘的叙述中,不正确的是( )。
在考生文件夹下,打开文档WORD1.DOCX,按照要求完成下列操作并以该文件名(WORD1.DOCX)保存文档。【文档开始】声明科学是中国发展的机遇新华网北京10月28日电在可预见的未来,信息技术和声明科学将是世界科技中最活跃的两个领域,两者在未来有
最新回复
(
0
)