首页
登录
从业资格
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
题库
2022-08-02
81
问题
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。
【C++代码】 #include<iostream> using namespace std; class invoice{ public: (1){ cout<<"This is the content of the invoice!"<<endl; } }; class Decorator:public invoice{ Invoice*ticket; public: Decorator(lnvoice*t){ticket=t;} void printinvoice(){ if(ticket!=NULL) (2); } }; class HeadDecorator:public Decorator{ public: HeadDecorator(lnvoice*t):Decorator(t){} void printinvoice0{ cout<<"This is the header of the invoice!"<<endl; (3); } }; class FootDecorator:public Decorator{ public: FootDecorator(invoice*t):Decorator(t){} void printlnvoice(){ (4); cout<<"This is the footnote of the invoice!"<<endl; } }; int main(void){ Invoice t; FootDecorator f(&t); HeadDecorator h(&f); H.printlnvoice(); cout<<“_____”<<endl; FootDecorator a(NULL); HeadDecorator b((5)); B.printinvoice(); return 0; } 程序的输出结果为: This is the header of the invoice! This is the content of the invoice! This is the footnote of the invoice! ---------------------------- This is the header of the invoice! This is the footnote of the invoice!
选项
答案
解析
(1) virtual void printInvoice() (2) ticket->printInvoice() (3) Decorator::printInvoice() (4) Decorator::printInvoice() (5) &a
【解析】
试题分析
1.Invoice类下,义虛函数,按类图,函数名是printInvoice
2.前面定义对象名是ticket,那么在ticket不为空的时候调用函数printInvoice
3.这部分填写发票的抬头,看类图应该实现函数printInvoice ,Decorator装饰模式使用该方法
4.这部分是发票的脚注,看类图应该实现函数printlnvoice,Decorator装饰模式使用该方法
5.FootDecorator a(NULL) ;脚步的装饰参数是a,调用a参数,
转载请注明原文地址:https://tihaiku.com/congyezige/2424913.html
本试题收录于:
初级程序员题库软件水平考试初中高级分类
初级程序员
软件水平考试初中高级
相关试题推荐
IE浏览器能够正确解析()代码。A.ASP B.HTML C.JSP D
通过内部发起连接与外部主机建立联系,由外部主机控制并盗取用户信息的恶意代码为(
下列设置图像地图正确的HTML代码是()。A.<areashape="po
()不是蠕虫病毒。A.冰河 B.红色代码 C.熊猫烧香 D.爱虫病毒
()属于系统软件,它直接执行高级语言源程序或与源程序等价的某种中间代码。A.编译
有以下HTML代码,在浏览器中显示正确的是()。 <html>
要在HTML中按原格式输出一段程序代码,需使用()标记。A.<code></
HTML页面的“<title>主页</title>”代码应写在()标记内A.
HTML页面的标题代码应写在()标记内。A.<head></head> B.
要在HTML代码中加入注释,应使用()来标记。A.<!----> B./
随机试题
【S1】[br]【S7】of→from介词误用题。hearof是“听说”的意思,hearfrom是“收到某人的来信”的意思。根据原文应该是很多年没收到信
Languageislearnedprimarilythroughcommunicationwithotherpeople.Resea
Thedetectivestory,ascreatedbyPoe,is
视野是指人的头部和眼球固定不动的情况下,眼睛观看正前方物体时所能看得见的空间范围
专业性检查是指对易发生事故的设备、场所或操作工序,除在综合性大检查时检查外,还要
依据行为改变的阶段理论,健康管理师在第4、5阶段的最主要工作是()A.重
粉末涂料不使用溶剂或水作为分散介质,而是借助于空气作为分散介质。
属于Ⅲ度胎盘早剥临床表现的项目,错误的是A、子宫硬如板状 B、血压下降
酪氨酸在体内可转变为 A.胆色素B.肾上腺素C.延胡索酸D.乙酰乙酸
单位工程优良率高于(),工程项目方可评定为优良。A.50% B.70%
最新回复
(
0
)