Question: C++ CODE Using inheritance and dynamic allocation You are starting up your own fast-food restaurant and want to offer the following items: -----------PART A ****ALREADY
C++ CODE Using inheritance and dynamic allocation
You are starting up your own fast-food restaurant and want to offer the following items:
-----------PART A ****ALREADY SOLVED-----------
(1) burgers with either: fish, beef, chicken or cheese (and beef). Each of these cost $3.50. (Pricey!)
(2) drinks filled with: coke, sprite or juice. Large cups cost $0.99, Medium costs $0.75 and Small $0.65.
------------PART B** what is needed to be added----------------------------
(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.
You may also assume less than 100 items will be ordered.
---------ADD TO PART A's CODE** ***fix and add to it as desired------------------
#include
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[100]; 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("large coke", 0.99, "large"); else if(cupSize == 'm') food[count] = new Drink("medium coke", 0.75, "medium"); else food[count] = new Drink("small coke", 0.65, "small"); else if(drinkType == 's') if(cupSize == 'l') food[count] = new Drink("large sprite", 0.99, "large"); else if(cupSize == 'm') food[count] = new Drink("medium sprite", 0.75, "medium"); else food[count] = new Drink("small sprite", 0.65, "small"); else if(drinkType == 'j') if(cupSize == 'l') food[count] = new Drink("large juice", 0.99, "large"); else if(cupSize == 'm') food[count] = new Drink("medium juice", 0.75, "medium"); else food[count] = new Drink("small 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 burger", 3.5); else if(foodType == 'b') food[count] = new Food("beef burger", 3.5); else if(foodType == 'c') food[count] = new Food("chicken burger", 3.5); else food[count] = new Food("cheese burger", 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; } } }
------------------------------------------------------------
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
Is this correct? (y )
n
What item do you wish to remove?
5
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
6: Price: 3.5, Item: fish burger
Total: 7.28
Is this correct? (y )
y
-------------------------------------------------
C++ Code
Thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
