Untitled
unknown
plain_text
2 years ago
10 kB
4
Indexable
#include <iostream> #include <string> #include <vector> using namespace std; void List_Restaurants();//list the restaurants with delivery fee void Add_Items_to_Cart(vector<string>&, vector<string>&,int &);//input his name and the cuisine number that he wants to add to the cart void Payment(vector<string>&,int&); //input his name and show all of the items in his cart int main() { string do_what;vector<string> cartlist;int counter=0; vector<string>namelist; 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 3 to Payment" << endl; cout << "Enter exit() to quit\n>>>" ; getline(cin,do_what); if(do_what=="1"||do_what=="2"||do_what=="3"||do_what=="exit()")//good input { cout<<endl; } else { cout << "Unknown command\n"<<endl ; continue; } if(do_what=="1") { List_Restaurants(); } else if(do_what=="2") { Add_Items_to_Cart(cartlist,namelist,counter); } else if(do_what=="3") { Payment(cartlist,counter); } }while(do_what!="exit()"); return 0; } void List_Restaurants() { string option; do { cout << "*** List Restaurants ***" << endl; cout << "No. Restaurant Delivery Fee" << endl; cout << "1 Wang shih jhen sin tang NTD 29" << endl; cout << "2 Taiwan di er jia yan su ji NTD 49" << endl; cout << "3 Fang kong nai ba NTD 39" << endl; cout << "Enter number to the restaurant or enter back to the main menu\n>>>"; getline(cin,option); if(option=="1"||option=="2"||option=="3"||option=="back")//good input { cout<<endl; } else { cout << "Unknown command\n"<<endl ; continue; } if(option=="back") { cout<<endl; return; } if(option=="1") { cout << "*** Wang shih jhen sin tang ***"<<endl ; cout << "No. Cuisine Price"<<endl ; cout << "1-1 Bubble Tea NTD 75"<<endl ; cout << "1-2 Cheese-Topped Black Tea NTD 85"<<endl ; cout <<endl; continue; } if(option=="2") { cout << "*** Taiwan di er jia yan su ji ***"<<endl ; cout << "No. Cuisine Price"<<endl ; cout << "2-1 Boneless Salted Crispy Chicken NTD 71"<<endl ; cout << "2-2 Egg Tofu NTD 78"<<endl ; cout << "2-3 Green Beans NTD 52"<<endl ; cout <<endl; continue; } if(option=="3") { cout << "*** Fang kong nai ba ***"<<endl ; cout << "No. Cuisine Price"<<endl ; cout << "3-1 Sakura Shrimp Fried Rice NTD 140"<<endl ; cout << "3-2 Squid Fried Noodles NTD 130"<<endl ; cout << "3-3 Grilled King Oyster Mushrooms NTD 50"<<endl ; cout <<endl; continue; } }while(true); } void Add_Items_to_Cart(vector<string>& cartlist,vector<string>& namelist,int &counter) { string name;string add_cart;int same=0;int first=0; cout <<"*** Add Items to Cart ***" << endl; cout << "Enter your name: "; getline(cin,name); if(counter==0)// first name { namelist[counter]=name; cartlist[counter]=name; cartlist[counter]+=","; same=1;first=1; do { cout << "Enter cuisine number to add it to cart: " ; 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[counter]+=add_cart;cartlist[counter]+=","; cout <<"Added successfully!\n" << endl; break; } else { cout <<"Wrong number, please enter again!" << endl; continue; } }while(true); counter++; } for(int i=0;i<counter;i++)//name used? { if(namelist[i]==name&&first==0)//name same { same=1; } if(same==1)//name same { do { cout << "Enter cuisine number to add it to cart: " ; 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[i]+=add_cart; cartlist[i]+=","; cout <<"Added successfully!\n" << endl; break; } else { cout <<"Wrong number, please enter again!" << endl; continue; } }while(true); } } if(same==0&&first==0)//new name { namelist[counter]=name; cartlist[counter]=name; cartlist[counter]+=","; counter++; do { cout << "Enter cuisine number to add it to cart: " ; 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[counter]+=add_cart;cartlist[counter]+=","; cout <<"Added successfully!\n" << endl; break; } else { cout <<"Wrong number, please enter again!" << endl; continue; } }while(true); same=0; } } void Payment(vector<string>& cartlist,int&counter) { string name;int same=0;int deliver1=0;int deliver2=0;int deliver3=0; string item1_1="Bubble Tea NTD 75"; string item1_2="Cheese-Topped Black Tea NTD 85"; string item2_1="Boneless Salted Crispy Chicken NTD 71"; string item2_2="Egg Tofu NTD 78"; string item2_3="Green Beans NTD 52"; string item3_1="Sakura Shrimp Fried Rice NTD 140"; string item3_2="Squid Fried Noodles NTD 130"; string item3_3="Grilled King Oyster Mushrooms NTD 50"; string dfee1="Delivery Fee NTD 29"; string dfee2="Delivery Fee NTD 49"; string dfee3="Delivery Fee NTD 39"; cout << "*** Payment ***" << endl; cout << "Enter your name: " ; getline(cin,name);cout<<endl; for(int i=0;i<counter;i++)//which cartlist { if(cartlist[i].substr(0,name.length())==name)//consumer { same=1;int total=0; cout << "*** This is "<<name<<"'s order ***"<<endl ; cout << "Item Price"<<endl ; cout << "-------------------------------------------"<<endl ; for(int x=name.length()+1;x<cartlist[i].length();x+=4)//buy what { if(cartlist[i][x]=='1') { deliver1=1; if(cartlist[i][x+2]=='1') { total+=75;cout<<item1_1<<endl; } else if(cartlist[i][x+2]=='2') { total+=85;cout<<item1_2<<endl; } } if(cartlist[i][x]=='2') { deliver2=1; if(cartlist[i][x+2]=='1') { total+=71;cout<<item2_1<<endl; } if(cartlist[i][x+2]=='2') { total+=78;cout<<item2_2<<endl; } if(cartlist[i][x+2]=='3') { total+=52;cout<<item2_3<<endl; } } if(cartlist[i][x]==3) { deliver3=1; if(cartlist[i][x+2]=='1') { total+=140;cout<<item3_1<<endl; } if(cartlist[i][x+2]=='2') { total+=130;cout<<item3_2<<endl; } if(cartlist[i][x+2]=='3') { total+=50;cout<<item3_3<<endl; } } } if(deliver1==1) { total+=29; } if(deliver2==1) { total+=49; } if(deliver3==1) { total+=39; } cout<<"-------------------------------------------"<<endl; cout<<"Total NTD "<<total<<"\n"<<endl; break; } } if(same==0) { cout << "You don't have any item in cart!\n" << endl; } }
Editor is loading...
Leave a Comment