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

[C++] Using inheitance and dynamic allocation: You are starting up your own fast

ID: 3830842 • Letter: #

Question

[C++] Using inheitance and dynamic allocation:

You are starting up your own fast-food restraunt and want to offer the following items: (1) burgers with either: fish, beef, chicken or cheese (and beef). Each of these cost $3.50. (Pricey!) (2) drinks filled with: coke, sprte or juice. Large cups cost $0.99, Medium costs $0.75 and Small $0.65. (3) all salads cost $1.30, they get to choose their own dressing (anything), then ask them if they want cheese on top for an extra $0.30. (4) fries cost $1.49 for large, $0.99 for medium and $0.79 for small

Repeatedly ask the user what they want to order until they choose the check-out. After they select check-out, show everything in the order that they ordered it and the total.

Additionally, when they checkout add numbers to each item (starting at 1) and ask them if the order is correct. If they say the order is incorrect, ask them which number they want removed and then re-show them the order (repeat as many times as necessary). Do not re-number the order after items have been removed (this should make it easier for you).

You can assume only valid options will be entered.

************USE INHERITANCE FOR THIS PROBLEM*******************

Example (user input is in bold):

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

d

Do you want (c)oke, (s)prite or (j)uice?

j

What size cup?  (l)arge, (m)edium or (s)mall

l

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

s

Do you want a (c)hicken, (f)ruit or (t)urkey salad?

c

What type of dressing?

ranch

Do you want to add cheese for $0.30?

y

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

s

Do you want a (c)hicken, (f)ruit or (t)urkey salad?

f

What type of dressing?

little tiny cucumbers shaped like ponies

Do you want to add cheese for $0.30?

n

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

f

What size?  (l)arge, (m)edium or (s)mall

l

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

f

What size?  (l)arge, (m)edium or (s)mall

s

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

b

Do you want to have (f)ish, (b)eef, (c)hicken or ch(e)ese?

f

Would you like to order a (d)rink, (b)urger, (s)alad, (f)ries or (c)heck out?

c

Your order is:

1: Price: 0.99, Item: large juice

2: Price: 1.6, Item: chicken salad with ranch and cheese

3: Price: 1.3, Item: fruit salad with little tiny cucumbers shaped like ponies

4: Price: 1.49, Item: large fries

5: Price: 0.79, Item: small fries

6: Price: 3.5, Item: fish burger

Total: 9.67 Is this correct? (y )

n

What item do you wish to remove?

2

Your order is:

1: Price: 0.99, Item: large juice

3: Price: 1.3, Item: fruit salad with little tiny cucumbers shaped like ponies

4: Price: 1.49, Item: large fries

5: Price: 0.79, Item: small fries

6: Price: 3.5, Item: fish burger

Total: 8.07

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;
class Food
{
    string foodType;
    double cost;
    public:
        Food(string foodType, double cost)
        {
           this->foodType = foodType;
           this->cost = cost;
        }
        string getFoodType() { return foodType; }
        double getCost() { return cost; }
        void printOrder()
        {
           cout << "Price: " << fixed << setprecision(2) << cost << ", Item: " << foodType << endl;
        }
};
class Drink : public Food
{
    string size;
    public:
        Drink(string foodType, double cost, string size) : Food(foodType, cost)
        {
           this->size = size;
        }
        string getSize() { return size; }
        void printOrder()
        {
           cout << "Price: " << fixed << setprecision(2) << getCost() << ", Item: " << size << " " << getFoodType() << endl;
        }
};
int main()
{
    char foodType, cupSize, drinkType;
    Food *food[10];
    int count = 0;
    double total;
    while(true)
    {
       cout << "Would you like to order a (d)rink, (b)urger or (c)heck out?" << endl;
       cin >> foodType;
       switch(foodType)
       {
          case 'd':
                      cout << "Do you want (c)oke, (s)prite or (j)uice?" << endl;
                      cin >> drinkType;
                      cout << "What size cup? (l)arge, (m)edium or (s)mall" << endl;
                      cin >> cupSize;
                      if(drinkType == 'c')
                          if(cupSize == 'l')
                              food[count] = new Drink("coke", 0.99, "large");
                          else if(cupSize == 'm')
                              food[count] = new Drink("coke", 0.75, "medium");
                          else
                              food[count] = new Drink("coke", 0.65, "small");
                      else if(drinkType == 's')
                          if(cupSize == 'l')
                              food[count] = new Drink("sprite", 0.99, "large");
                          else if(cupSize == 'm')
                              food[count] = new Drink("sprite", 0.75, "medium");
                          else
                              food[count] = new Drink("sprite", 0.65, "small");
                      else if(drinkType == 'j')
                          if(cupSize == 'l')
                              food[count] = new Drink("juice", 0.99, "large");
                          else if(cupSize == 'm')
                              food[count] = new Drink("juice", 0.75, "medium");
                          else
                              food[count] = new Drink("juice", 0.65, "small");
                          count++;  
                          break;  
          case 'b':
                      cout << "Do you want to have (f)ish, (b)eef, (c)hicken or ch(e)ese?" << endl;
                      cin >> foodType;
                      if(foodType == 'f')
                          food[count] = new Food("fish", 3.5);
                      else if(foodType == 'b')
                          food[count] = new Food("beef", 3.5);
                      else if(foodType == 'c')
                          food[count] = new Food("chicken", 3.5);
                      else
                          food[count] = new Food("cheese", 3.5);
                      count++;  
                      break;  
          case 'c':
                      for(int i = 0; i < count; i++)
                      {
                         food[i]->printOrder();
                         total += food[i]->getCost();
                      }  
                      cout << "Total: " << fixed << setprecision(2) << total << endl;
                      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