导航
您当前的位置:首页 > 计算机 > 软件水平
问题:

[问答题] 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(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
答案解析:

相关问题
关于我们 | 用户指南 | 版权声明 | 给我留言 | 联系我们 | 积分商城 | 答案求助 | 网站地图
Copyright © 2024 www.daanwo.com All Rights Reserved