Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
8.1 kB
0
Indexable
Never
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void List_Restaurants() {
    string option_rest;
    int rest = 0;

    cout << "\n*** List Restaurants ***\nNo. Restaurant                         Delivery Fee\n";
    cout << "1   Wang shih jhen sin tang            NTD   29\n2   Taiwan di er jia yan su ji         NTD   49\n3   Fang kong nai ba                   NTD   39\n";
    cout << "Enter number to the restaurant or enter back to the main menu \n>>>";
    cin >> option_rest;

    //change option to integer make it can be switched
    if (option_rest == "1")
        rest = 1;
    else if (option_rest == "2")
        rest = 2;
    else if (option_rest == "3")
        rest = 3;
    else if (option_rest == "back")
        rest = 4;

    //switch and print each restaurant menu
    switch(rest) {
    case 1 :
        cout << "\n*** Wang shih jhen sin tang ***\nNo. Cuisine                            Price\n";
        cout << "1-1 Bubble Tea                         NTD   75\n1-2 Cheese-Topped Black Tea            NTD   85\n" ;
        List_Restaurants();
        break;
    case 2 :
        cout << "\n*** Taiwan di er jia yan su ji ***\nNo. Cuisine                            Price";
        cout << "\n2-1 Boneless Salted Crispy Chicken     NTD   71\n2-2 Egg Tofu                           NTD   78\n2-3 Green Beans                        NTD   52\n" ;
        List_Restaurants();
        break;
    case 3 :
        cout << "\n*** Fang kong nai ba ***\nNo. Cuisine                            Price";
        cout << "\n3-1 Sakura Shrimp Fried Rice           NTD  140\n3-2 Squid Fried Noodles                NTD  130\n3-3 Grilled King Oyster Mushrooms      NTD   50\n" ;
        List_Restaurants();
        break;
    case 4 :
        cout << endl;
        break;
    default :
        cout << "Unknown command\n";
        List_Restaurants();
        break;
    }

}


void Add_Items_to_Cart(vector <vector <int>> userscart , vector <string> usersname) {

    string user_name;
    string food_str;
    int user_name_num = 9;
    int food_choice_num = 0;
    int endd = 0;
    int no_name = 0;




    cout << "\n*** Add Items to Cart ***" << endl;
    cout << "Enter your name: ";
    cin >> user_name;
    //cout << user_name;

    //check whether the name have been entered

    for (int i = 0 ; i < usersname.size() ; i++) {

        if (user_name == usersname[i]) {
            //cout << "hi";
            user_name_num = i;
            no_name = 1;
            break;
        }
        cout << user_name << " " << usersname[i];

            //cout << usersname[user_name_num] << "   ";

    }

    if (no_name == 0) {
        usersname.push_back(user_name);
        user_name_num = usersname.size()-1;
        //cout << user_name << "is in" << user_name_num << "   " << usersname[user_name_num] << "size:" << usersname.size();
    }

    /*for (int j = 0 ; j < usersname.size() ; j++) {
                cout << usersname[j] << " ";
            }*/




    //put item to the relative cart
    do {
        cout << "Enter cuisine number to add it to cart: ";
        cin >> food_str;
        if (food_str != "1-1" && food_str != "1-2" && food_str != "2-1" && food_str != "2-2" && food_str != "2-3" && food_str != "3-1" && food_str != "3-2" && food_str != "3-3") {
            endd = 1;
            cout << "Wrong number, please enter again!\n";
            continue;
        }else {
            food_choice_num = ((int)(food_str[0] - '0'))*10 + (int)(food_str[2] - '0');
            //cout << food_choice_num << endl;

            userscart[user_name_num].push_back(food_choice_num);
            //cout << "fu";

            cout << "Added successfully!\n\n";
            break;
        }
    }while(endd == 1);


}

void Payment(vector <vector <int>> price,vector <string> usersname,vector <vector <int>> user_cart,vector <vector <string>> cuisine_name) {
    string user_name;
    int user_num = 0;
    int total_price = 0;
    int a = 0, b = 0;
    int endd = 1;
    int no_name = 0;




    cout << "*** Payment ***\nEnter your name: ";
    cin >> user_name;

    //check user have items in their cart
    for (int i = 0 ; i < usersname.size() ; i++) {

        if (user_name == usersname[i]) {
            user_num = i;
            no_name = 1;
            cout << "hi";
        }

        cout << user_num << usersname[user_num] << endl;

    }

    if (no_name = 0) {
            cout << "You don't have any item in cart!\n\n";
            endd = 0;
        }

    if (endd == 1) {
        cout << "*** This is " << usersname[user_num] << "'s order ***" << endl;
        cout << "Item                               Price\n-------------------------------------------";


        for (int i = 0 ; i < user_cart[user_num].size() ; i++) {
            a = user_cart[user_num][i]/10;//since usersname vector start at i = 1
            b = user_cart[user_num][i] - 10*a;
            cout << cuisine_name[a][b] << endl;
            total_price += price[a][b];
        }

        for (int i = 0 ; i < user_cart[user_num].size() ; i++) {
            if (user_cart[user_num][i] == 11 || user_cart[user_num][i] == 12)
                cout << "Delivery Fee                       NTD   29";
                total_price += 29;
                break;
        }
        for (int i = 0 ; i < user_cart[user_num].size() ; i++) {
            if (user_cart[user_num][i] == 21 || user_cart[user_num][i] == 22 || user_cart[user_num][i] == 23)
                cout << "Delivery Fee                       NTD   49";
                total_price += 49;
                break;
        }
        for (int i = 0 ; i < user_cart[user_num].size() ; i++) {
            if (user_cart[user_num][i] == 31 || user_cart[user_num][i] == 32 || user_cart[user_num][i] == 33)
                cout << "Delivery Fee                       NTD   39";
                total_price += 39;
                break;
        }

        cout << "-------------------------------------------\nTotal                              NTD  " << total_price << endl;
    }



}




int main()
{
    string option;

    vector <vector <string>> cuisine_name = {
        {{},{},{},{}},
        {{},{"Bubble Tea                         NTD   75"},{"Cheese-Topped Black Tea            NTD   85"},{}},
        {{},{"Boneless Salted Crispy Chicken     NTD   71"},{"Egg Tofu                           NTD   78"},{"Green Beans                        NTD   52"}},
        {{},{"Sakura Shrimp Fried Rice           NTD  140"},{"Squid Fried Noodles                NTD  130"},{"Grilled King Oyster Mushrooms      NTD   50"}}
        };
    vector <vector <int>> price = {
        {0,0,0,0}, {0,75,85,0}, {0,71,78,52}, {0,140,130,50}
        };
    vector <vector <int>> user_cart(10);
    vector <string> usersname;

    do {
        int func = 0;
        cout << "**********************************\n***    Food Delivery System    ***\n**********************************\nEnter 1 to List Restaurants\n";
        cout << "Enter 2 to Add Items to Cart\nEnter 3 to Payment\nEnter exit() to quit";
        cout << "\n>>>";
        cin >> option;

        if (option == "1")
            func = 1;
        else if (option == "2")
            func = 2;
        else if (option == "3")
            func = 3;
        else if (option == "exit()")
            func = 4;


        switch(func) {
            case 1 :
                List_Restaurants();
                break;
            case 2 :
                Add_Items_to_Cart(user_cart,usersname);
                break;
            case 3 :
                Payment(price,usersname,user_cart,cuisine_name);
                break;
            case 4 :
                break;
            default :
                cout << "Unknown command";
        }

    }while(option != "exit()");

    return 0;
}
Leave a Comment