首页
登录
从业资格
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构
admin
2022-08-02
17
问题
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。
【C++代码】#includeusing 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 printInvoice( ){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.printInvoice( );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.这部分是发票的脚注,看类图应该实现函数printInvoice,Decorator装饰模式使用该方法。
5.FootDecorator a(NULL);脚步的装饰参数是a,调用a参数。
转载请注明原文地址:https://www.tihaiku.com/congyezige/2409837.html
本试题收录于:
中级 软件设计师题库软件水平考试初中高级分类
中级 软件设计师
软件水平考试初中高级
相关试题推荐
某企业信息系统的部分关系模式及属性说明如下: (1)员工关系模式:员工(员工编
某法院要开发一个诉讼案件信息处理系统,该信息系统的部分关系模式如下: 职工(职
某医院管理系统部分关系模式为:科室(科室号,科室名,负责人,电话)、病患(病历号
天津市某银行信息系统的数据库部分关系模式如下所示: 客户(客户号,姓名,性别,
计算机指令一般包括操作码和地址码两部分,为分析执行一条指令,则其( )。A.操
操作系统的功能可分为相互配合、协调工作的5大部分,其中不含()。A.进程管理
某超市销售系统的部分关系模式如下:商品表:Commodity(Ccode,C
某航空公司要开发一个订票信息处理系统,该系统的部分关系模式如下:航班(航班编号,
某工厂的信息管理数据库的部分关系模式如下所示:职工(职工号,姓名,年龄,月工资,
某汽车租赁公司建立汽车租赁管理系统,其数据库的部分关系模式如下:用户:USERS
随机试题
IfyouwanttoknowwhyDenmarkistheworld’sleaderinwindpower,startw
TheblueswasbornontheMississippiRiverDeltaintheearly1900s.Aftert
Sheleaned_________thewallwhileshewasspeakingtoherfriend.A、toB、against
AtthepublicradiostationKEXPinSeattle,there’sasimpleprocedurefor
WirelessChargingMayTakePlaceofWiredChargingA)Lastmonth,
下列因素中,影响旅客运送速度的是()。A.旅客排队购票时间 B.客运车辆的技
甲某,因肝硬化门静脉高压入院就诊,近日患者诉左腹部疼痛,行CT检查提示脾脏区低密
患儿,女,6个月,睡眠不安、夜间啼哭,多汗,枕秃。体检:胸部有肋骨串珠、哈里森沟
关于成长小组,下列理解错误的有( )。A.成长小组被广泛地应用于社区、学校、医
强调引导小组组员建立团结、互助与合作的关系体现了小组工作()的特点。A.小组组
最新回复
(
0
)