基于C++的餐饮预订系统-创新互联
前言
一、系统介绍
二、系统设计
一、系统介绍
一个餐饮预订系统。程序运行后,首先选择用户类型,然后从文本文件读入菜单信息
进行初始化,根据用户类型不同在控制台界面上提供不同功能选择。用户选择某项功能
后,根据提示进行操作;操作完成后,能返回功能选择菜单重新选择,直至用户退出。
客户功能:
1) 预订——打印出可选菜单,提示用户选择;在用户选择后,提示用户输入个人
信息,记录下信息,并保存至本地文件。
2) 查询/退订——显示所有的已订的订单列表,提示输入退订订单;用户输入后,
如果卖家尚未确认订单,则成功退订并修改本地文件;否则提示退订失败。
卖家功能:
1) 添加/删除菜单——菜单根据文件初始化后,卖家可以对其进行修改,包括添加
和删除菜式等,修改后将新菜单保存至文件,下次初始化仍可用。
2) 查询/修改订单——读取本地文件,显示所有的订单及其状态,提示确认订单或
不进行操作;卖家选择订单后,修改该订单为确认状态。
二.设计过程与讨论
1.设计思路
作为一个自助订餐系统,除了实现基本功能,还要能提供友好的用户界面,有良好的提示语句,做到不错的用户体验,并处理大部分的用户错误输入。
菜单:包含编号,菜名,价格。
订单:包含菜单,用户姓名,用户电话,用户地址,数量,订单日期,订单状态。
首先考虑买家功能。买家的类里存着姓名,地址,电话,点餐数量,订餐日期,以及所有该用户的订单。
预订:如果没有可选菜单,输出提示语句。否则,输出所有菜单。提示用户输入选择。若输入的菜单信息无效,则提示找不到菜单,请用户重新输入。若有效,测提示用户继续输入,或者用户选择下单结束。点完所有菜时,将所有用户刚点的菜打印出来,提示用户输入个人信息,包括姓名,电话,地址,以及订单的日期。完毕后,将订单保存到本地文件。然后返回上一层。
查询:若用户之前输入过姓名,则直接输出所有已下订单。否则,提示用户输入姓名,并根据姓名在订单里查找,然后输出,返回上一层。
退订:若该用户没有任何订单,则输出提示并返回上一层。否则,输出所有该用户已下订单的具体情况,并提示用户输入想要取消的订单,若错误输入,提示用户继续输入。否则判断该订单是否已确认,已确认则提示用户订单不可修改,否则输出提示语句,取消订单。然后将新的订单写入本地文件。
然后考虑卖家功能。
进入卖家菜单,需要输入密码。密码保存在本地文件,默认为888888。当用户输入正确密码,才可以进入系统。输入错误5次会自动退出。进入后,有5个功能供选择。
添加菜单。提示用户输入菜式编号,菜名,价格,可以继续添加,然后选择退出。程序加添加后的菜单保存至本地文件。
删除菜单。打印出所有菜单,提示用户输入编号,输入错误则提示无此菜式。否则提示菜式已删除。然后用户可以选择继续删除或返回上一层。
查询订单。若无订单,则提示没有订单。否则,输出所有订单的详细信息。
修改订单。若没有未确认的订单,则提示所有订单已确认。否则输出所有未确认的订单,并为每一个订单规定一个编号。用户可以选择一键确认或者逐一确认。一键确认则程序修改所有订单状态并保存至本地文件。逐一确认则由用户输入编号确认,最后在用户放回上一层的时候保存至本地文件。
修改密码。先由用户输入旧密码,正确之后提示输入新密码。新密码需输入两次,若两次都一样,则修改密码并保存至本地文件。
用户进入阶段。如果是点餐者,可以选择1;如果是卖家,可以选择2。
二、系统设计
1.1主函数头文件
#include#include#include#include#include#include "Menu.h"
#include "User.h"
//以上均为定义头文件
#pragma warning(disable : 4267)//VS2022版本,会出现C4267报错,防止其报错
using namespace std;
fstream finout;//文件读和写字节流
vectororder;//声明了一个Order数组order[]
vector
以下为主函数
int main()
{
string n;//定义一个字符串n,并初始化为空
bool success = 0;
cout<< setw(55)<< "Welcome to the MyBooking system!"<< endl;//setw(55)为预留55空间
cout<< " ----------------------------------------------------------"<< endl;
//1为买家,2为卖家,3为退出系统
cout<< right;//右对齐,默认为右对齐
cout<< endl<< setw(25)<< "1.Buyer"<< setw(15)<< "2.Seller"<< setw(15)<< "3.Exit"<< endl;
while (cin >>n)
{
order.clear();//什么访问什么来着?
menu.clear();
if (n == "3") break;
//处理错误输入
if (n != "1" && n != "2")
{
cout<< endl<< "Invalid number!Please input again :"<< endl;
cout<< endl<< setw(25)<< "1.Buyer"<< setw(15)<< "2.Seller"<< setw(15)<< "3.Exit"<< endl;
continue;
}
if (n == "1") seviceForBuyer();
else seviceForSeller();
cout<< right;
cout<< endl<< setw(25)<< "1.Buyer"<< setw(15)<< "2.Seller"<< setw(15)<< "3.Exit"<< endl;
}
return 0;
}
用于读取文件中的菜单和订单,需要用户提前输入好,储存在txt文本文档里
//用于读取文件中的菜单
Menu inputMenu()
{
Menu iMenu;
string dishID, dishName;
double price = -1;
finout >>dishID;
if (dishID == " " || dishID == "\n") {
iMenu.setDishID("-1");
return iMenu;
}
finout >>dishName >>price;
if (price< 0 || price >100000) {
iMenu.setDishID("-1");
return iMenu;
}
iMenu.setDishID(dishID);
iMenu.setDishName(dishName);
iMenu.setPrice(price);
return iMenu;
}
//用于读取文件中的订单
Order inputOrder()
{
string dishID, dishName, name, adress, phone;
double price = -1;
int year, month, day, hour, modify, num;
finout >>dishID;
if (dishID == " " || dishID == "\n")
{
Order iOrder;
iOrder.setDishID("-1");
return iOrder;
}
finout >>dishName >>price >>num >>name >>adress >>phone;
if (price< 0 || price >100000) {
Order iOrder;
iOrder.setDishID("-1");
return iOrder;
}
finout >>year >>month >>day >>hour >>modify;
Date date(year, month, day, hour);
Order iOrder(dishName, dishID, price, name, adress, phone, date);
iOrder.setnum(num);
if (!modify) iOrder.setModify();
return iOrder;
}
卖家函数
//卖家
void seviceForSeller()
{
Seller iSeller;
Order iOrder;
Menu iMenu;
//验证密码
string password;
finout.open("password.txt", ios::in);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
return;
}
finout >>password;
finout.close();
iSeller.setPassword(password);
cout<< endl<< "Please input your password ( default is 888888 ) :";
string str;
int num = 5;
cin >>str;
while (num-- && str != iSeller.getPassword())
{
cout<< endl<< "The password is wrong!\nPlease input again : ";
cin >>str;
}
if (num<= 0)
{
cout<< endl<< "You have input wrong password five times!"<< endl;
return;
}
//1为增加菜单,2为删除菜单,3为查询订单,4为确认订单,5为设置密码,6返回主菜单
cout<< endl<< "Please choose the function you want :"<< endl;
cout<< left;
cout<< endl<< " "<< setw(30)<< "1. Append menu"<< setw(20)<< "2. Cancel menu"<< endl;
cout<< " "<< setw(30)<< "3. Inquire"<< setw(20)<< "4.Modify"<< endl;
cout<< " "<< setw(30)<< "5.Set password"<< setw(20)<< "6.Main Menu"<< endl;
string choice;
while (cin >>choice)
{
if (choice == "6")
{
return;
}
//处理错误输入
if (choice != "1" && choice != "2" && choice != "3" && choice != "4" && choice != "5")
{
cout<< endl<< "Invalid input!Please input anain!"<< endl;
cout<< endl<< " "<< setw(30)<< "1. Append menu"<< setw(20)<< "2. Cancel menu"<< endl;
cout<< " "<< setw(30)<< "3. Inquire"<< setw(20)<< "4.Modify"<< endl;
cout<< " "<< setw(30)<< "5.Set password"<< setw(20)<< "6.Main Menu"<< endl;
continue;
}
//从文件读取以初始化菜单信息和订单信息
order.clear();
finout.open("order.txt", ios::in);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
break;
}
while (!finout.eof())
{
iOrder = inputOrder();
if (iOrder.getDishID() == "-1") break;
order.push_back(iOrder);
}
finout.close();
menu.clear();
finout.open("menu.txt", ios::in);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
break;
}
while (!finout.eof())
{
iMenu = inputMenu();
if (iMenu.getDishID() == "-1") break;
menu.push_back(iMenu);
}
finout.close();
if (choice == "1")
iSeller.appendMenu(menu);
else if (choice == "2")
iSeller.cancelMenu(menu);
else if (choice == "3")
iSeller.inquireOrder(order);
else if (choice == "4")
iSeller.modifyOrder(order);
else
{
//修改密码
string str1, str2;
cout<< right;
cout<< endl<< setw(35)<< "1.Continue"<< setw(20)<< "2.return"<< endl;
while (cin >>str1)
{
if (str1 == "2") break;
//处理错误输入
if (str1 != "1")
{
cout<< "Invalid input!"<< endl;
cout<< endl<< setw(35)<< "1.Continue"<< setw(20)<< "2.return"<< endl;
continue;
}
cout<< "Please input your old password : ";
cin >>str1;
if (str1 == iSeller.getPassword()) break;
else
{
cout<< right;
cout<< endl<< "Wrong!"<< endl;
cout<< endl<< setw(35)<< "1.Continue"<< setw(20)<< "2.return"<< endl;
}
}
if (str1 == "2")
{
cout<< left;
cout<< endl<< " "<< setw(30)<< "1. Append menu"<< setw(20)<< "2. Cancel menu"<< endl;
cout<< " "<< setw(30)<< "3. Inquire"<< setw(20)<< "4.Modify"<< endl;
cout<< " "<< setw(30)<< "5.Set password"<< setw(20)<< "6.Main Menu"<< endl;
continue;
}
cout<< endl<< "Please input your new password : ";
cin >>str1;
cout<< endl<< "Please input again :";
cin >>str2;
//两次输入的新密码一样,则修改密码,写入文件
if (str1 == str2) {
finout.open("password.txt", ios::out);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
return;
}
finout<< str1;
finout.close();
iSeller.setPassword(str1);
cout<< endl<< "The new password have benn set!"<< endl;
}
else
{
cout<< endl<< "The new password you have input twice times is different !"<< endl;
}
}
cout<< left;
cout<< endl<< " "<< setw(30)<< "1. Append menu"<< setw(20)<< "2. Cancel menu"<< endl;
cout<< " "<< setw(30)<< "3. Inquire"<< setw(20)<< "4.Modify"<< endl;
cout<< " "<< setw(30)<< "5.Set password"<< setw(20)<< "6.Main Menu"<< endl;
}
if (choice == "6")
{
return;
}
}
买家函数
void seviceForBuyer()
{
Buyer ibuyer;
Menu iMenu;
Order iOrder;
string n;
// 1为点菜,2为查询订单,3为修改订单 ,4返回主菜单
cout<< left;
cout<< endl<< "Please continue to choose the function you want:"<< endl;
cout<< endl<< " "<< setw(20)<< "1. Order"<< setw(20)<< "2. Inquire"<< endl;
cout<< " "<< setw(20)<< "3. Cancel"<< setw(20)<< "4.Main Menu"<< endl;
cin >>n;
while (n != "4")
{
//处理错误输入
if (n != "1" && n != "2" && n != "3")
{
cout<< endl<< "Invalid input!Please input anain!"<< endl;
cin >>n;
continue;
}
//从文件读取以初始化菜单信息和订单信息
order.clear();
finout.open("order.txt", ios::in);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
break;
}
while (!finout.eof())
{
iOrder = inputOrder();
if (iOrder.getDishID() == "-1") break;
order.push_back(iOrder);
}
finout.close();
menu.clear();
finout.open("menu.txt", ios::in);
if (finout.fail())
{
cout<< endl<< "The system can't find the file!"<< endl;
break;
}
while (!finout.eof())
{
iMenu = inputMenu();
if (iMenu.getDishID() == "-1") break;
menu.push_back(iMenu);
}
finout.close();
if (n == "1")
ibuyer.bookOrder(menu, order);
else if (n == "2")
ibuyer.inquireOrder(order);
else if (n == "3")
ibuyer.modifyOrder(order);
cout<< left;
cout<< endl<< "Please continue to choose the function you want:"<< endl;
cout<< endl<< " "<< setw(20)<< "1. Order"<< setw(20)<< "2. Inquire"<< endl;
cout<< " "<< setw(20)<< "3. Cancel"<< setw(20)<< "4.Main Menu"<< endl;
cin >>n;
}
if (n == "4") return;
}
菜单头文件
#include#include#includeusing namespace std;
//定义日期类,存年月日及小时
#ifndef DATE_H
#define DATE_H
class Date
{
private:
int year, month, day, hour;
public:
Date();
Date(int y, int m, int d, int h);
bool operator ==(Date date2);
int getYear();
int getMonth();
int getDay();
int getHour();
void setYear(int);
void setMonth(int);
void setDay(int);
void setHour(int);
};
#endif
#ifndef MENU_H
#define MENU_H
class Menu
{
protected:
string dishName, dishID;
double price;
public:
Menu();
Menu(string dishName, string dishID, double price);
void setDishName(string);
void setDishID(string);
void setPrice(double);
string getDishName();
string getDishID();
double getPrice();
};
#endif
//Order类存有用户名,地址,电话,数量,日期,确认状态
#ifndef ORDER_H
#define ORDER_H
class Order :public Menu
{
private:
string customerName, adress, phone;
int num;
Date bookDate;
bool modify;
public:
Order();
Order(string dishName, string dishID, double price, string customerName, string adress, string phone, Date bookDate);
Order(string dishName, string dishID, double price);
Order(Menu, int);
const bool operator==(Order order2);
string getCustomerName();
string getAdress();
string getPhone();
Date getBookDate();
bool getModify();
int getNum();
bool setCustomerName(string customerName);
bool setAdress(string adress);
bool setPhone(string phone);
bool setnum(int num);
bool setBookDate(Date bookDate);
void setModify();
};
#endif
菜单程序
#include#include#include#include#include "Menu.h"
using namespace std;
Date::Date(int y, int m, int d, int h)
{
year = y;
month = m;
day = d;
hour = h;
}
Date::Date()
{
year = 2012;
month = 12;
day = 12;
hour = 12;
}
bool Date::operator==(Date date2)
{
if (date2.year == year && date2.month == month && date2.day == day && date2.hour == hour) return true;
return false;
}
int Date::getYear()
{
return year;
}
int Date::getMonth()
{
return month;
}
int Date::getDay()
{
return day;
}
int Date::getHour()
{
return hour;
}
void Date::setYear(int y)
{
year = y;
}
void Date::setMonth(int m)
{
month = m;
}
void Date::setDay(int d)
{
day = d;
}
void Date::setHour(int h)
{
hour = h;
}
Menu::Menu()
{
}
Menu::Menu(string dishName, string dishID, double price)
{
this->dishName = dishName;
this->dishID = dishID;
this->price = price;
}
void Menu::setDishName(string name)
{
dishName = name;
}
void Menu::setDishID(string ID)
{
dishID = ID;
}
void Menu::setPrice(double p)
{
price = p;
}
string Menu::getDishName()
{
return dishName;
}
string Menu::getDishID()
{
return dishID;
}
double Menu::getPrice()
{
return price;
}
Order::Order()
{
modify = 1;
}
Order::Order(string dishName, string dishID, double price, string customerName, string adress, string phone, Date date) :Menu(dishName, dishID, price), bookDate(date)
{
this->customerName = customerName;
this->adress = adress;
this->phone = phone;
modify = 1;
}
Order::Order(string dishName, string dishID, double price) : Menu(dishName, dishID, price)
{
modify = 1;
}
Order::Order(Menu m, int n) :Menu(m), num(n)
{
modify = 1;
};
const bool Order::operator==(Order order2)
{
if (order2.dishID != dishID) return false;
if (order2.dishName != dishName) return false;
if (order2.customerName != customerName) return false;
if (order2.phone != phone) return false;
if (order2.adress != adress) return false;
if (!(order2.bookDate == bookDate)) return false;
return true;
}
string Order::getCustomerName()
{
return customerName;
}
string Order::getAdress()
{
return adress;
}
string Order::getPhone() {
return phone;
}
Date Order::getBookDate()
{
return bookDate;
}
bool Order::getModify()
{
return modify;
}
int Order::getNum()
{
return num;
}
bool Order::setCustomerName(string customerName)
{
if (!modify) return false;
this->customerName = customerName;
return true;
}
bool Order::setAdress(string adress)
{
if (!modify) return false;
this->adress = adress;
return true;
}
bool Order::setPhone(string phone)
{
if (!modify) return false;
this->phone = phone;
return true;
}
void Order::setModify()
{
modify = 0;
}
bool Order::setBookDate(Date bookDate)
{
if (!modify) return false;
this->bookDate = bookDate;
return true;
}
bool Order::setnum(int num)
{
if (!modify) return false;
this->num = num;
return true;
}
用户预订订单流程图
用户查询订单流程图
用户修改订单流程图
卖家增加、删除订单流程图
卖家查询、确认订单流程图
用户头文件
#pragma once
#include"Menu.h"
#include#ifndef USER_H
#define USER_H
class User {
private:
public:
virtual void modifyOrder(vector&) = 0;
virtual void inquireOrder(vector&) = 0;
};
#endif
//卖家有密码成员变量
#ifndef SELLER_H
#define SELLER_H
class Seller :public User {
private:
string password;
public:
Seller();
void modifyOrder(vector&);
void inquireOrder(vector&);
void appendMenu(vector
用户程序
#include
#include #include #include #include #include #include "Menu.h" #include "User.h" #pragma warning(disable : 4267) using namespace std; fstream inout; //用于输出日期 void printDate(Date date) { cout<< left; cout<< date.getYear()<< '/'<< date.getMonth()<< '/'<< date.getDay()<< "-"<< date.getHour()<< 'h'; } //用于输出菜单 void printMenu(Menu m) { cout<< left; cout<< setw(20)<< m.getDishID()<< setw(20)<< m.getDishName()<< setw(20)<< m.getPrice()<< endl; } //用于输出订单 void printOrder(Order myOrder) { cout<< left; cout<< setw(7)<< myOrder.getDishID()<< setw(10)<< myOrder.getDishName()<< setw(6)<< myOrder.getPrice()<< setw(4)<< myOrder.getNum(); cout<< setw(8)<< myOrder.getCustomerName()<< setw(8)<< myOrder.getPhone()<< setw(12)<< myOrder.getAdress(); cout<< " "; printDate(myOrder.getBookDate()); cout<< " "; if (myOrder.getModify()) { cout<< setw(10)<< "New"<< endl; } else cout<< setw(10)<< "Approved"<< endl; } //用于将菜单写入文件 void outputMenu(Menu& iMenu) { inout<< iMenu.getDishID()<< ' '<< iMenu.getDishName()<< ' '<< iMenu.getPrice()<< endl; } //用于将订单写入文件 void outputOrder(Order& iOrder) { Date date = iOrder.getBookDate(); int modify = iOrder.getModify() ? 1 : 0; inout<< iOrder.getDishID()<< ' '<< iOrder.getDishName()<< ' '<< iOrder.getPrice()<< ' '<< iOrder.getNum()<< endl; inout<< iOrder.getCustomerName()<< ' '<< iOrder.getAdress()<< ' '<< iOrder.getPhone()<< endl; inout<< date.getYear()<< ' '<< date.getMonth()<< ' '<< date.getDay()<< ' '<< date.getHour()<< ' '<< modify<< endl; } Buyer::Buyer() { name = "no"; adress = "no"; num = 0; } string Buyer::getName() { return name; } //买家订菜 void Buyer::bookOrder(vector & myMenu, vector
& order) { int n, m = 0, i, year, month, day, hour, appNum = 0; string str; char ch; n = myMenu.size(); num = myOrder.size(); bool can = 1; //判断菜单是否为空 if (!n) { cout<< endl<< "Sorry! There is no dish for you to choose!"<< endl; return; } cout<< left; cout<< endl<< "Here is the Menu :"<< endl; cout<< endl<< " "<< setw(20)<< "DishID"<< setw(20)<< "DishName"<< setw(20)<< "Price"<< endl; for (i = 0; i< n; ++i) { cout<< " "; printMenu(myMenu[i]); } //1为继续,2返回上一层 cout<< right; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; while (cin >>str) { can = 1; if (str == "2") break; cout<< "Please input the dish ID : "; cin >>str; for (i = 0; i< n; ++i) { if (myMenu[i].getDishID() == str) { myOrder.push_back(Order(myMenu[i], m)); break; } //判断该编号是否存在 if (i == n - 1) { cout<< endl<< "There is no such dish!"<< endl; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; can = 0; } } if (!can) continue; appNum++; cout<< endl<< "Please input the count you want : "; cin >>m; myOrder[myOrder.size() - 1].setnum(m); cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; } //判断有无新增菜单 if (appNum == 0) { cout<< endl<< "You haven't ordered anything!"<< endl; return; } //输出所有用户已预定的菜 cout<< left; cout<< endl<< "Here is the dish you have ordered:"<< endl; cout<< endl<< setw(20)<< "DishID"<< setw(20)<< "DishName"<< setw(20)<< "Price"<< endl; for (i = 0; i< myOrder.size(); ++i) { printMenu(myOrder[i]); } //判断此时买家是否为匿名状态,是则跳过输入姓名,地址,电话 if (name == "no" || adress == "no") { cout<< endl<< "Please input your name : "; cin >>name; cout<< endl<< "Please input your address : "; cin >>adress; cout<< endl<< "Please input your phone : "; cin >>phone; } cout<< endl<< "Please input the date you want to have you dish,"<< endl; cout<< "just as 2013/5/2 14 (year/month/day hour) : "<< endl; cin >>year >>ch >>month >>ch >>day >>hour; bookDate.setYear(year); bookDate.setMonth(month); bookDate.setDay(day); bookDate.setHour(hour); for (int i = num; i< myOrder.size(); ++i) { myOrder[i].setCustomerName(name); myOrder[i].setAdress(adress); myOrder[i].setPhone(phone); myOrder[i].setBookDate(bookDate); } inout.open("order.txt", ios::app); if (inout.fail()) { cout<< endl<< "The system can't find the file!"<< endl; return; } for (i = num; i< myOrder.size(); ++i) { outputOrder(myOrder[i]); } inout.close(); num = myOrder.size(); } //买家查询订单 void Buyer::inquireOrder(vector & order) { //名字是否为空 if (name == "no") { cout<< endl<< "please input your name : "; cin >>name; } myOrder.clear(); for (int i = 0; i< order.size(); ++i) { if (order[i].getCustomerName() == name) { myOrder.push_back(order[i]); } } num = myOrder.size(); if (num == 0) { cout<< endl<< "You haven't ordered any dish!"<< endl; return; } cout<< left; cout<< endl<< "Here is the dishes you have ordered :"<< endl; cout<< endl<< setw(7)<< "DishID"<< setw(10)<< "DishName"<< setw(6)<< "price"<< setw(4)<< "num"<< setw(8)<< "Name"; cout<< setw(8)<< "Phone"<< setw(12)<< "Address"<< setw(15)<< "Date"<< setw(10)<< "state"<< endl; for (int i = 0; i< num; ++i) { printOrder(myOrder[i]); } return; } //买家取消订单 void Buyer::modifyOrder(vector & order) { num = myOrder.size(); if (num == 0) { cout<< endl<< "You haven't ordered any dish!"<< endl; return; } //输出买家自已的所有订单 cout<< left; cout<< endl<< "The dish you have ordered is :"<< endl; cout<< endl<< setw(7)<< "DishID"<< setw(10)<< "DishName"<< setw(6)<< "price"<< setw(4)<< "num"<< setw(8)<< "Name"; cout<< setw(8)<< "Phone"<< setw(12)<< "Address"<< setw(15)<< "Date"<< setw(10)<< "state"<< endl; for (int i = 0; i< num; ++i) { printOrder(myOrder[i]); } //选择1-继续或2-返回上一层 cout<< right; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; string str; int pos = -1, n = 0; Order iOrder; int* cancleDish = new int[num + 1], * cancle = new int[order.size()]; memset(cancleDish, 0, 4 * (num + 1)); memset(cancle, 0, 4 * (order.size())); while (cin >>str) { if (str == "2") break; //判断无效输入 if (str != "1") { cout<< endl<< "Invalid input!"<< endl; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; continue; } cout<< endl<< "Please input the dishID : "; cin >>str; for (int i = 0; i< num; ++i) { if (myOrder[i].getDishID() == str) { //该订单是否已确认 if (myOrder[i].getModify()) { cout<< endl<< "The order have been canceled!"<< endl; pos = i; break; } else { cout<< endl<< "The order have been approved! You can't cancel it !"<< endl; pos = -2; break; } } } //查看该买家想取消的编号是否存在 if (pos< 0) { if (pos == -1) cout<< endl<< "There is no such dish you have ordered!"<< endl; } else { cancleDish[pos] = 1; n++; } pos = -1; cout<< right; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; } //将更新的订单写入文件 inout.open("order.txt", ios::out); if (inout.fail()) { cout<< endl<< "The system can't find the file!"<< endl; delete cancleDish; delete cancle; return; } for (int i = 0; i< num; ++i) { if (cancleDish[i]) { for (int j = 0; j< order.size(); ++j) { if (order[j] == myOrder[i]) { cancle[j] = 1; break; } } } } for (int i = 0; i< order.size(); ++i) { if (cancle[i]) { continue; } outputOrder(order[i]); } inout.close(); num -= n; delete cancleDish; delete cancle; } int Buyer::getNum() { return num; } Seller::Seller() { password = "888888"; } void Seller::appendMenu(vector & myMenu) { cout<< endl<< "Do you want to append Menu? Y/N"<< endl; string ch; int k = myMenu.size(); while (cin >>ch) { //判断无效输入 if (ch != "Y" && ch != "y") break; cout<< endl<< "please input the dish name : "; string str; Menu iMenu; double d; cin >>str; iMenu.setDishName(str); cout<< endl<< "Please input the dish ID : "; cin >>str; iMenu.setDishID(str); cout<< endl<< "Please input the price of the dish : "; cin >>d; iMenu.setPrice(d); myMenu.push_back(iMenu); cout<< endl<< "The dish have been added to the menu!"<< endl; cout<< endl<< "Do you want to continue to append Menu? Y/N"<< endl; } //将新增菜单写入文件 inout.open("menu.txt", ios::app); if (inout.fail()) { cout<< endl<< "The system can't find the file!"<< endl; return; } for (int i = k; i< myMenu.size(); ++i) { outputMenu(myMenu[i]); } inout.close(); return; } void Seller::cancelMenu(vector
& myMenu) { cout<< endl<< "Do you want to cancel Menu? Y/N"<< endl; string str; string ch; Menu iMenu; vector
::iterator it = myMenu.begin(); while (cin >>ch) { it = myMenu.begin(); if (ch == "N" || ch == "n") break; //判断无效输入 if (ch != "Y" && ch != "y") { cout<< endl<< "Invalid input!Please input again!"<< endl; cout<< endl<< "Do you want to cancel Menu? Y/N"<< endl; continue; } //输出所有菜单 cout<< left; cout<< endl<< "Here is the Menu :"<< endl; cout<< endl<< " "<< setw(20)<< "DishID"<< setw(20)<< "DishName"<< setw(20)<< "Price"<< endl; for (int i = 0; i< myMenu.size(); ++i) { cout<< " "; printMenu(myMenu[i]); } cout<< endl<< "Please input the dish ID you want cancel : "; cin >>str; for (int i = 0; i< myMenu.size(); ++i) { if (myMenu[i].getDishID() == str) { myMenu.erase(it + i); cout<< endl<< "The dish have been canceled!"<< endl; break; } //找不到该编号 if (i == myMenu.size() - 1) { cout<< endl<< "There is no such dish!Please input again!"<< endl; } } cout<< endl<< "Do you want to continue to cancel Menu? Y/N"<< endl; } //将修改后菜单写入文件 inout.open("menu.txt", ios::out); if (inout.fail()) { cout<< endl<< "The system can't find the file!"<< endl; return; } for (int i = 0; i< myMenu.size(); ++i) { outputMenu(myMenu[i]); } inout.close(); } //卖家查询订单 void Seller::inquireOrder(vector
& order) { //没有订单则输出提示并返回上一层 if (order.size() == 0) { cout<< endl<< "There is no any order!"<< endl; return; } cout<< left; cout<< endl<< "Here is the order :"<< endl; cout<< endl<< setw(7)<< "DishID"<< setw(10)<< "DishName"<< setw(6)<< "price"<< setw(4)<< "num"<< setw(8)<< "Name"; cout<< setw(8)<< "Phone"<< setw(12)<< "Address"<< setw(15)<< "Date"<< setw(10)<< "state"<< endl; for (int i = 0; i< order.size(); ++i) { printOrder(order[i]); } return; } //卖家确认订单 void Seller::modifyOrder(vector & order) { int* pos = new int[order.size() + 1], count = 0; memset(pos, 0, sizeof(pos)); for (int i = 0; i< order.size(); ++i) { if (order[i].getModify()) { count++; pos[i] = 1; } } //没有未确认订单则提示后返回上一层 if (count == 0) { cout<< endl<< "All order have been approved!"<< endl; return; } cout<< left; cout<< endl<< "Here is the order you haven't approve : "<< endl; cout<< endl<< setw(7)<< "DishID"<< setw(10)<< "DishName"<< setw(6)<< "price"<< setw(4)<< "num"<< setw(8)<< "Name"; cout<< setw(8)<< "Phone"<< setw(12)<< "Address"<< setw(15)<< "Date"<< setw(10)<< "state"<< endl; count = 0; for (int i = 0; i< order.size(); ++i) { if (pos[i] && order[i].getModify()) { count++; cout<< count<< endl; printOrder(order[i]); } } //卖家可选择 1-全部确认 或 2-逐个确认 或 3-返回 cout<< right; cout<< endl<< setw(20)<< "1.Aprove all"<< setw(25)<< "2.Aprove one by one"<< setw(20)<< "3.return"<< endl; string n; while (cin >>n) { if (n == "1" || n == "2" || n == "3") break; else { cout<< endl<< "Invalid input!"<< endl; cout<< endl<< setw(20)<< "1.Aprove all"<< setw(25)<< "2.Aprove one by one"<< setw(20)<< "3.return"<< endl; } } if (n == "3") return; if (n == "1") { for (int i = 0; i< order.size(); ++i) { if (pos[i]) order[i].setModify(); } } else { cout<< right; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; int k, m; while (cin >>m) { if (m == 2) return; if (m != 1) { cout<< endl<< "Invalid input!"<< endl; return; } cout<< endl<< "Please input the number of order:"; cin >>m; //检验输入正确性 if (m >count) { cout<< endl<< "There is only "<< count<< " order!"<< endl; cout<< endl<< "Please input again!"<< endl; } else if (m<= 0) { cout<< endl<< "The number must be positive !"<< endl; } else { k = 0; for (int i = 0; i< order.size(); ++i) { if (pos[i]) { k++; if (k == m) { order[i].setModify(); cout<< endl<< "The order have approved!"<< endl; } } } } cout<< right; cout<< endl<< setw(30)<< "1.Continue"<< setw(20)<< "2.return"<< endl; } } //将修改后的订单写入文件 inout.open("order.txt", ios::out); if (inout.fail()) { cout<< endl<< "The system can't find the file!"<< endl; return; } for (int i = 0; i< order.size(); ++i) { outputOrder(order[i]); } inout.close(); } void Seller::setPassword(string p) { password = p; } string Seller::getPassword() { return password; }
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
文章名称:基于C++的餐饮预订系统-创新互联
URL链接:http://wjwzjz.com/article/ehdjc.html