首页
登录
从业资格
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。
题库
2022-08-02
75
问题
阅读下列说明和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./
随机试题
Teddy:Gravityisveryimportant.Bob:Whatdoyoumean?Teddy:Gravityisthef
[originaltext]Therearedifferentwaystostorefish.Twowaystokeepfish
Idon’tknowwhenhe______,butwhenhe______I’llspeaktohim.A、willcome...co
关于消防增(稳)压设施的水箱保养,以下说法错误的是()A.针对检查发现的问
下列关于里约热内卢奥运会的说法正确的是: ①里约热内卢是奥运史上首个举办奥运会
共用题干 某食品企业为了扩大生产规模,提高市场占有率,经过市场考察决定收购某同
教师的平均工资水平应当( )当地公务员的平均工资水平。 A.相当于
为了公共利益的需要,可以作出国有土地上房屋征收决定的情形有( )。A.旧城区改造
一住店客人未付房钱即想离开旅馆去车站。旅馆服务员揪住他不让走,并打报警电话。客人
根据《税务行政复议规则》,在复议机关作出复议决定前,申请人与被申请人可以自愿达成
最新回复
(
0
)