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

Define a class called Pizza that has member variables to track the type of pizza

ID: 3527379 • Letter: D

Question

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 or cheese toppings. You can use constants to represent the type and size. 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 return it as a double according to the following rules: Small pizza = $10 + $2 per topping Medium pizza = $14 + $2 per topping Large pizza = $17 + $2 per topping Write a suitable test program that creates and outputs a description and price of various pizza objects.

Explanation / Answer

#include
using namespace std;

const int DEEPDISH = 1;
const int HANDTOSSED = 2;
const int PAN = 3;
const int SMALL = 1;
const int MEDIUM = 2;
const int LARGE = 3;

class Pizza
{
private:
int type;
int size;
bool cheeseTopping; // true/false
bool pepperoniTopping; // true/false

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;
cheeseTopping = pepperoniTopping = false;
}

int Pizza::getType()
{
return type;
}

int Pizza::getSize()
{
return size;
}

bool Pizza::getCheeze()
{
return cheeseTopping;
}

bool Pizza::getPepperoni()
{
return pepperoniTopping;
}

void Pizza::setType(int t)
{
type = t;
}

void Pizza::setSize(int s)
{
size = s;
}

void Pizza::setCheese(bool choice)
{
cheeseTopping = choice;
}

void Pizza::setPepperoni(bool choice)
{
pepperoniTopping = 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 cost = 0.0;
switch (size)
{
case SMALL:
cost += 10; break;
case MEDIUM:
cost += 14; break;
case LARGE:
cost += 17; break;
}

if (cheeseTopping)
cost += 2.0;
if (pepperoniTopping)
cost += 2.0;

return cost;
}

//---------------------
// Application program
//---------------------
int main()
{
// variables to receive user input
char pType, pSize, topping, temp;
int type = 0, size = 0;

// Ask the user for the order
cout << "What size pizza would you like (S/M/L): ";
cin >> pSize;
cin.clear();

switch(pSize)
{
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 >> pType;
cin.clear();

switch(pType)
{
case 'D': case 'd':
type = DEEPDISH; break;
case 'H': case 'h':
type = HANDTOSSED; break;
case 'P': case 'p':
type = PAN; break;
}

// At this point, we can create a pizza (with no toppings)
Pizza myPizza;
myPizza.setSize(size);
myPizza.setType(type);

// Now ask about toppings.
cout << "Would you like cheese topping (y/n)? ";
cin >> topping;
cin.clear();

if (topping == 'Y' || topping == 'y')
myPizza.setCheese(true);

cout << "Would you like pepperoni topping (y/n)? ";
cin >> topping;
cin.clear();

if (topping == 'Y' || topping == 'y')
myPizza.setPepperoni(true);

// Then output the description of the order
cout << endl
<< "Your order: ";
myPizza.outputDescription();
cout << endl;

// Also compute the cost and display it.
cout << "Price: $" << myPizza.computePrice() << endl;

system("pause");
return 0;
}

/* Sample 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

*/

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