网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
阅读下列说明和C++代码,将应填入( )处的字句写在答题纸的对应栏内。
【说明】
某图像预览程序要求能够查看BMP、JPEG和GIF三种格式的文件,且能够Windows和Linux两种操作系统上运行。程序需具有较好的扩展性以支持新的文件格式和操作系统。为满足上述需求并减少所需生成的子类数目,现采用桥接(Bridge)模式进行设计,得到如图5-1所示的类图。

【C++代码】

#include#include<:string>;Using namespace std;class Matrix{//各种格式的文件最终都被转化为像素矩阵//此处代码省略};class Implementor{public:( );显示像素矩阵 m};class WinImp:publicImplementor{public:Viod doPaint(Matrix m){/*调用 Windows 系统的绘制函数绘制像素矩阵*/};class LinuxImp:publicImplementor{/*调用 Linux 系统的绘制函数绘制像素矩阵*/}};class Image{public:viod setImp(Implement*imp) {this->imp=imp;}Virtual viod parseFile(string fileName)=0protected:Implementor*imp;};class BMPImage:publicImage{//此处省略代码};class GIFImage:publicImage{Public:viod parseFile(string fileName) {//此处解析 GIF 文件并获得一个像素矩阵对象 m( );显示像素矩阵 m}};class JPEGImage:publicImage{//此处代码省略};int main(){//在 linux 操作系统上查看 demo.gif 图像文件Image*image=( );Implementor*imageImp=( );( )Image->parseFile(〝demo.gif〝);return0;}


参考答案

