軟件設計師案例分析當天每日一練試題地址:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4
往期軟件設計師每日一練試題匯總:m.xiexiliangjiufa.com/class/27/e4_1.html
軟件設計師案例分析每日一練試題(2022/1/31)在線測試:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4&day=2022/1/31
點擊查看:更多軟件設計師習題與指導
軟件設計師案例分析每日一練試題內容(2022/1/31)
[試題5]
閱讀下列說明和C++代碼,回答下列問題。
[說明]
某咖啡店賣咖啡時,可以根據(jù)顧客的要求在其中加入各種配料,咖啡店會根據(jù)所加入的配料來計算費用??Х鹊晁目Х燃芭淞系姆N類和價格如表2-8所示。
表2-8 咖啡及配料的種類和價格
咖啡 | 價格/杯(¥) |
| 配料 | 價格/份(¥) |
蒸餾咖啡(Espresso) | 25 |
| 摩卡(Mocha) | 10 |
深度烘焙咖啡(DarkRoast) | 20 |
| 奶泡(Whip) | 8 |
[C++代碼]
#include <iostream>
#include <string>
using namespace std;
consr int ESPRESSO_PRICE = 25;
const int DRAKROAST_PRICE = 20;
const int MOCHA_PRICE = 10;
const int WHIP_PRICE = 8;
classBeverage { //飲料
______: string description;
public: ______() {return description;}
______;};
class CondimentDecorator: public Beverage { //配料
protected: ______;};
classEspresso: 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(______) ;
beverage=new Whip (______) ;
cout<<beverage->getDescription()<<"¥"<<beverage->cost()end1;
return 0;
}
編譯運行上述程序,其輸出結果為:DarkRoast,Mocha,Whip ¥38。
信管網(wǎng)試題答案與解析:m.xiexiliangjiufa.com/st/2479421060.html信管網(wǎng)考友試題答案分享:
信管網(wǎng)試題答案與解析:m.xiexiliangjiufa.com/st/2479421060.html
溫馨提示:因考試政策、內容不斷變化與調整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請以權威部門公布的內容為準!
信管網(wǎng)致力于為廣大信管從業(yè)人員、愛好者、大學生提供專業(yè)、高質量的課程和服務,解決其考試證書、技能提升和就業(yè)的需求。
信管網(wǎng)軟考課程由信管網(wǎng)依托10年專業(yè)軟考教研傾力打造,官方教材參編作者和資深講師坐鎮(zhèn),通過深研歷年考試出題規(guī)律與考試大綱,深挖核心知識與高頻考點,為學員考試保駕護航。面授、直播&錄播,多種班型靈活學習,滿足不同學員考證需求,降低課程學習難度,使學習效果事半功倍。
發(fā)表評論 查看完整評論 | |