Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please correct my code and explain wrong using comment(//) in line. So, i can un

ID: 3540299 • Letter: P

Question

Please correct my code and

explain wrong using comment(//) in line.
So, i can understand my wrong.

Thank.



My code:


#include <iostream>
#include <string>

using namespace std;

class Pizza
{
    private:
            string name;
            int size, quantity;
            float price, totalprice;

    public:
            void menu()
            {

                cout<<"[1] - BBQ Chicken"<<endl;
                cout<<"[2] - Island Delight"<<endl;
                cout<<"[3] - Hawaiian Delight"<<endl;

            }

            void setSelection()
            {
                int menu;

                cout<<"Enter your choice based on the number:"<<endl;
                cin>>menu;

                switch(menu)
                {

                    case 1:
                    name="BBQ Chicken";
                    break;

                    case 2:
                    name="Island Delight";
                    break;

                    case 3:
                    name="Hawaiian Delight";
                    break;

                }


            }

            void setSizeQuantity()
            {

                cout<<"Please enter size [R / L]:"<<endl;
                cin>>size;

                cout<<"Please enter quantity:"<<endl;
                cin>>quantity;

                if(name=="BBQ Chicken" && size=='R')
                {
                    price=25.00;
                }

                else if(name=="BBQ Chicken" && size=='L')
                {
                    price=35.30;
                }

                else if(name=="Island Delight" && size=='R')
                {
                    price=22.00;
                }

                else if(name=="Island Delight" && size=='L')
                {
                    price=33.30;
                }

                else if(name=="Hawaiian Delight" && size=='R')
                {
                    price=24.50;
                }

                else if(name=="Hawaiian Delight" && size=='L')
                {
                    price=36.60;
                }

            }

            void display()
            {

                cout<<"Thank you for odering"<<endl;
                cout<<"----Your pizza details----"<<endl;
                cout<<"Pizza : "<<name<<endl;
                cout<<"Quantity : "<<quantity<<endl;
                cout<<"Price per pizza : "<<price<<endl;

                totalprice=price*quantity;

                cout<<"Total payment : " <<totalprice<<endl;

            }
};

int main()
{
    Pizza * dynamically = new Pizza;

    char decision;

    do
    {

    cout<<"Would you like to order a pizza [y/n]:";
    cin>>decision;

    dynamically->menu();
    dynamically->setSelection();
    dynamically->setSizeQuantity();
    dynamically->display();

    delete dynamically;

    }

    while(decision=='y'||decision=='Y');
    {

        if(decision=='n'||decision=='N')

            return 0;

    }

}



Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

class Pizza
{
    private:
            string name;
            //you have taken size as int but using as char
            char size;
            int quantity;
            float price, totalprice;

    public:
            void menu()
            {

                cout<<"[1] - BBQ Chicken"<<endl;
                cout<<"[2] - Island Delight"<<endl;
                cout<<"[3] - Hawaiian Delight"<<endl;

            }

            void setSelection()
            {
                int menu;

                cout<<"Enter your choice based on the number:"<<endl;
                cin>>menu;

                switch(menu)
                {

                    case 1:
                    name="BBQ Chicken";
                    break;

                    case 2:
                    name="Island Delight";
                    break;

                    case 3:
                    name="Hawaiian Delight";
                    break;

                }


            }

            void setSizeQuantity()
            {

                cout<<"Please enter size [R / L]:"<<endl;
                cin>>size;

                cout<<"Please enter quantity:"<<endl;
                cin>>quantity;

                if(name=="BBQ Chicken" && size=='R')
                {
                    price=25.00;
                }

                else if(name=="BBQ Chicken" && size=='L')
                {
                    price=35.30;
                }

                else if(name=="Island Delight" && size=='R')
                {
                    price=22.00;
                }

                else if(name=="Island Delight" && size=='L')
                {
                    price=33.30;
                }

                else if(name=="Hawaiian Delight" && size=='R')
                {
                    price=24.50;
                }

                else if(name=="Hawaiian Delight" && size=='L')
                {
                    price=36.60;
                }

            }

            void display()
            {

                cout<<"Thank you for odering"<<endl;
                cout<<"----Your pizza details----"<<endl;
                cout<<"Pizza : "<<name<<endl;
                cout<<"Quantity : "<<quantity<<endl;
                cout<<"Price per pizza : "<<price<<endl;

                totalprice=price*quantity;

                cout<<"Total payment : " <<totalprice<<endl;

            }
};

int main()
{
    Pizza * dynamically = new Pizza;

    char decision;
   
    // your program were executing even if you give "n" as input
    cout<<"Would you like to order a pizza [y/n]:";
    cin>>decision;
    while(decision=='y'||decision=='Y')
    {
    dynamically->menu();
    dynamically->setSelection();
    dynamically->setSizeQuantity();
    dynamically->display();

    delete dynamically;
    cout<<"Would you like to order a pizza [y/n]:";
    cin>>decision;

    }
            return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote