Untitled
unknown
plain_text
2 years ago
27 kB
7
Indexable
#include <iostream>
#include <string>
#include <vector>
#include<fstream>
#include<iomanip>
using namespace std;
void List_Restaurants(int&,vector<vector<string>>&,vector<string>&,int [],int);//list the restaurants with delivery fee
void Add_Items_to_Cart(vector<string>&, vector<string>&,int &,int);//input his name and the cuisine number that he wants to add to the cart
void Payment(vector<string>&,int&, int [][10],vector<string>dfee,bool&log,vector<string>& namelist); //input his name and show all of the items in his cart
void shopsystem(vector<vector<string>>,vector<string>&,int [],vector<string>& cartlist,vector<string>& namelist,int &counter,bool&log);
void Member_system(vector<string>&,int&, int [][10],vector<string>dfee,string &file,vector<string>&namelist,bool &log,bool &load);
void List_shops( vector<vector<string>> &shop,int shopgood[],vector<string>& shoplist );
void Log_In(int& counter , vector<string>& namelist , vector<string>& cartlist , string &file,bool &log);//according to file in member system, find record
void Sign_Up(int& counter,vector<string>& namelist,vector<string>& cartlist,string& file,bool &log);//according to file in member system, add record
void Log_Out(int& counter,vector<string>& namelist,vector<string>& cartlist,string &file,bool &log);
void Load_Member_Information(string & file,bool& load);
int main()
{
string Do;int shopgood[10];shopgood[1]=2;shopgood[2]=2;shopgood[3]=3;string file;bool log=0;//log=1 log in log=0 not log in
string do_what;vector<string> cartlist(100);int counter=0;vector<string>shoplist(10);//counter count how many names in namelist
vector<vector<string>> restaurant(10,vector<string>(20));bool load=0;
int shops=3;
shoplist[1]="*** Walmart ***";shoplist[2]="*** Target ***";shoplist[3]="*** Costco ***";
vector<string>namelist(100);vector<string> shopname(10);int good[10];//goods amount in each shop
vector<string>dfee(100);vector<vector<string>> shop(10,vector<string>(20));
dfee[1]="Delivery Fee NTD 29";dfee[11]="Delivery Fee NTD 49";
dfee[2]="Delivery Fee NTD 49";dfee[12]="Delivery Fee NTD 39";
dfee[3]="Delivery Fee NTD 39";dfee[13]="Delivery Fee NTD 29";
shop[1][0]="1 Walmart NTD 49";
shop[1][1]="1-1 Tissue NTD 124";shop[1][2]="1-2 Light Bulbs NTD 99";
shop[2][0]="2 Target NTD 39";
shop[2][1]="2-1 Shampoo NTD 239";shop[2][2]="2-2 Toothpaste NTD 129";
shop[3][0]="3 Costco NTD 29";
shop[3][1]="3-1 Milk NTD 259";shop[3][2]="3-2 Doritos NTD 165";shop[3][3]="3-3 Croissant NTD 199";
good[1]=2;good[2]=3;good[3]=3;
int goodvalue[10][10];
goodvalue[1][0]=29;goodvalue[2][0]=49;goodvalue[3][0]=39;//delivery fee
goodvalue[1][1]=75;goodvalue[1][2]=85; //good value
goodvalue[2][1]=71;goodvalue[2][2]=78;goodvalue[2][3]=52;//good value
goodvalue[3][1]=140;goodvalue[3][2]=130;goodvalue[3][3]=50;//good value
shopname[1]="*** Wang shih jhen sin tang ***";
shopname[2]="*** Taiwan di er jia yan su ji ***";
shopname[3]="*** Fang kong nai ba ***";
restaurant[1][0]="1 Wang shih jhen sin tang NTD 29";restaurant[1][10]="1 Wang shih jhen sin tang NTD 0";
restaurant[2][0]="2 Taiwan di er jia yan su ji NTD 49";restaurant[2][10]="2 Taiwan di er jia yan su ji NTD 0";
restaurant[3][0]="3 Fang kong nai ba NTD 39";restaurant[3][10]="3 Fang kong nai ba NTD 0";
restaurant[1][1]="1-1 Bubble Tea NTD 75";
restaurant[1][2]="1-2 Cheese-Topped Black Tea NTD 85";
restaurant[2][1]="2-1 Boneless Salted Crispy Chicken NTD 71";
restaurant[2][2]="2-2 Egg Tofu NTD 78";
restaurant[2][3]="2-3 Green Beans NTD 52";
restaurant[3][1]="3-1 Sakura Shrimp Fried Rice NTD 140";
restaurant[3][2]="3-2 Squid Fried Noodles NTD 130";
restaurant[3][3]="3-3 Grilled King Oyster Mushrooms NTD 50";
do
{
cout << "**********************************\n*** Food Delivery Homepage ***\n**********************************" << endl;
cout << "Enter 1 to Food Delivery System" << endl;
cout << "Enter 2 to Shops System" << endl;
cout << "Enter 3 to Pick-Up System" << endl;
cout << "Enter 4 to Member System" << endl;
cout << "Enter 5 to Payment" << endl;
cout << "Enter exit() to quit\n>>>" ;
getline(cin,Do);
if(Do=="exit()")//old
{
return 0;
}
if(Do=="1"||Do=="2"||Do=="3"||Do=="4"||Do=="exit()"||Do=="5")//good input
{
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
if(Do=="1")
{
do
{
cout << "**********************************" << endl;
cout << "*** Food Delivery System ***\n**********************************" << endl;
cout << "Enter 1 to List Restaurants" << endl;
cout << "Enter 2 to Add Items to Cart" << endl;
cout << "Enter back to the Homepage\n>>>" ;
getline(cin,do_what);
if(do_what=="back")
{
cout<<endl;
break;
}
if(log==0&&do_what=="2")
{
cout<<endl;
cout << "Please log in first.\n"<<endl;
continue;
}
if(do_what=="1"||do_what=="2")//good input
{
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
if(do_what=="1")
{
List_Restaurants(shops,restaurant,shopname,good,0);
}
else if(do_what=="2")
{
Add_Items_to_Cart(cartlist,namelist,counter,0);
}
}while(do_what!="back");
}
else if(Do=="2")
{
shopsystem(shop,shoplist,shopgood,cartlist,namelist,counter,log);
}
else if(Do=="3")
{
do
{
cout << "**********************************" << endl;
cout << "*** Pick-Up System ***\n**********************************" << endl;
cout << "Enter 1 to List Restaurants" << endl;
cout << "Enter 2 to Add Items to Cart" << endl;
cout << "Enter back to the Homepage\n>>>";
getline(cin,do_what);
if(do_what=="back")
{
cout<<endl;
break;
}
if(log==0&&do_what=="2")
{
cout<<endl;
cout << "Please log in first.\n"<<endl;
continue;
}
if(do_what=="1"||do_what=="2")//good input
{
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
if(do_what=="1")
{
List_Restaurants(shops,restaurant,shopname,good,2);
}
else if(do_what=="2")
{
Add_Items_to_Cart(cartlist,namelist,counter,2);
}
}while(true);
}
else if(Do=="5")
{
Payment(cartlist,counter,goodvalue,dfee,log, namelist);
}
else if(Do=="4")
{
Member_system(cartlist,counter,goodvalue,dfee,file,namelist,log,load);
}
}while(Do!="exit()");
}
void List_shops( vector<vector<string>> &shop,int shopgood[],vector<string>& shoplist )
{
string listoption;
do
{
cout<<"*** List Shops ***"<<endl;
cout<<"No. Shop Delivery Fee"<<endl;
for(int i=1;i<=3;i++)
{
cout << shop[i][0] << endl;
}
cout<<"Enter number to the shop or enter back to the Shops System"<<endl;
cout<<">>>";
getline(cin,listoption);
if(listoption=="back")
{
cout<<endl;
break;
}
if(listoption=="1"||listoption=="2"||listoption=="3")
{
cout<<endl;
cout << shoplist[stoi(listoption)]<<endl;
cout<<"No. Groceries Price"<<endl;
for(int i=1;i<=shopgood[stoi(listoption)];i++)
{
cout<<shop[stoi(listoption)][i]<<endl;
}
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
}while(listoption!="back");
}
void List_Restaurants(int &shops , vector<vector<string>> &restaurant , vector<string> &shopname ,int good[],int control)//control=0 deliver control=2 pick up
{
string option;
do
{
cout << "*** List Restaurants ***" << endl;
cout << "No. Restaurant Delivery Fee" << endl;
if(control==0)
{
for(int i=1;i<=3;i++)
{
cout<< restaurant[i][0] <<endl;
}
}
if(control==2)
{
for(int i=1;i<=3;i++)
{
cout<< restaurant[i][10] <<endl;
}
}
if(control==0)
{
cout << "Enter number to the restaurant or enter back to the Food Delivery System\n>>>";
}
else if(control==2)
{
cout << "Enter number to the restaurant or enter back to the Pick-Up System\n>>>";
}
getline(cin,option);
if((option[0]-'0'<=shops||option=="back")&&option[0]-'0'>0&&(option.length()==4||option.length()==1))//good input
{
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl ;
continue;
}
if(option=="back")
{
return;
}
else //stoi(option) is the place of store
{
cout << shopname[stoi(option)]<<endl ;
cout << "No. Cuisine Price"<<endl ;
for(int i=1;i<=good[stoi(option)];i++)
{
cout<<restaurant[stoi(option)][i]<<endl;
}
cout <<endl;
continue;
}
}while(true);
}
void Add_Items_to_Cart(vector<string>& cartlist,vector<string>& namelist,int &counter,int control)//control=0 delivery ,control=1 shop control=2 pick up
{
string name;string add_cart;int same=0;int first=0;
cout <<"*** Add Items to Cart ***" << endl;
if(control==0)//delivery
{
if(first==0)
{
cartlist[0]+=",";
first=1;
}
do
{
cout << "Enter item number to add it to cart: " ;
getline(cin,add_cart);
if(add_cart=="1-1"||add_cart=="1-2"||add_cart=="2-1"||add_cart=="2-2"||add_cart=="2-3"||add_cart=="3-1"||add_cart=="3-2"||add_cart=="3-3")//right
{
cartlist[0]+="0";cartlist[0]+=add_cart;cartlist[0]+=",";
cout <<"Added successfully!\n" << endl;
break;
}
else
{
cout <<"Wrong number, please enter again!" << endl;
continue;
}
}while(true);
}
else if(control==1)//shop
{
if(first==0)
{
cartlist[0]+=",";
first=1;
}
do
{
cout << "Enter item number to add it to cart: " ;
getline(cin,add_cart);
if(add_cart=="1-1"||add_cart=="1-2"||add_cart=="2-1"||add_cart=="2-2"||add_cart=="3-1"||add_cart=="3-2"||add_cart=="3-3")//name,11-1,13-3...
{
cartlist[0]+="1";cartlist[0]+=add_cart;cartlist[0]+=",";
cout <<"Added successfully!\n" << endl;
break;
}
else
{
cout <<"Wrong number, please enter again!" << endl;
continue;
}
}while(true);
}//end of shop
if(control==2)//pick up
{
if(first==0)
{
cartlist[0]+=",";
first=1;
}
do
{
cout << "Enter item number to add it to cart: " ;
getline(cin,add_cart);
if(add_cart=="1-1"||add_cart=="1-2"||add_cart=="2-1"||add_cart=="2-2"||add_cart=="2-3"||add_cart=="3-1"||add_cart=="3-2"||add_cart=="3-3")////name,21-1...
{
cartlist[0]+="2";cartlist[0]+=add_cart;cartlist[0]+=",";
cout <<"Added successfully!\n" << endl;
break;
}
else
{
cout <<"Wrong number, please enter again!" << endl;
continue;
}
}while(true);
}
}
void Payment(vector<string>& cartlist,int&counter,int goodvalue[][10],vector<string>dfee,bool& log,vector<string>& namelist )//control=0 delivery ,control=1 shop control=2 pick up
{
string name;int same=0;int deliveramount=0;vector<string> shopfee(10);int y=cartlist[0].length();
int deliverplace[100]={0};int shopplace[100]={0};
shopfee[1]="Delivery Fee NTD 49";
shopfee[2]="Delivery Fee NTD 39";
shopfee[3]="Delivery Fee NTD 29";
int shopvalue[10][10];
shopvalue[1][0]=49;
shopvalue[2][0]=39;
shopvalue[3][0]=29;
shopvalue[1][1]=124;shopvalue[1][2]=99;
shopvalue[2][1]=239;shopvalue[2][2]=129;
shopvalue[3][1]=259;shopvalue[3][2]=165;shopvalue[3][3]=199;
vector <vector<string>> item(10,vector<string>(10));vector <vector<string>> shopitem(10,vector<string>(10));
item[1][1]="Bubble Tea NTD 75";shopitem[1][1]="Tissue NTD 124";
item[1][2]="Cheese-Topped Black Tea NTD 85";shopitem[1][2]="Light Bulbs NTD 99";
item[2][1]="Boneless Salted Crispy Chicken NTD 71";shopitem[2][1]="Shampoo NTD 239";
item[2][2]="Egg Tofu NTD 78";shopitem[2][2]="Toothpaste NTD 129";
item[2][3]="Green Beans NTD 52";shopitem[3][1]="Milk NTD 259";
item[3][1]="Sakura Shrimp Fried Rice NTD 140";shopitem[3][2]="Doritos NTD 165";
item[3][2]="Squid Fried Noodles NTD 130";shopitem[3][3]="Croissant NTD 199";
item[3][3]="Grilled King Oyster Mushrooms NTD 50";
cout << "*** Payment ***" << endl;
if(log==0)
{
cout << "Please log in first.\n"<<endl ;
return;
}
int total=0;bool deliverusage[10]={0};bool shopusage[10]={0};
for(int x=(namelist[0].length()+1);x<y;x+=5)//buy what cart list= name,01-1,21-2,13-3... only count
{
if(deliverusage[static_cast<int>(cartlist[0][x+1])-'0']==0 && static_cast<int>(cartlist[0][x]-'0')==0)//deliver fee
{
deliverusage[static_cast<int>(cartlist[0][x+1])-'0']=1;
total+=goodvalue[static_cast<int>(cartlist[0][x+1])-'0'][0];
deliverplace[deliveramount]=static_cast<int>(cartlist[0][x+1])-'0';//
deliveramount++;
}
if(cartlist[0][x]=='0')//pick up and deliver
{
//cout<<item[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
total+=goodvalue[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0'];
}
else if(cartlist[0][x]=='1')//shop
{
if(shopusage[static_cast<int>(cartlist[0][x+1])-'0']==0)//deliver fee shop version
{
shopusage[static_cast<int>(cartlist[0][x+1])-'0']=1;
total+=shopvalue[static_cast<int>(cartlist[0][x+1])-'0'][0];
deliverplace[deliveramount]=static_cast<int>(cartlist[0][x+1])-'0'+10;// 11,12,13
deliveramount++;
}
//cout<<shopitem[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
total+=shopvalue[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0'];
}
else if(cartlist[0][x]=='2')//pick up and deliver
{
//cout<<item[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
total+=goodvalue[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0'];
}
}
if(total==0)
{
cout << "You don't have any item in cart!\n" << endl;
return;
}
cout<<endl;
cout<<"This is "<<namelist[0]<<"'s order ***"<<endl;
cout << "Item Price"<<endl;
cout << "-------------------------------------------"<<endl ;
for(int x=(namelist[0].length()+1);x<y;x+=5)//buy what cart list= name,01-1,21-2,13-3... only output
{
if(cartlist[0][x]=='0')//pick up and deliver
{
cout<<item[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
}
else if(cartlist[0][x]=='1')//shop
{
cout<<shopitem[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
}
else if(cartlist[0][x]=='2')//pick up and deliver
{
cout<<item[static_cast<int>(cartlist[0][x+1])-'0'][static_cast<int>(cartlist[0][x+3])-'0']<<endl;
}
}
for(int i=0;i<deliveramount;i++)//output delivery fee for food system and shop
{
cout<<dfee[deliverplace[i]]<<endl;
}
cout<<"-------------------------------------------"<<endl;
cout<<"Total NTD "<<total<<"\n"<<endl;
}
void shopsystem(vector<vector<string>> shop,vector<string>& shoplist,int shopgood[],vector<string>& cartlist,vector<string>& namelist,int &counter,bool&log)
{
string option;string listoption;
do
{
cout << "**********************************" << endl;
cout << "*** Shops System ***" << endl;
cout << "**********************************" << endl;
cout << "Enter 1 to List Shops"<<endl;
cout << "Enter 2 to Add Items to Cart"<<endl;
cout << "Enter back to the Homepage\n>>>";
getline(cin,option);
if(option=="back")
{
cout<<endl;
break;
}
if(log==0&&option=="2")
{
cout<<endl;
cout << "Please log in first.\n"<<endl;
continue;
}
if((option[0]-'0'<=2||option=="back")&&option[0]-'0'>0&&(option.length()==4||option.length()==1))//good input
{
cout<<endl;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
if(option=="back")
{
return;
}
else if (option=="1")
{
List_shops(shop,shopgood,shoplist);
}//end of else if
else if (option=="2")
{
Add_Items_to_Cart(cartlist,namelist,counter,1);
}
}while(true);
}
void Member_system(vector<string>&cartlist,int&counter, int goodvalue[][10] ,vector<string>dfee,string &file,vector<string>&namelist,bool &log,bool &load)
{
string option;ifstream memberfile(file,ios::in);
if(!memberfile)// f1
{
do
{
cout << "**********************************\n*** Member system ***"<<endl;
cout << "**********************************"<<endl;
cout << "Enter 1 to Load Member Information"<<endl;
cout << "Enter back to the Homepage\n>>>";
getline(cin,option);
if(option=="1")
{
Load_Member_Information(file,load);
Member_system(cartlist,counter,goodvalue,dfee,file,namelist,log,load);
return;
}
if(option=="back")
{
cout <<endl;
return;
}
else
{
cout << "Unknown command\n"<<endl;
continue;
}
}while(1);
}
else // f2 f3
{
if(log==0)
{
do
{
cout << "**********************************\n*** Member system ***"<<endl;
cout << "**********************************"<<endl;
cout << "Enter 2 to Log In"<<endl;
cout << "Enter 3 to Sign Up"<<endl;
cout << "Enter back to the Homepage\n>>>";
getline(cin,option);
if(option!="2"&&option!="3"&&option!="back")
{
cout << "Unknown command\n"<<endl;
}
}while(option!="2"&&option!="3"&&option!="back");
if(option=="2")
{
cout<<endl;
Log_In(counter, namelist, cartlist,file,log);
Member_system(cartlist,counter,goodvalue,dfee,file,namelist,log,load);
}
if(option=="3")
{
cout<<endl;
Sign_Up( counter, namelist, cartlist,file,log);
Member_system(cartlist,counter,goodvalue,dfee,file,namelist,log,load);
}
if(option=="back")
{
cout<<endl;
return;
}
}
else if(log==1)//f4
{
do
{
cout << "**********************************\n*** Member system ***"<<endl;
cout << "**********************************"<<endl;
cout << "You are log in."<<endl;
cout << "Enter 4 to log out"<<endl;
cout << "Enter back to the Homepage\n>>>";
getline(cin,option);
if(option!="4"&&option!="back")
{
cout << "Unknown command\n"<<endl;
}
}while(option!="4"&&option!="back");
if(option=="4")
{
Log_Out(counter, namelist, cartlist,file,log);
Member_system(cartlist,counter,goodvalue,dfee,file,namelist,log,load);
}
if(option=="back")
{
cout<<endl;
return;
}
}
}
}
void Load_Member_Information(string& file,bool &load)
{
cout<<endl;
cout << "*** Load Member Information ***"<<endl;
cout << "Enter the member file name: ";
getline(cin,file);
ifstream tryfile(file,ios::in);
if(tryfile)
{
cout << "The file "<<file<<" has been loaded...\n"<<endl;
return;
}
else
{
cout << "File could not be opened.\n"<<endl;
return;
}
}
void Log_In(int& counter,vector<string>& namelist,vector<string>& cartlist,string &file,bool &log)
{
string name;string password;ifstream infile(file,ios::in);string file_message;
infile.seekg(0);
cout << "*** Log In ***"<<endl;
cout << "Enter Username: ";
getline(cin,name);
cout << "Enter Password: ";
getline(cin,password);
while(getline(infile,file_message))//file_message: name password
{
if(file_message.substr(0,name.length())==name)//consumer
{
if(file_message.substr(name.length()+5-1,password.length())==password)//password right
{
cout<<"Welcome, "<<name<<"!\n"<<endl;
namelist[0]=name;
cartlist[0]+=name;
counter=1;
log=1;
return;
}
}
}
cout<<"Fail to find your data."<<endl;
cout<<"Please sign up first.\n"<<endl;
return;
}
void Log_Out(int& counter,vector<string>& namelist,vector<string>& cartlist,string &file,bool &log)
{
log=0;
cout << "You are logging out...\n"<<endl;
namelist[0].clear();
cartlist[0].clear();
}
void Sign_Up(int& counter,vector<string>& namelist,vector<string>& cartlist,string &file,bool &log)
{
ofstream outfile(file,ios::app);string name;string password;
cout << "*** Sign Up ***"<<endl;
cout << "Enter Username: ";
getline(cin,name);
cout << "Enter Password: ";
getline(cin,password);
outfile<<endl;
outfile<<name<<" "<<password;
cout << "Welcome! You are now a member of Food Delivery System.\n"<<endl;
}
Editor is loading...
Leave a Comment