軟件設(shè)計師案例分析當天每日一練試題地址:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4
往期軟件設(shè)計師每日一練試題匯總:m.xiexiliangjiufa.com/class/27/e4_1.html
軟件設(shè)計師案例分析每日一練試題(2025/2/23)在線測試:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4&day=2025/2/23
點擊查看:更多軟件設(shè)計師習(xí)題與指導(dǎo)
軟件設(shè)計師案例分析每日一練試題內(nèi)容(2025/2/23)
試題五
閱讀下列說明和C++代碼,將應(yīng)填入 (n) 處的字句寫在對應(yīng)欄內(nèi)。
[說明]
某飯店在不同的時段提供多種不同的餐飲,其菜單的結(jié)構(gòu)圖如圖5-1所示。
現(xiàn)在采用組合(Composition)模式來構(gòu)造該飯店的菜單,使得飯店可以方便地在其中增加新的餐飲形式,得到如圖5-2所示的類圖。其中MenuComponent為抽象類,定義了添加(add)新菜單和打印飯店所有菜單信息(print)的方法接口。類Menu表示飯店提供的每種餐飲形式的菜單,如煎餅屋菜單、咖啡屋菜單等。每種菜單中都可以添加子菜單,例如圖5-1中的甜點菜單。類MenuItem表示菜單中的菜式。
[C++代碼]
#include<iostream>
#include<list>
#include<string>
using namespace std;
clas s MenuComponent {
protected: string name;
public:
MenuComponent(string name) {this->name=name; }
String getName19{return name;}
(1) : //添加新菜單
virtual void print19=0; //打印菜單信息
};
clasS MenuItem: public MenuComponent {
private: double price;
public:
Menultem(string name, double price): MenuComponent(name){this->price=price;}
double getPrice19{return price;}
void add(MenuComponent* menuComponent) {return; } //添加新菜單
void print19 { cout<<" "<<getName19<<", "<<getPrice19<<end1;}
};
clasS Menu: public MenuComponent {
private: list< (2) > menuComponents;
pubiic:
Menu(string name): MenuC0mponent(name){}
void add(MenuComponent* menuComponent) //添加新菜單
{ (3) ; }
void print19{
cout<<"\n"<<getName19<<"\n-------------------------"<<end1;
std::list<MenuC0mponent*>::iterator iter;
for(iter=menuComponents.begin19; iter!=menuComponents. end19; iter++)
(4) ->print19;
}
};
void main19{
MenuComponent* allMenus=new Menu("ALL MENUS");
MenuComponent* dinerMenu=new Menu("DINER MENU");
…//創(chuàng)建更多的Menu對象,此處代碼省略
allMenus->add(dinerMenu); //將dinerMenu添加到餐廳菜單中
…//為餐廳增加更多的菜單,此處代碼省略
(5) ->print19; //打印飯店所有菜單的信息
}
信管網(wǎng)考友試題答案分享:
信管網(wǎng)試題答案與解析:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4&day=2025/2/23信管網(wǎng)訂閱號
信管網(wǎng)視頻號
信管網(wǎng)抖音號
溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請以權(quán)威部門公布的內(nèi)容為準!
信管網(wǎng)致力于為廣大信管從業(yè)人員、愛好者、大學(xué)生提供專業(yè)、高質(zhì)量的課程和服務(wù),解決其考試證書、技能提升和就業(yè)的需求。
信管網(wǎng)軟考課程由信管網(wǎng)依托10年專業(yè)軟考教研傾力打造,教材和資料參編作者和資深講師坐鎮(zhèn),通過深研歷年考試出題規(guī)律與考試大綱,深挖核心知識與高頻考點,為學(xué)員考試保駕護航。面授、直播&錄播,多種班型靈活學(xué)習(xí),滿足不同學(xué)員考證需求,降低課程學(xué)習(xí)難度,使學(xué)習(xí)效果事半功倍。
發(fā)表評論 查看完整評論 | |