Untitled

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
5.9 kB
3
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

void List_Restaurants() {
    while (1) {
        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" << endl;
        cout << ">>>";
        string ch;
        cin >> ch;

        if (ch == "back") {
            cout << endl;
            break;
        } else if (ch == "1") {
            cout << endl;
            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;


        } else if (ch == "2") {
            cout << endl;
            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;

        } else if (ch == "3") {
            cout << endl;
            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;

        } else {
            cout << "Unknown command" << endl;
        }

        cout << endl;
    }
}

void Add_Items_to_Cart(vector<string> &user, vector<vector<int>> &mon) {
    cout << "*** Add Items to Cart ***" << endl;
    cout << "Enter your name: ";
    string s;
    cin >> s;
    bool F = 0;
    int num = -1;

    for (int i = 0; i < user.size(); i++) {
        if (user[i] == s) {
            F = 1;
            num = i;
            break;
        }
    }

    if (!F) {
        num = user.size();
        user.push_back(s);
        mon.push_back(vector<int>(0));
    }

    while (1) {
        int a, b;
        cout << "Enter cuisine number to add it to cart: ";
        scanf("%d-%d", &a, &b);


        if (b <= 3 && b > 0 && a > 0 && a <= 3 && a * 10 + b != 13) {
            mon[num].push_back(a * 10 + b);
            break;
        } else
            cout << "Wrong number, please enter again!" << endl;
    }

    cout << "Added successfully!" << endl;
    cout << endl;
}

void Payment(vector<string> user, vector<vector<int>> mon) {
    string nam[4][4] = {
        {},
        {"", "Bubble Tea", "Cheese-Topped Black Tea"},
        {"", "Boneless Salted Crispy Chicken", "Egg Tofu", "Green Beans"},
        {"", "Sakura Shrimp Fried Rice", "Squid Fried Noodles", "Grilled King Oyster Mushrooms"}
    };
    int prz[4][4] = {
        {0, 29, 49, 39},
        {0, 75, 85},
        {0, 71, 78, 52},
        {0, 140, 130, 50}
    };
    cout << "*** Payment ***" << endl;
    cout << "Enter your name: ";
    string s;
    cin >> s;
    bool f = 0;
    int num = 0;

    for (int i = 0; i < user.size(); i++) {
        if (user[i] == s) {
            f = 1;
            num = i;
            break;
        }
    }

    if (f) {
        cout << endl;
        cout << "*** This is " << s << "'s order ***" << endl;
        cout << "Item                               Price" << endl;
        cout << "-------------------------------------------" << endl;

        vector<int> de;
        int sum = 0;

        for (int i : mon[num]) {
            int a = i / 10, b = i % 10;
            cout << left << setw(35) << nam[a][b] << "NTD" << right << setw(5) << prz[a][b] << endl;
            sum += prz[a][b];
            bool ff = 0;

            for (int j : de)
                if (j == a)
                    ff = 1;

            if (!ff)
                de.push_back(a);
        }

        for (int i : de) {
            cout << left << setw(35) << "Delivery Fee" << "NTD" << right << setw(5) << prz[0][i] << endl;
            sum += prz[0][i];
        }

        cout << "-------------------------------------------" << endl;
        cout << left << setw(35) << "Total" << "NTD" << right << setw(5) << sum << endl;
    } else {
        cout << "You don't have any item in cart!" << endl;
    }

    cout << endl;

}

signed main() {

    vector<string> user;
    vector<vector<int>> mon;

    while (1) {
        cout << "**********************************" << endl;
        cout << "***    Food Delivery System    ***" << endl;
        cout << "**********************************" << 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" << endl;
        cout << ">>>";
        string ch;
        cin >> ch;

        if (ch == "exit()")
            break;

        if (ch == "1") {
            cout << endl;
            List_Restaurants();
        } else if (ch == "2") {
            cout << endl;
            Add_Items_to_Cart(user, mon);
        } else if (ch == "3") {
            cout << endl;
            Payment(user, mon);

        } else {
            cout << "Unknown command" << endl;
            cout << endl;
        }
    }

}
Leave a Comment