Untitled
unknown
plain_text
2 years ago
26 kB
9
Indexable
#include <iostream>
#include <string>
#include <vector>
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); //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);
void pickup(vector<string> &, vector<string> &, int &);
void List_shops(vector<vector<string>> &shop, int shopgood[], vector<string> &shoplist);
int main() {
string Do;
int shopgood[10];
shopgood[1] = 2;
shopgood[2] = 2;
shopgood[3] = 3;
string do_what;
vector<string> cartlist(100);
int counter = 0;
vector<string>shoplist(10);
vector<vector<string>> restaurant(10, vector<string>(20));
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 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()") { //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 (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);
} 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 (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 == "4") {
Payment(cartlist, counter, goodvalue, dfee);
}
} 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;
cout << "Enter your name: ";
getline(cin, name);
if (control == 0) { //delivery
if (counter == 0) { // first name
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
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[counter] += "0";
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 item number to add it to cart: " ;//cuisine
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[i] += "0";
cartlist[i] += add_cart;
cartlist[i] += ",";
cout << "Added successfully!\n" << endl;
return;
} else {
cout << "Wrong number, please enter again!" << endl;
continue;
}
} while (true);
}
}
if (same == 0 && first == 0) { //new name not first
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
counter++;
do {
cout << "Enter item number to add it to cart: " ;//cuisine
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,01-1...
cartlist[counter - 1] += "0";
cartlist[counter - 1] += add_cart;
cartlist[counter - 1] += ",";
cout << "Added successfully!\n" << endl;
break;
} else {
cout << "Wrong number, please enter again!" << endl;
continue;
}
} while (true);
}
} else if (control == 1) { //shop
if (counter == 0) { // first name
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
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[counter] += "1";
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 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") { //right
cartlist[i] += "1";
cartlist[i] += add_cart;
cartlist[i] += ",";
cout << "Added successfully!\n" << endl;
return;
} else {
cout << "Wrong number, please enter again!" << endl;
continue;
}
} while (true);
}
}
if (same == 0 && first == 0) { //new name not first
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
counter++;
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") { //right
cartlist[counter - 1] += "1";
cartlist[counter - 1] += add_cart;
cartlist[counter - 1] += ",";
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 (counter == 0) { // first name
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
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[counter] += "2";
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 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[i] += "2";
cartlist[i] += add_cart;
cartlist[i] += ",";
cout << "Added successfully!\n" << endl;
return;
} else {
cout << "Wrong number, please enter again!" << endl;
continue;
}
} while (true);
}
}
if (same == 0 && first == 0) { //new name not first
namelist[counter] = name;
cartlist[counter] = name;
cartlist[counter] += ",";
counter++;
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,1-1...
cartlist[counter - 1] += "2";
cartlist[counter - 1] += add_cart;
cartlist[counter - 1] += ",";
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) { //control=0 delivery ,control=1 shop control=2 pick up
string name;
int same = 0;
int deliveramount = 0;
vector<string> shopfee(10);
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;
cout << "Enter your name: " ;
getline(cin, name);
for (int i = 0; i < counter; i++) { //which cartlist
if (cartlist[i].substr(0, name.length()) == name && cartlist[i].substr(name.length(), 1) == ",") { //consumer
same = 1;
int total = 0;
bool deliverusage[10] = {0};
bool shopusage[10] = {0};
cout << endl;
cout << "*** This is " << name << "'s order ***" << endl ;
cout << "Item Price" << endl ;
cout << "-------------------------------------------" << endl ;
int y = cartlist[i].length();
for (int x = (name.length() + 1); x < y; x += 5) { //buy what cart list= name,01-1,21-2,13-3...
if (deliverusage[static_cast<int>(cartlist[i][x + 1]) - '0'] == 0 &&
static_cast<int>(cartlist[i][x] - '0') == 0) { //deliver fee
deliverusage[static_cast<int>(cartlist[i][x + 1]) - '0'] = 1;
total += goodvalue[static_cast<int>(cartlist[i][x + 1]) - '0'][0];
deliverplace[deliveramount] = static_cast<int>(cartlist[i][x + 1]) - '0'; //
deliveramount++;
}
if (cartlist[i][x] == '0') { //pick up and deliver
cout << item[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>(cartlist[i][x + 3]) - '0'] << endl;
total += goodvalue[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>(cartlist[i][x + 3]) - '0'];
}
if (cartlist[i][x] == '1') { //shop
if (shopusage[static_cast<int>(cartlist[i][x + 1]) - '0'] == 0) { //deliver fee shop version
shopusage[static_cast<int>(cartlist[i][x + 1]) - '0'] = 1;
total += shopvalue[static_cast<int>(cartlist[i][x + 1]) - '0'][0];
deliverplace[deliveramount] = static_cast<int>(cartlist[i][x + 1]) - '0' + 10; // 11,12,13
deliveramount++;
}
cout << shopitem[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>
(cartlist[i][x + 3]) - '0'] << endl;
total += shopvalue[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>(cartlist[i][x + 3]) - '0'];
}
if (cartlist[i][x] == '2') { //pick up and deliver
cout << item[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>(cartlist[i][x + 3]) - '0'] << endl;
total += goodvalue[static_cast<int>(cartlist[i][x + 1]) - '0'][static_cast<int>(cartlist[i][x + 3]) - '0'];
}
}
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;
break;
}
}
if (same == 0) {
cout << "You don't have any item in cart!\n" << endl;
}
}
void shopsystem(vector<vector<string>> shop, vector<string> &shoplist, int shopgood[],
vector<string> &cartlist, vector<string> &namelist, int &counter) {
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[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);
}
Editor is loading...
Leave a Comment