188k views
3 votes
Define a class called Pizza that has member variables to track the type of pizza (either deep dish, hand tossed, or pan) along with the size (either small, medium, or large) and the number of pepperoni and cheese toppings. You can use constants to represent the type and size. Your class will have four member variables: size, type, pepperoniToppings, cheeseToppings. Include mutator and accessor functions for your class. Create a void function, outputDescription(), that outputs a textual description of the pizza object. Also include a function, computePrice(), that computes the cost of the pizza and returns it as a double according to the rules:

Small pizza = $10 + $2 per topping
Medium pizza = $14 + $2 per topping
Large pizza = $17 + $2 per topping
Sample output:

This pizza is: Small, Hand tossed, with 0 pepperoni toppings and 3 cheese toppings.
Price of cheesy: 16
This pizza is: Large, Pan, with 2 pepperoni toppings and 1 cheese toppings.
Price of pepperoni : 23

User Vincent J
by
4.8k points

1 Answer

3 votes

Answer:

see explaination

Step-by-step explanation:

include <iostream>

#include <string>

using namespace std;

using namespace std;

const int SMALL = 1;

const int MEDIUM = 2;

const int LARGE = 3;

const int DEEPDISH = 1;

const int HANDTOSSED = 2;

const int PAN = 3;

class Pizza

{

private:

int type;

int size;

bool cheeseToppings;

bool pepperoniToppings;

public:

Pizza();

int getType();

int getSize();

bool getCheeze();

bool getPepperoni();

void setType(int t);

void setSize(int s);

void setCheese(bool choice);

void setPepperoni(bool choice);

void outputDescription();

double computePrice();

};

Pizza::Pizza()

{

type = DEEPDISH;

size = SMALL;

cheeseToppings = pepperoniToppings = false;

}

int Pizza::getType()

{

return type;

}

int Pizza::getSize()

{

return size;

}

bool Pizza::getCheeze()

{

return cheeseToppings;

}

bool Pizza::getPepperoni()

{

return pepperoniToppings;

}

void Pizza::setType(int t)

{

type = t;

}

void Pizza::setSize(int s)

{

size = s;

}

void Pizza::setCheese(bool choice)

{

cheeseToppings = choice;

}

void Pizza::setPepperoni(bool choice)

{

pepperoniToppings = choice;

}

void Pizza::outputDescription()

{

switch (size)

{

case SMALL:

cout << "Small "; break;

case MEDIUM:

cout << "Medium "; break;

case LARGE:

cout << "Large "; break;

default:

cout << "Unknown sized ";

}

switch (type)

{

case DEEPDISH:

cout << "deepdish "; break;

case HANDTOSSED:

cout << "hand tossed "; break;

case PAN:

cout << "pan "; break;

default:

cout << "unknown type ";

}

cout << "pizza";

}

double Pizza::computePrice()

{

double pizzaCost = 0.0;

switch (size)

{

case SMALL:

pizzaCost += 10;

break;

case MEDIUM:

pizzaCost += 14;

break;

case LARGE:

pizzaCost += 17;

break;

}

if (cheeseToppings)

pizzaCost += 2.0;

if (pepperoniToppings)

pizzaCost += 2.0;

return pizzaCost;

}

int main()

{

char pizzaType, pizzaSize, pizzaTopping;

int type = 0, size = 0;

cout << "What size pizza would you like (S/M/L): ";

cin >> pizzaSize;

cin.clear();

switch(pizzaSize)

{

case 'S': case 's':

size = SMALL; break;

case 'M': case 'm':

size = MEDIUM; break;

case 'L': case 'l':

size = LARGE; break;

}

cout << "What type pizza would you like ((D)eepdish/(H)and-tossed/(P)an): ";

cin >> pizzaType;

cin.clear();

switch(pizzaType)

{

case 'D': case 'd':

type = DEEPDISH; break;

case 'H': case 'h':

type = HANDTOSSED; break;

case 'P': case 'p':

type = PAN; break;

}

Pizza cheesy;

cheesy.setSize(size);

cheesy.setType(type);

cout << "Would you like cheese topping (y/n)? ";

cin >> pizzaTopping;

cin.clear();

if (pizzaTopping == 'Y' || pizzaTopping == 'y')

cheesy.setCheese(true);

cout << "Would you like pepperoni topping (y/n)? ";

cin >> pizzaTopping;

cin.clear();

if (pizzaTopping == 'Y' || pizzaTopping == 'y')

cheesy.setPepperoni(true);

cout << endl

<< "Your order: ";

cheesy.outputDescription();

cout << endl;

cout << "Price: $" << cheesy.computePrice() << endl;

return 0;

}

/*

output:

What size pizza would you like (S/M/L): L

What type pizza would you like ((D)eepdish/(H)and-tossed/(P)an): P

Would you like cheese topping (y/n)? y

Would you like pepperoni topping (y/n)? y

Your order: Large pan pizza

Price: $21

*/

User Evg
by
5.1k points