资源描述
(word完整版)C++课程设计自助点餐系统
面向对象程序课程设计
(2014/2015学年第一学期第20周)
指导教师: 庄巧莉、杨东鹤
班级:计算机科学与技术13(1)
学号:你好你好你
姓名:你好你啊哈啊啊啊
面向对象程序课程设计
目 录
一、 题目
二、 需求分析
三、 系统结构图
四、 类的设计
五、 程序代码与说明
六、 运行结果与分析
七、 心得与体会
一:题目
自助点餐系统
二:需求分析
有一个小型餐厅,该餐厅提供即时就餐和外卖服务。现在这个餐厅打算使用自助点餐系统,让顾客自己点餐,实现以下功能。
1、根据顾客的选择正确打出账单
2、正确统计出每一天的及时就餐和外卖的销售情况
3、实现对餐厅菜式和价格的有效管理
4、考虑点餐的自动排序问题,使顾客可以实时查询到自己菜单处理情况
三:系统结构图
四:类的设计
Client类:客户类,包含客户属性姓名,电话号码,费用等信息,登记客户,记录客户订单信息
ClientManager类:客户管理类,用于管理客户,记录客户数量,存储客户菜单信息,查询客户订单信息,统计订单
FeeManager类:用于记录就餐、外卖的销售费用,统计收入
Food类:餐厅食物的类,包含食物名称和价格
FoodManager类:管理菜单,用于添加食物,修改食物,删除食物,记录不同食物的信息,呈现菜单
MenuView类:用于打印各种操作界面
五:程序代码与说明
Client.h
#ifndef CLIENT
#define CLIENT
#include"FoodManager。h”
#include<iostream>
using namespace std;
class Client
{
private:
int number; //客户编号
int type; //客户的类型,1表示就餐,2表示外卖
double fee; //客户账单费用
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 getType(); //返回客户类型
void setType(int n); //设置客户类型
void addFee(double x); //添加费用
double getFee(); //返回费用
void showClientMessage();//展示客户信息
void changNum(); //修改客户所点的食物的数量
void deleFood(); //删除客户所选择的食物
};
#endif
Client.cpp
#include"Client.h"
#include<iomanip>
Client::Client(char *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 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"<<ss〈〈endl;
cout<〈”手机号码: "<〈phone<<endl;
cout〈<"订单总价: ”<<fee<〈endl;
cout<〈"订单详情:"〈〈endl;
cout〈〈setw(10)〈〈setiosflags(ios::left)〈<"食物序列"<<setw(10)<〈setiosflags(ios::left)<<”菜名"〈<"\t数量\t价格"<〈endl;
for(int i = 0 ; i < client_fm.getTotal() ; i ++)
{
cout<〈setw(10)<〈setiosflags(ios::left)〈〈setw(10)〈〈i+1〈<setiosflags(ios::left)<〈client_fm.food[i].getName()<<”\t”<<num[i]<〈"\t"〈〈num[i]*client_fm。food[i]。getPrice()<<endl;
}
cout<〈"总价:\t\t”<〈fee〈<endl;
}
char * Client::getName()
{
return name;
}
void Client::changNum()
{
int n;
int numss;
cout<〈"请输入食物序号: ”;cin>>n;
cout<〈"您选择了食物: "<〈client_fm.getNameByList(n—1)<<endl;
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〈〈”您选择了食物: ”〈<client_fm.getNameByList(n-1)<〈endl;
fee -= (num[n-1] )*client_fm。getPriceByName(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"
#include〈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 showQuery(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()
{
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总价是: ”〈<client[i]。getFee()〈〈"元"〈〈"\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<<endl;
if(strcmp(client[i]。getName(),s)==0)th =count;
}
cout〈<"您当前排在第"〈<th〈〈"单"<〈endl;
cout<〈”-—————--—--—-——----—-—-—---—-—-———"<〈endl;
}
void ClientManager::showAll()
{
for(int i = 0 ; i 〈 clientNum ; i ++ )
{
if(client[i]。getType()==1)
{
cout〈〈”订单号: ”<<i+1<<endl;
client[i]。showClientMessage();
cout<<endl;
}
}
for(int i = 0 ; i < clientNum ; i ++ )
{
if(client[i].getType()==2)
{
cout<〈”订单号: "〈〈i+1<〈endl;
client[i].showClientMessage();
cout〈<endl;
}
}
}
Food.h
#ifndef FOOD
#define FOOD
class Food
{
private:
char *name; //食物名称
double 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”Food.h”
#include<iostream〉
using namespace std;
Food::Food(char *s,double p)
{
name = s;
price = p;
}
void Food::setName(char *s)
{
name = s;
}
void Food::setPrice(double p)
{
price = p;
}
void Food::showMessage()
{
cout〈<name〈<”\t"<<price<<”。"〈〈endl;
}
double Food::getPrice()
{
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() ; //返回食物种类数
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(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::addFood(Food f)
{
food[total++]=f;
cout<<"成功添加了食物,当前共有"〈<total<<endl;
}
void FoodManager::showFood()
{
cout<〈"食物中共有"<<total<〈”种"<〈endl;
cout<<”食物编号 "〈〈"名称\t\t”〈〈”单价"<<endl;
for(int i = 0 ; i 〈 total ; i ++ )
cout<<setw(10)<〈setiosflags(ios::left)<〈i〈〈setw(10)〈〈setiosflags(ios::left)〈<food[i].getName()<〈"\t"〈〈food[i]。getPrice()<<endl;
}
void FoodManager::changePrice()
{
char *s;
int code;
s = new char[20];
double p;
cout<〈"请输入食物编号: ”;
cin〉〉code;
s = food[code].getName();
cout<〈"您选择了食物: ”〈<s〈<endl;
cout<<"请输入价格: ”;
cin〉〉p;
for(int i = 0; i 〈 total ; i ++)
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(),s)==0)
{
cout〈<”成功删除”〈<s<〈endl;
total --;
for(int t = i; t 〈 total ; t ++)
food[t]=food[t+1];
return;
}
cout<<"没有这种食物"<〈endl;
}
void FoodManager::addFood(char *s , double p)
{
food[total++]=Food(s,p);
}
double FoodManager::getPriceByName(char *s)
{
for(int i = 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()
{
return 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; //外卖总收入
public:
FeeManager(); //构造函数
double getWaiMaiFee(); //返回外卖总收入
double getJiuCanFee(); //返回就餐总收入
void addWaiMaiFee(double x); //增加外卖总收入
void addJiuCanFee(double x); //添加就餐总收入
};
#endif
FeeManager.cpp
#include”FeeManager。h"
FeeManager::FeeManager()
{
jiuCanFee = 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 MENUVIEW
class MenuView
{
private:
char whiteSmile; //白色笑脸
char blackSmile; //黑色笑脸
char heart; //心形图形
public:
MenuView(); //构造函数
void showJiuCan(); //显示就餐用户点菜界面
void showWaiMai(); //显示外卖用户点菜界面
int showMain(); //显示用户选择就餐还是外卖界面
int showViewChoice(); //显示进入本系统的功能选择界面
int showRegister(); //显示客户注册界面
int showClientChoice(); //显示客户点餐界面
int showQuery(); //显示查询客户订单界面
int showMend(); //显示修改食物界面
int showMenuChoice(); //显示选择菜单界面
int showMendDingDan(); //显示客户修改订单界面
};
#endif
MenuView.cpp
#include"MenuView.h"
#include<iostream〉
using namespace std;
MenuView::MenuView()
{
whiteSmile = 1;
blackSmile = 2;
heart = 3;
}
int MenuView::showMain()
{
for(int i = 1 ; i <= 80 ; i++ )cout〈〈heart;
for(int i = 1;i<=80;i++){if(i==1||i==80)cout<〈heart;else cout〈〈’ ’;}
cout<<heart〈〈”\t\t\t\t欢迎光临本餐厅”;
for(int j=1;j〈=33;j++)cout<〈' ’;cout<〈heart;
for(int i = 1;i<=80;i++){if(i==1||i==80)cout〈<heart;else cout<〈' ’;}
for(int i = 1 ; i 〈= 80 ; i++ )cout〈〈heart;
//输出餐厅的外形
cout<〈endl<<endl;
cout<〈"\t我是服务员小坠”<<whiteSmile<〈",竭诚为您服务哦”<<blackSmile<<endl<〈endl〈〈endl;
for(int k=1;k<=10;k++)cout〈〈’ ’;
for(int i = 1 ; i 〈= 20 ; i++ )cout<<heart;cout<〈endl;
for(int k=1;k<=10;k++)cout〈<' ’;
cout<<heart〈〈"请选择您需要的服务”〈〈heart〈<endl;
for(int k=1;k〈=10;k++)cout<<’ ’;
for(int i = 1 ; i <= 60 ; i++ )cout〈〈heart;cout<<endl;
for(int k=1;k〈=10;k++)cout〈<' ’;
cout〈〈heart<〈”1:就餐”;for(int i = 1 ; i 〈= 52 ; i ++ )cout<〈’ ';cout<<heart〈<endl;
for(int k=1;k〈=10;k++)cout〈<’ ';
cout<〈heart〈<”2:外卖";for(int i = 1 ; i 〈= 52 ; i ++ )cout<<’ ’;cout<〈heart<<endl;
for(int k=1;k〈=10;k++)cout〈<’ ';
for(int i = 1 ; i 〈= 60 ; i++ )cout<〈heart;cout〈〈endl<<endl;
for(int i = 1;i<=7;i++)
cout<〈endl;
cout〈〈"\t\t\t您的选择是:”;
int choice;
cin〉〉choice;
return choice;
}
void MenuView::showJiuCan()
{
cout<<"欢迎就餐,本餐厅有以下食品供您品尝”〈<whiteSmile<〈endl;
}
int MenuView::showViewChoice()
{
for(int i = 1 ; i <= 80 ; i++ )cout〈<heart;
for(int i = 1;i〈=80;i++){if(i==1||i==80)cout〈〈heart;else cout<〈’ ';}
cout〈<heart<<"\t\t\t\t陈旺均特色餐厅";
for(int j=1;j〈=33;j++)cout<〈’ ’;cout<〈heart;
for(int i = 1;i〈=80;i++){if(i==1||i==80)cout<〈heart;else cout〈〈’ ';}
for(int i = 1 ; i <= 80 ; i++ )cout<〈heart;
cout〈〈endl〈<endl;
cout〈〈”-——-—-—-——-——-———---—---”<〈endl;
cout<〈”| 1:顾客服务 |”〈<endl;
cout<〈"| 2:食物管理 |"<〈endl;
cout<〈"| 3:今日反馈 |"<<endl;
cout<〈"| 4:退出系统 |”<〈endl;
cout<<"————-——--—-———————-——---"<〈endl;
cout<〈"您的选择是: ”;
int next;
cin〉>next;
cout<<endl;
return next;
}
int MenuView::showRegister()
{
cout〈<"---————————-——————---——-"<〈endl;
cout〈<”| 1:新顾客点餐 |"<〈endl;
cout〈<"| 2:查询订单 |"〈〈endl;
cout〈<”—-—-——-—--——-—-—-—-----—"<<endl;
int next;
cin〉〉next;
return next;
}
int MenuView::showClientChoice()
{
cout<<"-—---—-----—--—-----—-——"〈〈endl;
cout<〈"| 1:加菜 |”〈<endl;
cout<<"| 2:修改订单 |”<〈endl;
cout〈<"| 3:提交订单 |”〈<endl;
cout<〈"---———-————-——-———--—-—-”<<endl;
int next;
cin〉>next;
return next;
}
int MenuView::showQuery()
{
cout<〈”—--—----——-———-——-——-——-”〈<endl;
cout<〈"| 1:查询订单 |"〈<endl;
cout〈<”| 2:退出查询 |"〈<endl;
cout<<”———-—-—---——---———---——-”〈<endl;
int next;
cin>〉next;
return next;
}
int MenuView::showMend()
{
cout〈〈"-—--—--——--——-—---————--”<〈endl;
cout<〈"| 1:添加食物 |”〈<endl;
cout〈〈”| 2:修改价格 |”〈<endl;
cout〈〈”| 3:删除食物 |”<<endl;
cout<〈"| 4:退出食物管理 |"<<endl;
cout〈<”--—--————-—--—--—-——---—"〈<endl;
int next;
cin〉〉next;
return next;
}
int MenuView::showMenuChoice()
{
cout〈〈”添加菜单:"<〈endl;
cout〈<”-——————-—-———--——------—"〈〈endl;
cout<<”| 1:原菜单 |”〈<endl;
cout<〈”| 2:更新后的菜单 |”<〈endl;
cout<〈"—----——-———-——-—-——-—--—”<〈endl;
int next;
cin〉>next;
return next;
}
int MenuView::showMendDingDan()
{
cout〈<"----—-—-—--————-———-———-”<〈endl;
cout<〈"| 1:修改数量 |”〈<endl;
cout<〈"| 2:删除食物 |"<<endl;
cout〈〈”| 3:退出修改 |"〈<endl;
cout〈<”——-—-———--—--—--—---——-—”〈<endl;
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<fstream〉
#include<iomanip〉
using namespace std;
int main()
{
FeeManager feem;//管理就餐和外卖的费用
MenuView 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 foodChoice;//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 char[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];
phone = new char[20];
cout<<"请完善客户资料”<<endl;
cout〈〈"您的订单号是”<<cm。getClientNum()+1<〈endl;
curClient = cm。getClientNum();
cout<<"请输入姓名: ”;cin〉>name;
cout〈〈"请输入手机号码: ";cin>〉phone;
Client cc(name,phone);
cc.setNumber(cm。getClientNum());
cm.addClient(cc);
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
展开阅读全文