首页
登录
从业资格
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
题库
2022-08-02
49
问题
阅读下列说明和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./
随机试题
Thehorseandcarriageisathingofthepast,butloveandmarriagearesti
颐和园(theSummerPalace)位于北京西郊,始建于清朝,是中国规模最大、保存最完好的皇家园林(imperialgarden)之一。186
Thepassageismainlyaboutwhyandhowtoplantmoretreestomakeuniversities
为患者翻身时,操作不妥的是A.手术后患者应先翻身再换药 B.骨牵引的患者翻身时
上市公司对于存货计价方法的不同选择会影响到可比性。()
腰椎管狭窄症最有意义的检查是A.腰椎平片 B.腰椎穿刺 C.腰椎管造影 D
纳税人停业期满不能及时恢复生产、经营的,应当在()向税务机关提出延长停业登记。A
银行承兑汇票的承兑银行,应当按照票面金额向出票人收取()的手续费。A:千分之一
根据2017版红皮书通用条件,下列关于承包商发起的变更与工程师征求建议书变更的
A.筒箭毒 B.酚妥拉明 C.普萘洛尔 D.六烃季铵 E.十烃季铵N受体
最新回复
(
0
)