Question: C++ Adding Code for Pizza Program I have the following code below and I require some additional work for it: 1. Add code so that
C++ Adding Code for Pizza Program
I have the following code below and I require some additional work for it:
1. Add code so that more than 1 pizza can be ordered.
2. Use a map to determine the price of pizzas.
3. Print all the pizzas at the end.
The code below should work as a base:
#include
using namespace std;
class pizza { private: int type; int size; int num_top;
public: //mutator pizza(int t, int s, int n) { type = t; size = s; num_top = n; }
//accessor
void dis() { cout << "pizza type:" << endl; switch (type) { case 1: cout << "deep dish" << endl; break; case 2: cout << "hand tossed" << endl; break; case 3: cout << "pan" << endl; } printf("pizza size: "); switch (size) { case 1: cout << "small" << endl; break; case 2: cout << "medium" << endl; break; case 3: cout << "large" << endl; }
cout << "number of toppings:" << num_top << endl; } int price() { int total = 0; if (size == 1) { total += 10; } else if (size == 2) { total += 14; } else if (size == 3) { total += 17; } total = total + (num_top > 0 ? num_top * 2 : 1); return total; } };
class order { private: std::vector
public: void add_pizza(int typ, int siz, int no) { ordr.push_back(pizza(typ, siz, no)); } void set_na(std::string na) { name = na; } void set_num(std::string num) { phone_number = num; } void ret() { int tot = 0; cout << "your name" << name << endl; cout << "your contact number" << phone_number << endl; for (int i = 0; i < ordr.size(); i++) {
cout << "pizza number:-" << i + 1; ordr[i].dis(); tot += ordr[i].price(); cout << endl; } cout << "total cost:" << tot < int main() { int ty, si, nt, in; string nae, numb; order o; cout << "enter your name" << endl; cin >> nae; o.set_na(nae); cout << "enter your number" << endl; cin >> numb; o.set_num(numb); do { cout << "place your order here: "; cout << "select pizza type" << endl; cout << "1.deep dish" << endl; cout << "2.hand tossed" << endl; cout << "3.pan" << endl; cin >> ty; system("CLS"); cout << "select pizzasize" << endl; cout << "1.small" << endl; cout << "2.medium" << endl; cout << "3.large" << endl; cin >> si; system("CLS"); cout << "select number of toppings" << endl; cin >> nt; o.add_pizza(ty, si, nt); system("CLS"); cout << "for exit press 0 and for order more press 1" << endl; cin >> in; } while (in != 0); o.ret(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
