1、C+课程设计自助点餐系统面向对象程序课程设计(2014/2015学年第一学期第20周)指导教师: 庄巧莉、杨东鹤班级:计算机科学与技术13(1)学号:姓名:面向对象程序课程设计一、题目二、需求分析三、系统结构图四、类的设计五、程序代码与说明六、运行结果与分析七、心得与体会一:题目 自助点餐系统二:需求分析有一个小型餐厅,该餐厅提供即时就餐和外卖服务。现在这个餐厅打算使用自助点餐系统,让顾客自己点餐,实现以下功能。1、根据顾客的选择正确打出账单2、正确统计出每一天的及时就餐和外卖的销售情况3、实现对餐厅菜式和价格的有效管理4、考虑点餐的自动排序问题,使顾客可以实时查询到自己菜单处理情况三:系统结
2、构图四:类的设计Client类:客户类,包含客户属性姓名,电话号码,费用等信息,登记客户,记录客户订单信息ClientManager类:客户管理类,用于管理客户,记录客户数量,存储客户菜单信息,查询客户订单信息,统计订单FeeManager类:用于记录就餐、外卖的销售费用,统计收入Food类:餐厅食物的类,包含食物名称和价格FoodManager类:管理菜单,用于添加食物,修改食物,删除食物,记录不同食物的信息,呈现菜单MenuView类:用于打印各种操作界面五:程序代码与说明Client.h#ifndef CLIENT#define CLIENT#includeFoodManager.h#i
3、ncludeusing namespace std;class Clientprivate: int number; /客户编号 int type; /客户的类型,1表示就餐,2表示外卖 double fee; /客户账单费用 char *name; /客户名称 char *phone; /客户手机号码public: Client() /构造函数 char * getName(); /返回客户姓名 int num100; /numi存储食物数量,i表示食物编号 FoodManager client_fm; /管理客户所点的食物 Client(char *n,char *p);/构造函数 int
4、 getNumber(); /返回客户编号 void setNumber(int n); /设置客户编号 int getType(); /返回客户类型 void setType(int n); /设置客户类型 void addFee(double x); /添加费用 double getFee(); /返回费用 void showClientMessage();/展示客户信息 void changNum(); /修改客户所点的食物的数量 void deleFood(); /删除客户所选择的食物;#endifClient.cpp#includeClient.h#includeClient:Cli
5、ent(char *s,char *p) name = s; phone = p; fee = 0; for(int i = 0 ; i 100 ; i+) numi = 0 ; cout客户注册成功endl;int Client:getNumber() return number;void Client:setNumber(int n) number = n;int Client:getType() return type;void Client:setType(int n) type = n;void Client:addFee(double x) fee += x;double Clie
6、nt:getFee() return fee;void Client:showClientMessage() char * ss; if(type = 1)ss = 就餐; else if(type = 2)ss = 外卖; cout姓名: namettssendl; cout手机号码: phoneendl; cout订单总价: feeendl; cout订单详情:endl; coutsetw(10)setiosflags(ios:left)食物序列setw(10)setiosflags(ios:left)菜名t数量t价格endl; for(int i = 0 ; i client_fm.ge
7、tTotal() ; i +) coutsetw(10)setiosflags(ios:left)setw(10)i+1setiosflags(ios:left)client_fm.foodi.getName()tnumitnumi*client_fm.foodi.getPrice()endl; cout总价:ttfeeendl;char * Client:getName() return name;void Client:changNum() int n; int numss; coutn; cout您选择了食物: client_fm.getNameByList(n-1)endl; cout
8、numss; fee += (numss - numn-1 )*client_fm.getPriceByName(client_fm.getNameByList(n-1); numn-1=numss;void Client:deleFood() int n; coutn; cout您选择了食物: client_fm.getNameByList(n-1)endl; fee -= (numn-1 )*client_fm.getPriceByName(client_fm.getNameByList(n-1); for(int i = n-1 ; i client_fm.getTotal() ; i
9、+) client_fm.foodi=client_fm.foodi+1; numi=numi+1; client_fm.setTotal(client_fm.getTotal()-1);ClientManager.h#ifndef CLIENTMANAGER#define CLIENTMANAGER#includeClient.h#includeusing namespace std;#define MAX_CLIENT_NUM 60 /最大客户数量class ClientManagerpublic: ClientManager(); /构造函数 int clientNum ; /记录客户数
10、量 Client clientMAX_CLIENT_NUM; /记录存储客户 void addClient(Client c); /添加新客户 int getClientNum(); /返回客户数量 void showQuery(char * s); /查询客户 void showAll(); /显示所有客户;#endifClientManager.cpp#includeClientManager.hClientManager:ClientManager() clientNum = 0;void ClientManager:addClient(Client c) clientclientNum
11、+ = c; cout客户注册成功endl;int ClientManager:getClientNum() return clientNum;void ClientManager:showQuery(char * s) int count = 0; int th; cout-endl; for(int i = 0; i clientNum ; i +) if(clienti.getType()=1) cout第+count单: clienti.getName()t总价是: clienti.getFee()元t就餐endlendl; if(strcmp(clienti.getName(),s)
12、=0)th =count; for(int i = 0; i clientNum ; i +) if(clienti.getType()=2) cout第+count单: clienti.getName()t总价是: clienti.getFee()元t外卖endlendl; if(strcmp(clienti.getName(),s)=0)th =count; cout您当前排在第th单endl; cout-endl;void ClientManager:showAll() for(int i = 0 ; i clientNum ; i + ) if(clienti.getType()=1)
13、 cout订单号: i+1endl; clienti.showClientMessage(); coutendl; for(int i = 0 ; i clientNum ; i + ) if(clienti.getType()=2) cout订单号: i+1endl; clienti.showClientMessage(); coutendl; Food.h#ifndef FOOD#define FOODclass Food private: char *name; /食物名称 double price; /食物价格 public: Food(); /构造函数 Food(char *s,do
14、uble p); /构造函数 void setName(char *s); /更改食物名称 char* getName(); /返回食物名称 double getPrice(); /返回食物价格 void setPrice(double p); /设置食物价格 void showMessage(); /显示食物的名称和价格;#endifFood.cpp#includeFood.h#includeusing namespace std;Food:Food(char *s,double p) name = s; price = p;void Food:setName(char *s) name =
15、 s;void Food:setPrice(double p) price = p;void Food:showMessage() coutnametprice?endl;double Food:getPrice() return price;char* Food:getName() return name;FoodManager.h#ifndef FOODMANAGER#define FOODMANAGER#includeFood.h#define MAX_FOOD_NUM 99 /最多容纳的食物种类数class FoodManager int total ; /食物种类数 public:
16、FoodManager(); /构造函数 int getTotal() ; /返回食物种类数 Food foodMAX_FOOD_NUM; /记录食物 void addFood(Food f); /添加食物 void addFood(char *s,double p); /添加食物 void deleteFood(); /删除食物 void changePrice(); /修改食物价格 void showFood(); /显示食物信息 char * getNameByList(int list); /通过食物编号返回食物名称 double getPriceByName(char *s); /通
17、过食物名称返回食物价格 int getListByName(char *s); /通过食物名称返回食物编号 void setTotal(int x); /修改食物种类数;#endifFoodManager.cpp#includeFoodManager.h#includeusing namespace std;#includeFoodManager:FoodManager() total = 0;void FoodManager:addFood(Food f) foodtotal+=f; cout成功添加了食物,当前共有totalendl;void FoodManager:showFood()
18、cout食物中共有total种endl; cout食物编号 名称tt单价endl; for(int i = 0 ; i total ; i + ) coutsetw(10)setiosflags(ios:left)isetw(10)setiosflags(ios:left)foodi.getName()tfoodi.getPrice()endl;void FoodManager:changePrice() char *s; int code; s = new char20; double p; coutcode; s = foodcode.getName(); cout您选择了食物: send
19、l; coutp; for(int i = 0; i total ; i +) if(strcmp(foodi.getName(),s)=0) foodi.setPrice(p); cout修改成功endl; return; cout没有这种食物,修改失败endl;void FoodManager:deleteFood() char *s; s = new char20; couts; for(int i = 0 ; i total ; i +) if(strcmp(foodi.getName(),s)=0) cout成功删除sendl; total -; for(int t = i; t t
20、otal ; t +) foodt=foodt+1; return; cout没有这种食物endl;void FoodManager:addFood(char *s , double p) foodtotal+=Food(s,p);double FoodManager:getPriceByName(char *s) for(int i = 0 ; i total ; i +) if(strcmp(foodi.getName(),s)=0) return foodi.getPrice(); return false;int FoodManager:getListByName(char *s) f
21、or(int i = 0 ; i total ; i +) if(strcmp(foodi.getName(),s)=0) return i; return false;int FoodManager:getTotal() return total;char * FoodManager:getNameByList(int list) return foodlist.getName();void FoodManager:setTotal(int x) total = x;FeeManager.h#ifndef FEEMANAGER#define FEEMANAGERclass FeeManage
22、rprivate: double jiuCanFee; /就餐总收入 double waiMaiFee; /外卖总收入public: FeeManager(); /构造函数 double getWaiMaiFee(); /返回外卖总收入 double getJiuCanFee(); /返回就餐总收入 void addWaiMaiFee(double x); /增加外卖总收入 void addJiuCanFee(double x); /添加就餐总收入;#endifFeeManager.cpp#includeFeeManager.hFeeManager:FeeManager() jiuCanFee
23、 = 0; waiMaiFee = 0;double FeeManager:getWaiMaiFee() return waiMaiFee;double FeeManager:getJiuCanFee() return jiuCanFee;void FeeManager:addWaiMaiFee(double x) waiMaiFee += x;void FeeManager:addJiuCanFee(double x) jiuCanFee += x;MenuView.h#ifndef MENUVIEW#define MENUVIEWclass MenuView private: char w
24、hiteSmile; /白色笑脸 char blackSmile; /黑色笑脸 char heart; /心形图形 public: MenuView(); /构造函数 void showJiuCan(); /显示就餐用户点菜界面 void showWaiMai(); /显示外卖用户点菜界面 int showMain(); /显示用户选择就餐还是外卖界面 int showViewChoice(); /显示进入本系统的功能选择界面 int showRegister(); /显示客户注册界面 int showClientChoice(); /显示客户点餐界面 int showQuery(); /显示
25、查询客户订单界面 int showMend(); /显示修改食物界面 int showMenuChoice(); /显示选择菜单界面 int showMendDingDan(); /显示客户修改订单界面;#endifMenuView.cpp#includeMenuView.h#includeusing namespace std;MenuView:MenuView() whiteSmile = 1; blackSmile = 2; heart = 3;int MenuView:showMain() for(int i = 1 ; i = 80 ; i+ )coutheart; for(int i = 1;i=80;i+)if(i=1|i=80)coutheart;else cout ; couthearttttt欢迎光临本餐厅; for(int j=1;j=33;j+)cout ;coutheart; for(int i = 1;i=80;i+)if(i=1|i=80)coutheart;else cout ; for(int i = 1 ; i = 80 ; i+ )coutheart; /输出餐厅的外形 coutendlendl; coutt我是服务员小坠whiteSmile,竭诚为您服务哦bla
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1