参考解析
解析:1.virtual void doPaint(Matrix m) = 0
2. imp->doPaint(m)
3. new GIFImage()
4. new LinuxImp()
5. image->setImp(imageImp)
更多 “阅读下列说明和C++代码,将应填入( )处的字句写在答题纸的对应栏内。 【说明】 某图像预览程序要求能够查看BMP、JPEG和GIF三种格式的文件,且能够Windows和Linux两种操作系统上运行。程序需具有较好的扩展性以支持新的文件格式和操作系统。为满足上述需求并减少所需生成的子类数目,现采用桥接(Bridge)模式进行设计,得到如图5-1所示的类图。 【C++代码】 #include#include;Using namespace std;class Matrix{//各种格式的文件最终都被转化为像素矩阵//此处代码省略};class Implementor{public:( );显示像素矩阵 m};class WinImp:publicImplementor{public:Viod doPaint(Matrix m){/*调用 Windows 系统的绘制函数绘制像素矩阵*/};class LinuxImp:publicImplementor{/*调用 Linux 系统的绘制函数绘制像素矩阵*/}};class Image{public:viod setImp(Implement*imp) {this->imp=imp;}Virtual viod parseFile(string fileName)=0protected:Implementor*imp;};class BMPImage:publicImage{//此处省略代码};class GIFImage:publicImage{Public:viod parseFile(string fileName) {//此处解析 GIF 文件并获得一个像素矩阵对象 m( );显示像素矩阵 m}};class JPEGImage:publicImage{//此处代码省略};int main(){//在 linux 操作系统上查看 demo.gif 图像文件Image*image=( );Implementor*imageImp=( );( )Image->parseFile(〝demo.gif〝);return0;}” 相关考题
考题 阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】现欲实现一个图像浏览系统,要求该系统能够显示BMP、JPEG和GIF三种格式的文件,并且能够在Windows和Linux两种操作系统上运行。系统首先将BMP、JPEG和GIF三种格式的文件解析为像素矩阵,然后将像素矩阵显示在屏幕上。系统需具有较好的扩展性以支持新的文件格式和操作系统。为满足上述需求并减少所需生成的子类数目,采用桥接(Bridge)设计模式进行设计所得类图如图5—7所示。采用该设计模式的原因在于:系统解析BMP、GIF与JPEG文件的代码仅与文件格式相关,而在屏幕上显示像素矩阵的代码则仅与操作系统相关。【Java代码】class Matrix{//各种格式的文件最终都被转化为像素矩阵//gt处代码省略};abstract class ImageImp{public abstract void doPaint(Matrix m); //显示像素矩阵m};class WinImp extends ImageImp{public void doPaint(Matrix m){/*调用windows系统的绘制函数绘制像素矩阵*/}};class LinuxImp extends ImageImp{public void doPaint(Matrix m){/*调用Linux系统的绘制函数绘制像素矩阵*/}};abstract class Image{public void setImp(ImageImp imp){(1) =imp;}public abstract void parseFile(String fiieName);protected (2) imp;};class BMP extends Image{public void parseFile(String fiieName){//此处解析BMP文件并获得一个像素矩阵对象m(3) ;//显示像素矩阵m}};classGIF extends Image{//此处代码省略};class JPEG extends Image{//此处代码省略};publ.ic class j avaMain{public static v。id main (string[]args) {//在windows操作系统上查看demO.bmp图像文件Image imagel= (4) ;ImageImp imageImpl= (5) ,(6鱼) ;imagel.parseF’ile(“demo.bmp”);}}现假设该系统需要支持10种格式的图像文件和5种操作系统,不考虑类Matrix和类ja.vaMain,若采用桥接设计模式则至少需要设计 (7) 个类。

考题 阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款飞机飞行模拟系统,该系统主要模拟不同种类飞机的飞行特征与起飞特征。需要模拟的飞机种类及其特征如表5-l所示。为支持将来模拟更多种类的飞机,采用策略设计模式(Strategy)设计的类图如图5—1所示。图5-l中,AirCraft为抽象类,描述了抽象的飞机,而类Helicopter、AirPlane、Fighter和Harrier分别描述具体的飞机种类,方法fly( )和takeOff( )分别表示不同飞机都具有飞行特征和起飞特征;类FlyBehavior与TakeOffBehavior为抽象类,分别用于表示抽象的飞行行为与起飞行为;类SubSonicFly与SuperSonicFly分别捕述亚音速飞行和超音速飞行的行为;类Verti calTakeOff与LongDistanceTakeoff分别描述垂直起飞与长距离起飞的行为。【C++代码】includeusing namespace std;class FlyBehavior{public:virtual void fly( )=0;};class SubSonicFly:public FlyBehavior{public: void fly( ){cout"亚音速飞行! "

考题 阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:【c++代码】include1istincludeincludeusing namespace std;class AbstractFile{protected:string name;//文件或目录名称public:void printName(){cout*getChildren()=0; //获得一个目录的子目录或文件};class File:public AbstractFile{public:File(string name){ (1) =name;)void addChild(AbstractFile*file){return ;)void removeChiid(AbstractFile*file){return;}(2) getChildren(){return ( 3 ) ;}};class Folder:public AbstractFile{private:listchildList; //存储子目录或文件public:Folder(string name){ (4) =name;}void addChild(AbstractFile*file){childList.push back(file);}void removeChiid(AbstractFile*file)(chiidList.remove(file);}list*getChildren(){return (5) ;)};voidmain(){//构造一个树形的文件/目录结构AbstractFile*rootFolder=new Folder(“C:\\”);AbstractFile*compositeFolder=flew Folder(”composite”);AbstractFile*windowsFolder=new Folder(”windows”);AbstractFile*file=new File(”TestComposite.java”);rootFolder-addChild(compositeFolder);rootFolder-addChild (windowsFolder);compositeFolder-addChiid(file);)

考题 阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】现欲实现一个图像浏览系统,要求该系统能够显示BMP、JPEG和GIF三种格式的文件,并且能够在Windows和Linux两种操作系统上运行。系统首先将BMP、JPEG和GIF三种格式的文件解析为像素矩阵,然后将像素矩阵显示在屏幕上。系统需具有较好的扩展性以支持新的文件格式和操作系统。为满足上述需求并减少所需生成的子类数目,采用桥接(Bridge)设计模式进行设计所得类图如图5—6所示。采用该设计模式的原因在于:系统解析BMP、GIF与JPEG文件的代码仅与文件格式相关,而在屏幕上显示像素矩阵的代码则仅与操作系统相关。【c++代码】class Matrix{//各种格式的文件最终都被转化为像素矩阵//st处代码省略};class ImageImp{public:virtual void doPaint(Matrix m)=0; //显示像素矩阵m};class WinImp:public ImageImp{public:void doPaint(Matrix m){/*调用windows系统的绘制函数绘制像素矩阵*/));class LinuxImp:public ImageImp{public:void doPaint(Matrix m){/*调用Linux系统的绘制函数绘制像素矩阵*/)};class Image{public;void setImp(ImageImp*imp){ (1) =imp;)virtual void parseFile(string fileName)=0 ;protected:(2) *imp;};classBMP:public Image{public:void parseFile(string fileName){//此处解析BMP文件并获得一个像素矩阵对象m(3) ;//显示像素矩阵m};classGIF:public Image{//此处代码省略};classJPEG:public Image(//gh处代码省略};void main(){//在windows操作系统上查看demo.bmp图像文件Image*imagel= (4) ;ImageImp*imageImpl= (5) ;(6) ;imagel-parseFile(“demo.bmp”);}现假设该系统需要支持10种格式的图像文件和5种操作系统,不考虑类Matrix,若采用桥接设计模式则至少需要设计 (7) 个类。

考题 阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作井出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(Waiter)调度厨师制作套餐。现采用生成器(Builder) 模式实现制作过程,得到如图 5-1 所示的类图。图5-1 类图 【C++代码】 includeiostream include string using namespace std; class Pizza { private: string parts; public: void setParts(string parts) { this-parts=parts; } string getParts() { return parts; } }; class PizzaBuilder { protected:Pizza* pizza; public: Pizza* getPizza() { retum pizza; } void createNewPizza() { pizza = new Pizza(); } ( 1 ); } class HawaiianPizzaBuilder :public PizzaBuilder { public: void buildParts() { pizza-setParts(cross +mild + hampineapple); } }; class SpicyPizzaBuider: public PizzaBuilder { public: void buildParts() { pizza-setParts(pan baked +hot + hampineapple); } } Class Waiter{ Private: PizzaBuilder* pizzaBuilder; public: void setPizzaBuilder(PizzaBuilder* pizzaBuilder) { /*设置构建器*/ ( 2 ) } Pizza* getPizza() { return pizzaBuilder-getPizza(); } void construct() { /*构建*/ pizzaBuilder-createNewPizza(); ( 3 ) } }; int main(){ Waiter*waiter=new Waiter(); PizzaBuilder*hawaiian pizzabuilder=new HawaiianPizzaBuilder() ( 4 ); ( 5 ); cout pizza: waiter-getPizza()-getParts() endl; } 程序的输出结果为: pizza: cross + mild + hampineapple

考题 试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】include iostreamusing 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!

考题 阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说明】很多依托扑克牌进行的游戏都要先洗牌。下面的c++程序运行时先生成一副扑克牌,洗牌后再按顺序打印每张牌的点数和花色。【c++代码】inciude <iostream>4Finclude <stdlib. h>include <ctime>inciude <aigorithm>include <string>Using namespace stdConst string Rank[13]={”A”,”2”,”3”,”4“,“5”,”6,”’“7”8“,9”,”10,”J”,”Q”,”K”}j//扑克牌点数

考题 阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如图5-1所示。【c++代码】}

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。command模式的类图如图6-1所示。【Java代码】}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!---------------这是票据的台头!这是票据的脚注!【C++程序代码】#includeusing namespace std;class SalesTicket {public:(1) printTicket() { cout " 是票据正文!" endl;}class Decorator : public SalesTicket{SalesTicket *ticket;public:Decorator(SalesTicket *t){ ticket = t; }void printTicket(){if(ticket != NULL)ticket->printTicket();}};class HeadDecorator : public Decorator{public:HeadDecorator(SalesTicket *t): (2) { }void printTicket() {sour "这是票据的台头!" endl;Decorator::printTicket();}};class FootDecorator :public Decorator{public:FootDecorator(SalesTicket *t): (3)void printTicket() {Decorator::printTicket();cout "这是票据的脚注!" endl;}};void main(void) {SalesTicket t;FootDecorator f(t);HeadDecorator h( (4) );h.printTicket();cout "-------------------------" endl;FootDecorator a(NULL);HeadDecorator b( (5) );b.printTicket();}

考题 阅读下列说明和 C ++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 6-1 所示。 【C++ 代码】#includeusing namespace std;class BrakeBehavior{public:(1) ; /*其余代码省略*/};class LongWheelBrake : public BrakeBehavior{public:void stop(){cout

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 试题六(共 15 分)阅读下列说明和 C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 C++代码实现一个简单的聊天室系统(ChatRoomSystem),多个用户 (User)可以向聊天室(ChatRoom)发送消息,聊天室将消息展示给所有用户。 类图如图 6-1 所表示。 【C++代码】#include#include using namespace std; class User {private:string name; public:User(string name){ (1) =name;}~User(){} void setName(string name) {this->name=name; } string getName(){return name;}void sendMessage(string message); }; class ChatRoom { . public:static void showMessage(User* user, string message) { coutgetName()"] : " zhang->sendMessage("Hi! Leo!");li_>sendMessage("Hi! John!"); }void join(User* user) { (3) ("HeIIoEveryone!l am"+user->getName()); . ;} . };int main(){ChatRoomSystem*crs= (4) ; crs->startup();crs->join( (5) ("Wayne")); delete crs; }/* 程序运行结果: [John]:Hi! Leol [Leo]:Hi! John![Wayne】:Hello Everyone!Iam Wayne/*

考题 阅读下列说明和Java代码,将应填入( )处的字句写在答题纸的对应栏内。 【说明】 某图像预览程序要求能够查看BMP、JPEG和GIF三种格式的文件,且能够在Windows和Linux两种操作系统上运行。程序需具有较好的扩展性以支持新的文件格式和操作系统。为满足上述需求并减少所需生成的子类数目,现采用桥接模式进行设计,得到如图6-1所示的类图。 【Jave代码】 Import java.util.*;class Matrix{ //各种格式的文件最终都被转化为像素矩阵//此处代码省略};abstract class Implementor{Public( );//显示像素矩阵 m};class WinImp extends Implementor{public void doPaint(Matrix m){//调用Windows 系统的绘制函数绘制像素矩阵}};class LinuxImp extends Implementor{public void doPaint(Matrix m){//调用Linux 系统的绘制函数绘制像素矩阵}};abstract class Image{public void setImp(Implementor imp){this.imp= imp; }public abstract void parseFile(String fileName);protected Implementor imp;};class BMPImage extends Image{//此处代码省略};class GIFImage extends Image{public void parseFile(String fileName) {//此处解析BMP 文件并获得一个像素矩阵对象 m( );//显示像素矩阵 m}};Class Main{Public static viod main(String[]args){//在Linux 操作系统上查看 demo.gif 图像文件Image image=()Implementor imageImp=()( )Image.parseFile(〝demo.gif〝);}}

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 5-1 所示。 【Java代码】import java.util.*; interface BrakeBehavior{public (1) ;/*其余代码省略*/}class LongWheelBrake implements BrakeBehavior{public void stop(){System.out.println("模拟长轮胎刹车痕迹! ");}/*其余代码省略*/}class ShortWheelBrake implements BrakeBehavior {public void stop(){System.out.println("模拟短轮胎刹车痕迹! ");}/*其余代码省略 */}abstract class Car{protected (2) wheel;public void brake(){ (3) ;}/*其余代码省略*/}class ShortWheelCar extends Car {public ShortWheelCar(BrakeBehavior behavior){(4) ; } /*其余代码省略*/}class StrategyTest{public static void main(String[]args){BrakeBehaviorbrake =new ShortWheelBrake();ShortWheelCar car1= new ShortWheelCar(brake);car1. (5) ;}}

考题 阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。 【说明】某航空公司的会员积分系统将其会员划分为:普卡 (Basic)、银卡(Silver)和金卡 (Gold) 三个等级。非会员 (NonMember) 可以申请成为普卡会员。会员的等级根据其一年内累积 的里程数进行调整。描述会员等级调整的状态图如图 5-1 所示。现采用状态 (State) 模式实现上述场景,得到如图 5-2 所示的类图。 【问题1】(15分)阅读上述说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上 留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy) 设 计模式来实现该需求,所设计的类图如图 5-1 所示。

考题 阅读下列说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】   某软件公司现欲开发一款飞机飞行模拟系统,该系统主要模拟不同种类飞机的飞行特征与起飞特征。需要模拟的飞机种类及其特征如表5-1所示。表5-1  为支持将来模拟更多种类的飞机,采用策略设计模式(Strategy)设计的类图如图5-1所示。 图5-1中,AirCraft为抽象类,描述了抽象的飞机,而类Helicopter、AirPlane、Fighter和Harrier分别描述具体的飞机种类,方法fly()和takeOff()分别表示不同飞机都具有飞行特征和起飞特征;类FlyBehavior与TakeOffBehavior为抽象类,分别用于表示抽象的飞行为与起飞行为;类SubSonicFly与SuperSonicFly分别描述亚音速飞行和超音速飞行的行为;类VerticalTakeOff与LongDistanceTakeOff分别描述垂直起飞与长距离起飞的行为。 【C++ 代码】 #include

考题 阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 5-1 所示为其类图。 【C++代码】 #include #include using namespace std; class Product { private:? ?? string partA, partB; public: Product() {?? } ? ? ?void setPartA(const string} ???? void setPartB(const string} //? 其余代码省略 }; class Builder { public: ??????? (1)?? ; virtual void buildPartB()=0; ??????? (2)?? ; }; class ConcreteBuilder1 : public Builder { private: Product*?? product; public: ConcreteBuilder1() {product = new Product();???? } ??? void buildPartA() {????? (3)???? ("Component A"); } ??? void buildPartB() {????? (4)???? ("Component B"); } Product* getResult() { return product; } //? 其余代码省略 }; class ConcreteBuilder2 : public Builder {? ?? /*??? 代码省略??? */ }; class Director { private:? Builder* builder; public:? ? Director(Builder* pBuilder) { builder= pBuilder;} ???? void construct() { ? ? ? ? ? ? ? (5)???? ;? ? ? //? 其余代码省略 ????? } //? 其余代码省略 }; int main() { Director* director1 = new Director(new ConcreteBuilder1());? director1->construct();? ? delete director1;? ?? return 0;

考题 阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。 【说明】 某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如下图所示。 Command?模式类图

考题 阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class Invoice{ public: (1) { coutinvoice!" } }; 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( ) { coutheader of the invoice! " (3) ; } }; class FootDecorator : public Decorator{ public: FootDecorator(Invoice *t): Decorator(t) { } void printlnvoice( ){ (4) ; coutfootnote of the invoice!" } }; int main(void) { Invoice t; FootDecorator f( HeadDecorator h( h.printInvoice( ); cout 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!

考题 阅读下列说明和 Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某航空公司的会员积分系统将其会员划分为:普卡 (Basic) 、银卡(Silver)和金卡 (Gold)三个等级。非会员 (NonMember)可以申请成为普卡会员。会员的等级根据其 一年内累积的里程数进行调整。描述会员等级调整的状态图如图 6-1 所示 。现采用状态 (State) 模式实现上述场景,得到如图 6-2 所示的类图。

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

考题 阅读下列说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 某大型购物中心欲开发一套收银软件,要求其能够支持购物中心在不同时期推出的各 种促销活动,如打折、返利(例如,满300返100)等等。现采用策略(Strategy)模式实现该要求,得到如图5-1所示的类图。 图5-1 策略模式类图 【C++代码】 #include using namespace std; enum TYPE{NORMAL, CASH_DISCOUNT, CASH_RETURN}; class CashSuper{ public: (1); }; class CashNormal : public CashSuper { //正常收费子类 public: double acceptCash(double money) { retum money; } }; class CashDiscount : public CashSuper { private: double moneyDiscount; // 折扣率 public: CashDiscount(double discount) { moneyDiscount= discount; } double acceptCash(double money) { retum money * moneyDiscount; } }; class CashRetum : public CashSuper { // 满额返利 private: double moneyCondition; // 满额数额 double moneyReturn; // 返利数额 public: CashRetnm(double motieyCondition, double moneyReturn) { this->moneyCondition=moneyCondition; this->moneyReturn=moneyRetum; } double acceptCash(double money) { double result = money; if(money>=moneyCondition) result=money-(int)(money/moneyCondition ) * moneyRetum; return result ; } }; class CashContext { private: CashSuper *cs; public: CashContext(int type) { switch(type) { case NORMAL: //正常收费 (2) ; break; case CASH_RETURN: //满300返100 (3) ; break; case CASH_DISCOUNT: //打八折 (4) ; break; } } double GetResult(double money) { (5) ; } }; //此处略去main( )函数

考题 阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 6-1 所示为其类图。 阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 ???? 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。 ? 【C++代码】 #include #include using namespace std; class Product { private:? string partA, partB; public:? Product() {?? }? ? void setPartA(const string} ???? void setPartB(const string}? ? //? 其余代码省略 }; class Builder { public:? ? ?? (1)?? ;? virtual void buildPartB()=0;? ? ? (2)?? ; }; class ConcreteBuilder1 : public Builder { private:? Product*?? product; public: ConcreteBuilder1() {product = new Product();???? } void buildPartA() {????? (3)???? ("Component A"); }? void buildPartB() {????? (4)???? ("Component B"); }?? Product* getResult() { return product; } //? 其余代码省略 }; class ConcreteBuilder2 : public Builder {? ??? ? ? ? /*??? 代码省略??? */ }; class Director { private:? ?? Builder* builder; public:?? Director(Builder* pBuilder) { builder= pBuilder;}? ?? void construct() { ????????????????? (5)???? ; ?????????????? //? 其余代码省略? ? }?? //? 其余代码省略 }; int main() {? ? ?? Director* director1 = new Director(new ConcreteBuilder1());? ? director1->construct();? ? ?? delete director1;? ? ? return 0; 【Java代码】 import jav(6)A.util.*; class Product {? ? ? ? private String partA;? ? ? ? private String partB;? ? ? ?? public Product() {}? ? ?? public void setPartA(String s) { partA = s; }? ? ? ? public void setPartB(String s) { partB = s; } } interface Builder {? ? public?????? (1)???? ;? ?? public void buildPartB();? ? ?? public?????? (2)???? ; } class ConcreteBuilder1 implements Builder {? ? ? ? private Product product;? ? ? ? public ConcreteBuilder1() { product = new Product();?? }? ? ? ?? public void buildPartA() {???????? (3)?? ("Component A"); } public void buildPartB() {???? ????(4)?? ("Component B"); }? ? ?? public Product getResult() { return product;} } class ConcreteBuilder2 implements Builder {?? ? ? ? ? //? 代码省略 } class Director {? ? ? ? private Builder builder;? ? ? ? public Director(Builder builder) {this.builder = builder; } public void construct() { ? ? ? ? ? ? ? ? ? (5)???? ; ? ? ? ? ? ? ? //? 代码省略? ? ?? } } class Test {? ? ?? public static void main(String[] args) { ???????????????? Director director1 = new Director(new ConcreteBuilder1()); ???????????????? director1.construct();? ? ? ?? }

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。