前言
一、系統(tǒng)介紹
二、系統(tǒng)設(shè)計
一、系統(tǒng)介紹
一個餐飲預(yù)訂系統(tǒng)。程序運行后,首先選擇用戶類型,然后從文本文件讀入菜單信息
進(jìn)行初始化,根據(jù)用戶類型不同在控制臺界面上提供不同功能選擇。用戶選擇某項功能
后,根據(jù)提示進(jìn)行操作;操作完成后,能返回功能選擇菜單重新選擇,直至用戶退出。
客戶功能:
1) 預(yù)訂——打印出可選菜單,提示用戶選擇;在用戶選擇后,提示用戶輸入個人
信息,記錄下信息,并保存至本地文件。
2) 查詢/退訂——顯示所有的已訂的訂單列表,提示輸入退訂訂單;用戶輸入后,
如果賣家尚未確認(rèn)訂單,則成功退訂并修改本地文件;否則提示退訂失敗。
賣家功能:
1) 添加/刪除菜單——菜單根據(jù)文件初始化后,賣家可以對其進(jìn)行修改,包括添加
和刪除菜式等,修改后將新菜單保存至文件,下次初始化仍可用。
2) 查詢/修改訂單——讀取本地文件,顯示所有的訂單及其狀態(tài),提示確認(rèn)訂單或
不進(jìn)行操作;賣家選擇訂單后,修改該訂單為確認(rèn)狀態(tài)。
二.設(shè)計過程與討論
1.設(shè)計思路
作為一個自助訂餐系統(tǒng),除了實現(xiàn)基本功能,還要能提供友好的用戶界面,有良好的提示語句,做到不錯的用戶體驗,并處理大部分的用戶錯誤輸入。
菜單:包含編號,菜名,價格。
訂單:包含菜單,用戶姓名,用戶電話,用戶地址,數(shù)量,訂單日期,訂單狀態(tài)。
首先考慮買家功能。買家的類里存著姓名,地址,電話,點餐數(shù)量,訂餐日期,以及所有該用戶的訂單。
預(yù)訂:如果沒有可選菜單,輸出提示語句。否則,輸出所有菜單。提示用戶輸入選擇。若輸入的菜單信息無效,則提示找不到菜單,請用戶重新輸入。若有效,測提示用戶繼續(xù)輸入,或者用戶選擇下單結(jié)束。點完所有菜時,將所有用戶剛點的菜打印出來,提示用戶輸入個人信息,包括姓名,電話,地址,以及訂單的日期。完畢后,將訂單保存到本地文件。然后返回上一層。
查詢:若用戶之前輸入過姓名,則直接輸出所有已下訂單。否則,提示用戶輸入姓名,并根據(jù)姓名在訂單里查找,然后輸出,返回上一層。
退訂:若該用戶沒有任何訂單,則輸出提示并返回上一層。否則,輸出所有該用戶已下訂單的具體情況,并提示用戶輸入想要取消的訂單,若錯誤輸入,提示用戶繼續(xù)輸入。否則判斷該訂單是否已確認(rèn),已確認(rèn)則提示用戶訂單不可修改,否則輸出提示語句,取消訂單。然后將新的訂單寫入本地文件。
然后考慮賣家功能。
進(jìn)入賣家菜單,需要輸入密碼。密碼保存在本地文件,默認(rèn)為888888。當(dāng)用戶輸入正確密碼,才可以進(jìn)入系統(tǒng)。輸入錯誤5次會自動退出。進(jìn)入后,有5個功能供選擇。
添加菜單。提示用戶輸入菜式編號,菜名,價格,可以繼續(xù)添加,然后選擇退出。程序加添加后的菜單保存至本地文件。
刪除菜單。打印出所有菜單,提示用戶輸入編號,輸入錯誤則提示無此菜式。否則提示菜式已刪除。然后用戶可以選擇繼續(xù)刪除或返回上一層。
查詢訂單。若無訂單,則提示沒有訂單。否則,輸出所有訂單的詳細(xì)信息。
修改訂單。若沒有未確認(rèn)的訂單,則提示所有訂單已確認(rèn)。否則輸出所有未確認(rèn)的訂單,并為每一個訂單規(guī)定一個編號。用戶可以選擇一鍵確認(rèn)或者逐一確認(rèn)。一鍵確認(rèn)則程序修改所有訂單狀態(tài)并保存至本地文件。逐一確認(rèn)則由用戶輸入編號確認(rèn),最后在用戶放回上一層的時候保存至本地文件。
修改密碼。先由用戶輸入舊密碼,正確之后提示輸入新密碼。新密碼需輸入兩次,若兩次都一樣,則修改密碼并保存至本地文件。
用戶進(jìn)入階段。如果是點餐者,可以選擇1;如果是賣家,可以選擇2。
二、系統(tǒng)設(shè)計
1.1主函數(shù)頭文件
#include#include#include#include#include#include "Menu.h"
#include "User.h"
//以上均為定義頭文件
#pragma warning(disable : 4267)//VS2022版本,會出現(xiàn)C4267報錯,防止其報錯
using namespace std;
fstream finout;//文件讀和寫字節(jié)流
vectororder;//聲明了一個Order數(shù)組order[]
vector
以下為主函數(shù)
int main()
{
string n;//定義一個字符串n,并初始化為空
bool success = 0;
cout<< setw(55)<< "Welcome to the MyBooking system!"<< endl;//setw(55)為預(yù)留55空間
cout<< " ----------------------------------------------------------"<< endl;
//1為買家,2為賣家,3為退出系統(tǒng)
cout<< right;//右對齊,默認(rèn)為右對齊
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;
}
賣家函數(shù)
//賣家
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為確認(rèn)訂單,5為設(shè)置密碼,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;
}
}
買家函數(shù)
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類存有用戶名,地址,電話,數(shù)量,日期,確認(rèn)狀態(tài)
#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;
}
用戶預(yù)訂訂單流程圖
用戶查詢訂單流程圖
用戶修改訂單流程圖
賣家增加、刪除訂單流程圖
賣家查詢、確認(rèn)訂單流程圖
用戶頭文件
#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為繼續(xù),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;
}
//輸出所有用戶已預(yù)定的菜
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]);
}
//判斷此時買家是否為匿名狀態(tà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-繼續(xù)或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)
{
//該訂單是否已確認(rèn)
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;
}
//賣家確認(rèn)訂單
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;
}
}
//沒有未確認(rèn)訂單則提示后返回上一層
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-全部確認(rèn) 或 2-逐個確認(rèn) 或 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;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
網(wǎng)站名稱:基于C++的餐飲預(yù)訂系統(tǒng)-創(chuàng)新互聯(lián)
分享地址:http://m.rwnh.cn/article22/ehdjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、品牌網(wǎng)站制作、做網(wǎng)站、網(wǎng)站排名、Google、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)