Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
11 kB
3
Indexable
Never
#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(100);int counter=0;

    vector<string>namelist(100);
    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>>>" ;
        cin.sync();
        getline(cin,do_what);
        if(do_what=="exit()")
        {
            cout<<"\n";
            return 0;
        }

        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")
        {
            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]+=",";
         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;

                  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 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);


     }


}
void Payment(vector<string>& cartlist,int&counter)
{
    string name;int same=0;int deliver1=0;int deliver2=0;int deliver3=0;int deliverfee[3]={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);
    for(int i=0;i<counter;i++)//which cartlist
    {
        if(cartlist[i].substr(0,name.length())==name)//consumer
           {
                same=1;int total=0;int time=0;int usage1=0;int usage2=0;int usage3=0;
                cout<<endl;
                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')
                    {
                        if(deliverfee[time]==0&&time<3&&usage1!=1)
                        {
                            deliverfee[time]=1;
                            time++;usage1=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')
                    {
                        if(deliverfee[time]==0&&time<3&&usage2!=1)
                        {
                            deliverfee[time]=2;
                            time++;usage2=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')
                    {
                        if(deliverfee[time]==0&&time<3&&usage3!=1)
                        {
                            deliverfee[time]=3;
                            time++;usage3=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;

                        }
                    }

                }
                for(int i=0;i<3;i++)
                {
                    if(deliverfee[i]==3)
                    {
                        total+=39;cout<<dfee3<<endl;
                    }
                    else if(deliverfee[i]==2)
                    {
                        total+=49;cout<<dfee2<<endl;
                    }
                    else if(deliverfee[i]==1)
                    {
                        total+=29;cout<<dfee1<<endl;
                    }
                }

                cout<<"-------------------------------------------"<<endl;
                cout<<"Total                              NTD  "<<total<<"\n"<<endl;
                break;


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


}
Leave a Comment