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

In C++ Define a class called Pizza that has member variables to track the type o

ID: 3818540 • Letter: I

Question

In C++

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:

Sample output:

1 #include kiostream 2 using namespace std; 4 const int SMALL o; 5 const int MEDIUM 1; 6 const int LARGE 2; 8 const int DEEPDISH 0; 9 const int HANDTOSSED 1 10 const int PAN 12 int main 13 E 14 Pizza cheesy; 15 Pizza pepperoni; 16 17 cheesy. setChe Toppings (3) ee8e 18 cheesy setType (HANDTOSSED) 19 cheesy output Description 20 cout Price of cheesy cheesy.computePrice endl 21 22 pepperoni. setSize (LARGE) 23 pepperoni. set PepperoniToppings (2) 23 pepperoni. setType (PAN) 25 pepperoni. output Description 26 cout Price of pepperoni. pepperoni. .compute Price endl 27 28

Explanation / Answer


// C++ code
#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

*/