首页
登录
从业资格
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
题库
2022-08-02
78
问题
阅读下列说明和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./
随机试题
【B1】[br]【B3】A、differB、cleverC、famousC只有这个男孩成名,他的画才能卖许多钱。故应选C。
[originaltext]Inmyopinion,FrankLloydWrightwasthegreatestAmericana
[originaltext]INTERVIEWER:ProfessorNadelmanne,youhavebeenoneoftheearli
某集团公司拥有多个大型连锁商场,公司需要构建一个数据库系统以方便管理其业务运作活
我国最初的艾滋病属于带人性疾病。()
高血压健康管理的程序应该从哪几方面开始()A.一般情况调查 B.基本资料收
流浪未成年人工作是一项兼具救助性、福利性和管理性的工作。下列关于流浪未成年人工作
下列属于非关税国际贸易壁垒的有( )。[2008年中级真题]A.过境税 B.
“负责本单位变电站应急管理以及变电安全事件的调查分析及考核”属于()应履行的职
“诸断罪而无正条,其应出罪者,则举重以明轻;其应入罪者,则举轻以明重。”——《唐
最新回复
(
0
)