首页
登录
从业资格
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
题库
2022-08-02
57
问题
阅读下列说明和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./
随机试题
[originaltext]A:Youknow,whenitcomestotheconnectionsyoumakeinnetwork
对于可调的项目,必须明确调价的基准点,即调差的基本价格或原始价格。材料和设备价格
风湿性心脏炎患者,抗风湿治疗的疗程为A.6~9个月 B.1~2w C.8~1
根据现行的对贷款额度的规定,个人住房贷款最低首付款比例为( )。A.20%
治疗初期颈痈,应首选( )。A.五味消毒饮 B.牛蒡解肌汤 C.仙方活命饮
A.皮肤瘙痒 B.手足拘挛不伸 C.目睛上吊 D.手足蠕动 E.眩晕欲仆
图示结构,已知:q=10kN/m,P=20kN,Q=30kN。试求固定端A的约束
某学校倡导:“教育要和孩子的天性合作,让学校成为一个寓教于乐的地方“1-2年级
增值税的出口退税额()。 A.不计人会计利润B.不征收企业所得税C.不
A.氢氧化铝凝胶 B.硫酸镁 C.西咪替丁 D.奥美拉唑 E.枸橼酸铋钾
最新回复
(
0
)