1、word完整版)C++课程设计自助点餐系统 面向对象程序课程设计 (2014/2015学年第一学期第20周) 指导教师: 庄巧莉、杨东鹤 班级:计算机科学与技术13(1) 学号:你好你好你 姓名:你好你啊哈啊啊啊 面向对象程序课程设计 目 录 一、 题目 二、 需求分析 三、 系统结构图 四、 类的设计 五、 程序代码与说明 六、 运行结果与分析 七、 心得与体会 一:题目 自助点餐系统 二:需求分析 有一个小型餐厅,该餐厅提供即时就餐和外卖服务。现在这个餐厅打算使用自助点
2、餐系统,让顾客自己点餐,实现以下功能。 1、根据顾客的选择正确打出账单 2、正确统计出每一天的及时就餐和外卖的销售情况 3、实现对餐厅菜式和价格的有效管理 4、考虑点餐的自动排序问题,使顾客可以实时查询到自己菜单处理情况 三:系统结构图 四:类的设计 Client类:客户类,包含客户属性姓名,电话号码,费用等信息,登记客户,记录客户订单信息 ClientManager类:客户管理类,用于管理客户,记录客户数量,存储客户菜单信息,查询客户订单信息,统计订单 FeeManager类:用于记录就餐、外卖的销售费用,统计收入 Food类:餐厅食物的类,包含食物名称和价格 Fo
3、odManager类:管理菜单,用于添加食物,修改食物,删除食物,记录不同食物的信息,呈现菜单
MenuView类:用于打印各种操作界面
五:程序代码与说明
Client.h
#ifndef CLIENT
#define CLIENT
#include"FoodManager。h”
#include
4、单费用 char *name; //客户名称 char *phone; //客户手机号码 public: Client(){} //构造函数 char * getName(); //返回客户姓名 int num[100]; //num[i]存储食物数量,i表示食物编号 FoodManager client_fm; //管理客户所点的食物 Client(char *n,char *p);//构造函数 int getNumber(); //返回客户编号 void setNumber(int n); //设置客户编号 int g
5、etType(); //返回客户类型
void setType(int n); //设置客户类型
void addFee(double x); //添加费用
double getFee(); //返回费用
void showClientMessage();//展示客户信息
void changNum(); //修改客户所点的食物的数量
void deleFood(); //删除客户所选择的食物
};
#endif
Client.cpp
#include"Client.h"
#include
6、har *s,char *p) { name = s; phone = p; fee = 0; for(int i = 0 ; i 〈 100 ; i++) num[i] = 0 ; cout<<"客户注册成功”<〈endl; } int Client::getNumber() { return number; } void Client::setNumber(int n) { number = n; } int Client::getType() { return type; } void Client::setType(int
7、n)
{
type = n;
}
void Client::addFee(double x)
{
fee += x;
}
double Client::getFee()
{
return fee;
}
void Client::showClientMessage()
{
char * ss;
if(type == 1)ss = ”就餐";
else if(type == 2)ss = ”外卖";
cout〈<”姓名: ”〈〈name〈<”\t\t"< 8、<"订单总价: ”< 9、food[i].getName()<<”\t”< 10、
cout<<"请输入数量: ”;cin〉〉numss;
fee += (numss - num[n—1] )*client_fm。getPriceByName(client_fm.getNameByList(n—1));
num[n-1]=numss;
}
void Client::deleFood()
{
int n;
cout<〈"请输入食物序号: ";cin>〉n;
cout〈〈”您选择了食物: ”〈 11、ame(client_fm。getNameByList(n—1));
for(int i = n—1 ; i 〈 client_fm。getTotal() ; i ++)
{
client_fm。food[i]=client_fm。food[i+1];
num[i]=num[i+1];
}
client_fm.setTotal(client_fm。getTotal()-1);
}
ClientManager.h
#ifndef CLIENTMANAGER
#define CLIENTMANAGER
#include"Client.h"
#inclu 12、de〈iostream〉
using namespace std;
#define MAX_CLIENT_NUM 60 //最大客户数量
class ClientManager
{
public:
ClientManager(); //构造函数
int clientNum ; //记录客户数量
Client client[MAX_CLIENT_NUM]; //记录存储客户
void addClient(Client c); //添加新客户
int getClientNum(); //返回客户数量
void showQu 13、ery(char * s); //查询客户
void showAll(); //显示所有客户
};
#endif
ClientManager.cpp
#include"ClientManager.h"
ClientManager::ClientManager()
{
clientNum = 0;
}
void ClientManager::addClient(Client c)
{
client[clientNum++] = c;
cout〈<”客户注册成功"〈〈endl;
}
int ClientManager::getClientNum()
14、
{
return clientNum;
}
void ClientManager::showQuery(char * s)
{
int count = 0;
int th;
cout<〈”—-—--—---—--————-———————--——-—----"〈〈endl;
for(int i = 0; i 〈 clientNum ; i ++)
if(client[i]。getType()==1)
{
cout<<"第”<〈++count〈<"单: "〈〈client[i].getName()〈<"\t总价是: ”〈 15、tFee()〈〈"元"〈〈"\t就餐”〈〈endl<〈endl;
if(strcmp(client[i]。getName(),s)==0)th =count;
}
for(int i = 0; i < clientNum ; i ++)
if(client[i]。getType()==2)
{
cout<〈”第”<<++count<〈"单: "<〈client[i].getName()〈〈”\t总价是: ”〈〈client[i].getFee()〈<”元”<<"\t外卖”〈〈endl< 16、i]。getName(),s)==0)th =count;
}
cout〈<"您当前排在第"〈 17、e();
cout< 18、le price; //食物价格
public:
Food(){}; //构造函数
Food(char *s,double p); //构造函数
void setName(char *s); //更改食物名称
char* getName(); //返回食物名称
double getPrice(); //返回食物价格
void setPrice(double p); //设置食物价格
void showMessage(); //显示食物的名称和价格
};
#endif
Food.cpp
#include”Foo 19、d.h”
#include 20、
{
return price;
}
char* Food::getName()
{
return name;
}
FoodManager.h
#ifndef FOODMANAGER
#define FOODMANAGER
#include"Food.h”
#define MAX_FOOD_NUM 99 //最多容纳的食物种类数
class FoodManager
{
int total ; //食物种类数
public:
FoodManager(); //构造函数
int getTotal() ; // 21、返回食物种类数
Food food[MAX_FOOD_NUM]; //记录食物
void addFood(Food f); //添加食物
void addFood(char *s,double p); //添加食物
void deleteFood(); //删除食物
void changePrice(); //修改食物价格
void showFood(); //显示食物信息
char * getNameByList(int list); //通过食物编号返回食物名称
double getPriceByName 22、char *s); //通过食物名称返回食物价格
int getListByName(char *s); //通过食物名称返回食物编号
void setTotal(int x); //修改食物种类数
};
#endif
FoodManager。cpp
#include"FoodManager。h”
#include〈iostream〉
using namespace std;
#include〈iomanip>
FoodManager::FoodManager()
{
total = 0;
}
void FoodManager::addFoo 23、d(Food f)
{
food[total++]=f;
cout<<"成功添加了食物,当前共有"〈 24、d[i].getName()<〈"\t"〈〈food[i]。getPrice()< 25、
if(strcmp(food[i].getName(),s)==0)
{
food[i]。setPrice(p);
cout<<"修改成功"〈〈endl;
return;
}
cout<<”没有这种食物,修改失败”〈〈endl;
}
void FoodManager::deleteFood()
{
char *s;
s = new char[20];
cout〈<”请输入菜名: ”;
cin〉>s;
for(int i = 0 ; i 〈 total ; i ++)
if(strcmp(food[i]。getName 26、s)==0)
{
cout〈<”成功删除”〈 27、0 ; i 〈 total ; i ++)
if(strcmp(food[i].getName(),s)==0)
return food[i].getPrice();
return false;
}
int FoodManager::getListByName(char *s)
{
for(int i = 0 ; i 〈 total ; i ++)
if(strcmp(food[i]。getName(),s)==0)
return i;
return false;
}
int FoodManager::getTotal()
{
ret 28、urn total;
}
char * FoodManager::getNameByList(int list)
{
return food[list]。getName();
}
void FoodManager::setTotal(int x)
{
total = x;
}
FeeManager.h
#ifndef FEEMANAGER
#define FEEMANAGER
class FeeManager
{
private:
double jiuCanFee; //就餐总收入
double waiMaiFee; 29、 //外卖总收入
public:
FeeManager(); //构造函数
double getWaiMaiFee(); //返回外卖总收入
double getJiuCanFee(); //返回就餐总收入
void addWaiMaiFee(double x); //增加外卖总收入
void addJiuCanFee(double x); //添加就餐总收入
};
#endif
FeeManager.cpp
#include”FeeManager。h"
FeeManager::FeeManager()
{
jiuCanFee 30、 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 ME 31、NUVIEW
#define MENUVIEW
class MenuView
{
private:
char whiteSmile; //白色笑脸
char blackSmile; //黑色笑脸
char heart; //心形图形
public:
MenuView(); //构造函数
void showJiuCan(); //显示就餐用户点菜界面
void showWaiMai(); //显示外卖用户点菜界面
int showMain(); //显示用户选择就餐还是外卖界面
int sho 32、wViewChoice(); //显示进入本系统的功能选择界面
int showRegister(); //显示客户注册界面
int showClientChoice(); //显示客户点餐界面
int showQuery(); //显示查询客户订单界面
int showMend(); //显示修改食物界面
int showMenuChoice(); //显示选择菜单界面
int showMendDingDan(); //显示客户修改订单界面
};
#endif
MenuView.cpp
#include"MenuView.h" 33、
#include 34、
for(int j=1;j〈=33;j++)cout<〈' ’;cout<〈heart;
for(int i = 1;i<=80;i++){if(i==1||i==80)cout〈 35、〈’ ’;
for(int i = 1 ; i 〈= 20 ; i++ )cout< 36、1 ; i 〈= 52 ; i ++ )cout<〈’ ';cout< 37、t<〈endl;
cout〈〈"\t\t\t您的选择是:”;
int choice;
cin〉〉choice;
return choice;
}
void MenuView::showJiuCan()
{
cout<<"欢迎就餐,本餐厅有以下食品供您品尝”〈 38、rt;else cout<〈’ ';}
cout〈 39、 |”〈 40、————-——————---——-"<〈endl;
cout〈<”| 1:新顾客点餐 |"<〈endl;
cout〈<"| 2:查询订单 |"〈〈endl;
cout〈<”—-—-——-—--——-—-—-—-----—"< 41、ndl;
cout<<"| 2:修改订单 |”<〈endl;
cout〈<"| 3:提交订单 |”〈 42、 |"〈 43、食物管理 |"< 44、——-——-—-——-—--—”<〈endl;
int next;
cin〉>next;
return next;
}
int MenuView::showMendDingDan()
{
cout〈<"----—-—-—--————-———-———-”<〈endl;
cout<〈"| 1:修改数量 |”〈 45、
int next;
cin>〉next;
return next;
}
Main。cpp
#include〈iostream>
#include"Food。h”
#include"MenuView。h"
#include"FoodManager.h"
#include"ClientManager.h"
#include”FeeManager。h"
#include 46、nuView mv; //管理界面
ClientManager cm; //管理客户的类的对象
FoodManager fm;//管理食物的类的对象
fstream ioFile; //文件输入输出
int clientChoice;// 1 服务顾客 2 食物管理 3 今日反馈 4退出系统
int clientService;//1新顾客点餐 2 查询
int mainChoice;// 1 就餐 2 外卖
int curClient; //当前操作的顾客编号
int queryChoice;//1 查询订单 2 退出查询
int foodCho 47、ice;//1 添加食物 2 修改食物价格 3删除某种食物 4退出食物管理
int viewChoice;//1 顾客服务 2 食物管理 3 今日反馈 4 退出系统
int menuChoice;//1 原菜单 2 更新后菜单
int mendDingDanChoice;//1 修改数量 2 删除食物 3 退出修改
ioFile。open("C:\\Users\\Administrator\\Desktop\\food.txt”,ios::in);
while(!ioFile。eof())
{
char *s;
double p;
s=new cha 48、r[20];
ioFile〉〉s〉>p;
fm。addFood(s,p);
}
ioFile.close();
//以上是从文件读入食物的种类和价格信息
while(true){
viewChoice = mv。showViewChoice();
if(viewChoice == 1) //顾客服务
{
clientService = mv。showRegister();
if(clientService == 1)//用户注册
{
char *name,*phone;
name = new char[30 49、];
phone = new char[20];
cout<<"请完善客户资料”< 50、
mainChoice = mv。showMain();
if(mainChoice == 1) //就餐
{
cm。client[curClient]。setType(1);
mv。showJiuCan();
while(true)
{
fm.showFood();
int choices;
choices = mv.showClientChoice();
if(choices==1)//选择食物种类和数量,下单
{
char