试题五(共15分)阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。【C++代码】include iostreaminclude stringusing namespace std;const int ESPRESSO_PRICE = 25;const int DRAKROAST_PRICE = 20;const int MOCHA_PRICE = 10;const int WHIP_PRICE = 8;class Beverage { //饮料(1) :string description;public:(2) (){ return description; }(3) ;};class CondimentDecorator : public Beverage { //配料protected:(4) ;};class Espresso : public Beverage { //蒸馏咖啡public:Espresso () {description="Espresso"; }int cost(){return ESPRESSO_PRICE; }};class DarkRoast : public Beverage { //深度烘焙咖啡public:DarkRoast(){ description = "DardRoast"; }int cost(){ return DRAKROAST_PRICE; }};class Mocha : public CondimentDecorator { //摩卡public:Mocha(Beverage*beverage){ this-beverage=beverage; }string getDescription(){ return beverage-getDescription()+",Mocha"; }int cost(){ return MOCHA_PRICE+beverage-cost(); }};class Whip :public CondimentDecorator { //奶泡public:Whip(Beverage*beverage) { this-beverage=beverage; }string getDescription() {return beverage-getDescription()+",Whip"; }int cost() { return WHIP_PRICE+beverage-cost(); }};int main() {Beverage* beverage = new DarkRoast();beverage=new Mocha( (5) );beverage=new Whip( (6) );coutbeverage-getDescription()"¥"beverage-cost() endl;return 0;}编译运行上述程序,其输出结果为:DarkRoast, Mocha, Whip ¥38
试题五(共15分)
阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。
【C++代码】
include <iostream>
include <string>
using namespace std;
const int ESPRESSO_PRICE = 25;
const int DRAKROAST_PRICE = 20;
const int MOCHA_PRICE = 10;
const int WHIP_PRICE = 8;
class Beverage { //饮料
(1) :string description;
public:
(2) (){ return description; }
(3) ;
};
class CondimentDecorator : public Beverage { //配料
protected:
(4) ;
};
class Espresso : public Beverage { //蒸馏咖啡
public:
Espresso () {description="Espresso"; }
int cost(){return ESPRESSO_PRICE; }
};
class DarkRoast : public Beverage { //深度烘焙咖啡
public:
DarkRoast(){ description = "DardRoast"; }
int cost(){ return DRAKROAST_PRICE; }
};
class Mocha : public CondimentDecorator { //摩卡
public:
Mocha(Beverage*beverage){ this->beverage=beverage; }
string getDescription(){ return beverage->getDescription()+",Mocha"; }
int cost(){ return MOCHA_PRICE+beverage->cost(); }
};
class Whip :public CondimentDecorator { //奶泡
public:
Whip(Beverage*beverage) { this->beverage=beverage; }
string getDescription() {return beverage->getDescription()+",Whip"; }
int cost() { return WHIP_PRICE+beverage->cost(); }
};
int main() {
Beverage* beverage = new DarkRoast();
beverage=new Mocha( (5) );
beverage=new Whip( (6) );
cout<<beverage->getDescription()<<"¥"<<beverage->cost() endl;
return 0;
}
编译运行上述程序,其输出结果为:
DarkRoast, Mocha, Whip ¥38