首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。 【说明】 软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。 【代码13-l】 /*________________________
阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。 【说明】 软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。 【代码13-l】 /*________________________
admin
2010-01-15
43
问题
阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。
【说明】
软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。
【代码13-l】
/*___________________________________*/
/********* 文件 MiniComplex. h*********/
/*___________________________________*/
#include<iostream>
using namespace std;
class MiniComplex
{(1):
//重载流插入和提取运算符
(2) ostream & operator <<(ostream & osObject, const MiniComplex & complex)
{ osObject <<"("<<complex. realPart<<"+"<<complex. imagPart <<"I"<<")";
return osObject;
}
friend (3) operator >>(istream & isObject, MiniComplex & complex)
{ char ch;
isObject >>complex. realPart >>ch>>complex. imagPart >>ch;
return isObject;
}
MiniComplex(double real=0, double imag=0); //构造函数
MiniComplex operator+(const MiniComplex & otherComplex)const! //重载运算符+
MiniComplex operator--(const MiniComplex & otherComplex)const! //重载运算符-
MiniComplex operator*(const MiniComplex& othmComplex)const; //重载运算符*
MiniComplex operator/(const MiniComplex & otherComplex)const; //重载运算符/
bool operator==(const MiniComplex &otherComplex)const; //重载运算符==
private:
double realPart; //存储实部变量
double imagPart; //存储虚部变量
};
/*_______________________________________________________*/
/* * * * * * * * *文件 MiniComplex. cpp* * * * * * * * * */
/*_______________________________________________________*/
# include "MiniComplex.h"
bool MiniComplex:: operator==(const MiniComplex & otherComplex)const
{ (1);}
MiniComplex:: MiniComplex(double real, double imag){realPart=real;imagPart=imag!}
MiniComplex MiniComplex:: operator+(const MiniComplex & otherComplex)const
{ MiniComplex temp;
temp. realPart=realPart+ otherComplex. realPart;
temp. imagPart=imagPart+ otherComplex. imagPart;
return temp;
}
MiniComplex MiniComplex::operator--(const MiniComplex & otherComplex)const
{ MiniComplex temp;
temp.realPart=realPart-otherComplex.realPart;
temp. imagPart=imagPart-otherCompler.imagPart;
return temp;
}
MiniComplex MiniComplex:: operator*(const MiniComplex& otherComplex)const
{ MiniComplex temp;
temp.realPart=(realPart* otherComplex.realPart)-(imag-Part* otherComplex.imag-Part);
temp imagPart=(realPart* otherComplex. imagPart)+(imag-Part *otherComplex.realPart);
return temp,
}
MiniComplex MiniComplex:: operator/(const MiniComplex& otherComplex)eonst
{ MiniComplex temp;
float tt;
tt=1/(otherComplex. realPart *otherComplex. realPart+otherComplex. imagPart* other Complex.imagPart);
temp. realPart=((realPart* otherComplex.realPart)+(imagPart* otherComplex.imagPart))*tt;
temp. imagPart=((imagPart * otherComplex.realPart)-(realPart* otherComplex.imagPart))*tt;
return temp;
}
/*__________________________________________________*/
/* * * * * * * *主函数所在文件main.cpp* * * * * * * */
/*_________________________________________________*/
# include<iostream>
# include "(5)"
using namespace std;
int main(void)
{ MiniComplex num1(23, 34), num2;
cin>>num2;
cout<<"Initial Value of Numl="<<num1<<"\nInitial Value of Num2="<<num2<<end1;
cout<<num1<<"+"<<num2<<"="<<num1+num2<<end1;
//使用重载的加号运算符
cout<<num1<<"-"<<num2<<"="<<num1-num2<<end1;
//使用重载的减号运算符
cout<<num1<<"*"<<num2<<"-"<<num1*num2<<end1;
//使用重载的乘号运算符
cout<<num1<<"/"<<num2<<"="<<num1/num2<<end1;
//使用重载的除号运算符
return 0;
}
选项
答案
(1)public(2)friend(3)istream&. (4)return(realPart==otherComplex. realPart && imagPart==otherComplex. imagPart) (5)MiniComplex.h
解析
根据UML的类图可知,该迷你小型复数类有两个属性realPart、imagPart,分别表示复数的实部和虚部。它还重载了输出流和输入流运算符,而且重载了加、减、乘、除以及等于这5种运算符。以方法“+operator+(otherComplex:const MiniComplex&):MiniComplex”为例来说明其表述的方式:最前面的“+”号表示该方法是公有的(若是“-”号则表示是私有的,若是“#”则表示是保护的);otherComplex是该方法的参数,const MiniComplex&是该参数的类型;最后的MiniComplex表示该方法的返回类型。
通过上述分析可知,(1)空显然填public,因为各方法及构造函数均是公有的。在 operator<<的定义体内,发现使用了参数complex的属性realPart和imagPart,并对比 operator>>可知,operator<<是MiniComplex的友元函数,因此第(2)空显然应填 friend。(3)空显然是要填operator>>的返回类型,根据UML类图可知填istream&。两个复数的实部和虚部均相等时两复数相等,因此,第(4)空填“return(realPart==other Complex.realPart &&imagPart==otherComplex.imagPart);”,注意,不能丢分号。在使用一个类时,我们只要在文件中包含它的头文件即可,于是第(5)空填MiniComplex.h。
运行上述程序,输入复数56+35i,可得运行结果如下:
56+35i
Initial Value of Num1=<23+34i>
Initial Value of Num2=<56+35i>
<23+34i>+<56+35i>=<79+69i>
<23+34i>-<56+35i>=<-33+-1i>
<23+34i>*<56+35i>=<98+2709i>
<23+34i>/<56+35i>=<0.568218+0.252006i>
注意,各文件必须放在同一个工程之内,而且operator<<和operator>>的友元声明关键字:friend不能缺少,否则不能运行。
转载请注明原文地址:https://kaotiyun.com/show/TcDZ777K
本试题收录于:
软件设计师下午应用技术考试题库软考中级分类
0
软件设计师下午应用技术考试
软考中级
相关试题推荐
在结构化分析方法中,数据流图描述数据在系统中如何被传送或变换,反映系统必须完成的逻辑功能,用于(38)建模。在绘制数据流图时,(39)。(38)
假设系统中有三类互斥资源R1、R2和R3,可用资源数分别为10、5和3。在T0时刻系统中有P1、P2、P3、P4和P5五个进程,这些进程对资源的最大需求量和已分配资源数如下表所示,此时系统剩余的可用资源数分别为(22)。如果进程按(23)序列执行,那么系统
根据ANSI/IEEE829标准,(62)属于《测试案例说明》中的内容。 ①输入说明 ②测试目的 ③环境要求 ④特殊要求
在统一建模语言(UML)中,描述系统与外部系统及用户之间交互的图是(8)。
《GB/T18905软件工程产品评价》标准中确定的通用评价过程包括:(55)。
关于软件著作权产生的时间,下面表述正确的是(10)。
以下不属于单元测试测试内容的是______。
对于逻辑表达式(((a|b)‖(c>2))&&d<0),需要________________个测试用例才能完成条件组合覆盖。
针对下列程序段,对于(A,B)的取值,以下(57)测试用例组合能够满足条件覆盖的要求。IF((A-10)=20AND(B+20)>10)THENC=0IP((A-30)<10AND(B-30)<0)THENB=30①A=5
根据输出对输入的依赖关系设计测试用例的黑盒测试方法是________。
随机试题
InthelatenineteenthcenturyBritainkeptoutofforeignpoliticsasmuchaspossible.Europewasdividedintotwocamps:Fran
企业品牌网站设计的类型有【】
经批准可以在大众传播媒介上进行广告宣传的是
患者林某,男性,30岁,因脑外伤昏迷2天,持续性高热,体温40.5℃,遵医嘱给予冰帽降温以防止脑水肿的机理是
患者腰膝酸软,发白脱落,目昏暗,经诊断为肝肾精血亏虚证,在五行学说中属于()。
白血病化疗期间口服别嘌呤醇的目的是
下列关于未进行房屋所有权登记,人民法院也可以进行预查封的说法,正确的是()。
某公司计划对某一项目进行投资,投资额为300万元,期限为5年,每年净现金流量分别为150万元、200万元、200万元、100万元、200万元。假设资本成本率为10%。该项目的净现金流量及复利现值系数如下表所示:根据以上资料,回答下列问题:投资回收期
某部门组织一次活动,包括唱歌、聚餐和出游三个项目。其中,5人请病假没有参加任何活动,只参加一个项目的比没参加的人多,但不到10人,他们恰好可以平均分成3组;只参加2个项目的有十几个人,他们恰好可以平均分成4组;3个项目都参加的占到部门人数的一半,他们恰好可
(2015年第37题)结合材料回答问题:材料12014年10月闭幕的十八届四中全会,是党在中央全会上第一次专题讨论依法治国的问题,体现了对法治的高度重视。会议结束后,微博上的各种评论,满是对法治进步的热望:“想要法治的果实,就要给它阳光雨露”“期待法治
最新回复
(
0
)