题目详情

某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(Waiter)调度厨师制作套餐。现采用生成器(Builder)模式实现制作过程,得到如图5-1所示的类图。

中级软件设计师,历年真题,2017年上半年(下午)《软件设计师》真题

图5-1类图

【C++代码】

#include<iostream>

#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+ham&pineapple");}

};

class SpicyPizzaBuider:public PizzaBuilder{

public:

void buildParts(  ){pizza->setParts("pan baked+hot+ham&pineapple");}

}

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+ham&pineapple

正确答案及解析

正确答案
解析

(1)virtual void buildParts()=0

(2)this->pizzaBuilder=pizzaBuilder

(3)pizzaBuilder->buildParts()

(4)waiter->setPizzaBuilder(hawaiian_pizzabuilder)

(5)waiter->construct()

1.从类图中可以看到这个buildparts函数缺失,又子类中也有buildParts,所以它是虚函数,在扩展类中定义使用。

2.这部分填写设置构建器内容,在waiter类里面,定义pizzaBuilder。

3.从类图知道,构建方法应该是buildParts,当前对象是pizzaBuilder。

4.前面定义了对象waiter,新建hawaiian_pizzabuilder类,调用waiter的set方法。

5.调用waiter类中的construct方法,这样可以得到。

包含此试题的试卷

你可能感兴趣的试题

单选题

Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.

  • A.Artificial Intelligence
  • B.Cloud Computing
  • C.Internet of Things
  • D.Big Data
查看答案
单选题

In project human resource management , ( )is not a source of power for the project manager.

  • A.referent power
  • B.expert power
  • C.reward power
  • D.audit power
查看答案
单选题

At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.

  • A.detail feasibility analysis
  • B.opportunity analysis
  • C.economic feasibility analysis
  • D.risk analysis
查看答案
单选题

( )is a grid that shows the project resources assigned to each work package.

  • A.Stakeholder engagement assessment matrix
  • B.Requirements traceability matrix
  • C.Probability and impact matrix
  • D.Responsibility assignment matrix
查看答案
单选题

Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.

  • A.digital
  • B.networking
  • C.intelligentize
  • D.informatization
查看答案

相关题库更多 +