Question

In: Computer Science

***Define a class called Pizza that has member variables to track the type of pizza (either...

***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 returns 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.*** I HAVE THE CODE FOR THIS QUESTION, I NEED HELP WITH:

⦁   This Programming Project requires you to first complete Programming Project 7 from Chapter 5, which is an implementation of a Pizza class. Add an Order class that contains a private vector of type Pizza. This class represents a customer’s entire order, where the order may consist of multiple pizzas. Include appropriate functions so that a user of the Order class can add pizzas to the order (type is deep dish, hand tossed, or pan; size is small, medium, or large; number of pepperoni or cheese toppings). Data members: type and size. Also write a function that outputs everything in the order along with the total price. Write a suitable test program that adds multiple pizzas to an order(s).

Solutions

Expert Solution


#include <iostream>
#include <string>

using namespace std;

class Pizza
{
public:
   enum pizzaType {DeepDish = 1, HandTossed, Pan };
   enum pizzaSize { Small = 1, Medium, Large};
   enum pizzaToppings { None = 0, Cheese, Pepperoni, Both };

   Pizza();
   bool setType(int selectedType);
   bool setSize(int selectedSize);
   bool setToppings(int selectedToppings);

   pizzaType getType();
   pizzaSize getSize();
   pizzaToppings getToppings();

   void outputDescription();
   double computePrice();

private:
   pizzaType type;
   pizzaSize size;
   pizzaToppings toppings;
   string typeDescription;
   string sizeDescription;
   string toppingsDescription;
};

class Order
{
private:
   // Client allowed to have max of 20 orders
   static int const MAX_ORDERS = 20;
   Pizza orderArray[MAX_ORDERS];
   int orderQuantity;

   // Helper methods called by orderPizza() that ask for and set pizza specs
   void askUser_Type(Pizza &pizza);
   void askUser_Size(Pizza &pizza);
   void askUser_Topping(Pizza &pizza);

public:
   // Constructors
   Order();
   Order(int orders);
   // Getters and Setters
   bool setOrderQuantity(int input);
   int getOrderQuantity();
   // Other methods
   void client_orderQuantity();
   void orderPizza(); // Prompts user to specify all pizzas desired
   void showReceipt(); // Prints out a receipt of all the pizzas ordered

};

Pizza::Pizza()
{
   //Setting defaults values for the type, size, and toppings
   type = Pizza::DeepDish;
   size = Pizza::Small;
   toppings = Pizza::None;
}

bool Pizza::setType(int selectedType)
{
   switch (selectedType) {
   case 1:
      type = Pizza::DeepDish;
      typeDescription = "Deep Dish";
      break;
   case 2:
      type = Pizza::HandTossed;
      typeDescription = "Hand Tossed";
      break;
   case 3:
      type = Pizza::Pan;
      typeDescription = "Pan";
      break;
   default:
      return false;
   }
   return true;
}

bool Pizza::setSize(int selectedSize)
{
   switch (selectedSize) {
   case 1:
      size = Pizza::Small;
      sizeDescription = "Small";
      break;
   case 2:
      size = Pizza::Medium;
      sizeDescription = "Medium";
      break;
   case 3:
      size = Pizza::Large;
      sizeDescription = "Large";
      break;
   default:
      return false;
   }
   return true;
}

bool Pizza::setToppings(int selectedToppings)
{
   switch (selectedToppings) {
   case 0:
      toppings = Pizza::None;
      toppingsDescription = "No toppings";
      break;
   case 1:
      toppings = Pizza::Cheese;
      toppingsDescription = "Cheese";
      break;
   case 2:
      toppings = Pizza::Pepperoni;
      toppingsDescription = "Pepperoni";
      break;
   case 3:
      toppings = Pizza::Both;
      toppingsDescription = "Both cheese and pepperoni";
      break;
   default:
      return false;
   }
   return true;
}

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

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

Pizza::pizzaToppings Pizza::getToppings()
{
   return toppings;
}

void Pizza::outputDescription()
{
   cout << "   Type: " << typeDescription << "\n"
           "   Size: " << sizeDescription << "\n"
           "   Toppings: " << toppingsDescription << "\n"
           "   Price: $" << computePrice() <<endl;
}

double Pizza::computePrice()
{
   /* Compute price using the following formula:
   Small pizza = $10 + $2 per topping
   Medium pizza = $14 + $2 per topping
   Large pizza = $17 + $2 per topping
   */
   double price = 0;
   switch (size){
   case Pizza::Small:
      price += 10;
      break;
   case Pizza::Medium:
      price += 14;
      break;
   case Pizza::Large:
      price += 17;
      break;
   }
   switch (toppings){
   case Pizza::Cheese:
   case Pizza::Pepperoni:
      price += 2;
      break;
   case Pizza::Both:
      price += 2*2;
      break;
   }
   return price;

}

// Default constructor
Order::Order()
{
   orderQuantity = 0;
}

// Overloaded constructor
Order::Order(int orders)
{
   if(!setOrderQuantity(orders))
      orderQuantity = 0;
}

// Specifies a number of pizzas to order
bool Order::setOrderQuantity(int input)
{
   // Only accepts values from 1 to 20
   if ((input < 1) || (MAX_ORDERS < input))
      return false;
   orderQuantity = input;
   return true;
}

int Order::getOrderQuantity()
{
   return orderQuantity;
}

/*
Prompts for and creates pizzas according to user input. This is
done with the "askUser" series of helper methods. The point of
this is because the orderArray[] is private, and using a method
for this makes the task modular and easy to handle in main().
*/
void Order::orderPizza()
{
   // Needs at least one pizza being ordered
   if (orderQuantity < 1)
      return;

   Pizza thePizza;
   int current;

   // Instructions message
   cout << "\nPlease place your order by selecting from the following menus.\n"
           "Please enter item number to select.\n";

   // Loop while there are still orders to be completed
   for (current = 0; current < orderQuantity; current++)
   {
      cout << "__________________________________________\n\n";
      // Create Pizza
      askUser_Type(thePizza);
      askUser_Size(thePizza);
      askUser_Topping(thePizza);
      // Put into orderArray
      orderArray[current] = thePizza;
      cout << "\nPizza #" << (current + 1) << " completed!" << endl;
   }
}

// Prints the order, along with a receipt detailing each pizza and the total cost
void Order::showReceipt()
{
   // Needs at least one pizza that was ordered
   if (orderQuantity < 1)
      return;

   int current;
   double price,
          totalPrice = 0.0;

   // Beginning message
   cout << "\n________________________________________________________________________________\n\n"
           "You ordered " << orderQuantity << " pizzas. Here is your order:\n";

   // Loop through entire orderArray, output pizza's description
   for (current = 0; current < orderQuantity; current++)
   {
      // Show the pizzas
      cout << "\nPizza #" << (current + 1) << endl;
      orderArray[current].outputDescription();
   }

   // Loop through orderArray, this time for receipt
   cout << "\n---- Receipt ----" << endl;
   for (current = 0; current < orderQuantity; current++)
   {
      // Get the price
      price = orderArray[current].computePrice();
      // Print price
      cout << "Pizza #" << (current + 1) << ": $" << price << endl;
      totalPrice += price; // Add to total
   }
   cout << "\nTotal: $" << totalPrice << endl;
}

// Prompts client for and gives pizza a valid type
void Order::askUser_Type(Pizza &pizza)
{
   int type;
   cout << "Select pizza type;\nDeep dish (1)\nHand tossed (2)\nPan (3)\nEnter selection: ";
   cin >> type;
   while (!pizza.setType(type))
   {
      cout << "Please enter a valid selection for pizza type; Deep dish (1), Hand tossed (2), or Pan (3): ";
      cin >> type;
   }
}

// Prompts client for and gives pizza a valid size
void Order::askUser_Size(Pizza &pizza)
{
   int size;
   cout << "____________________\n\n"
           "Select pizza size;\nSmall (1)\nMedium (2)\nLarge (3)\nEnter selection: ";
   cin >> size;
   while (!pizza.setSize(size))
   {
      cout << "Please enter a valid selection for pizza size; Small (1), Medium (2), or Large (3):";
      cin >> size;
   }
}

// Prompts client for and gives pizza a valid topping
void Order::askUser_Topping(Pizza &pizza)
{
   int toppings;
   cout << "____________________\n\n"
           "Select pizza toppings;\nNone (0)\nCheese (1)\nPepperoni (2)\nBoth Cheese and Pepperoni (3)\nEnter selection: ";
   cin >> toppings;
   while (!pizza.setToppings(toppings))
   {
      cout << "Please enter a valid selection for pizza toppings; None (0), Cheese (1), Pepperoni (3), Both Cheese and Pepperoni (4):";
      cin >> toppings;
   }
}

int main()
{
   Order theOrder;
   int orderQuantity;

   // Welcome message
   cout << "****************************************************\n"
           "Welcome to City Pizza where the best pizza is made!\n"
           "****************************************************\n\n"
           "How many pizzas would you like to order? You may choose up to 20.\n"
           "Enter quantity: ";
   // Get number of orders; can be a method, but other than cleaner main(), it is not a pressing issue
   cin >> orderQuantity;
   while (!theOrder.setOrderQuantity(orderQuantity))
   {
      cout << "You can only set a quantity from 1 to 20. Enter a new quantity: ";
      cin >> orderQuantity;
   }

   // Use an order method because pizza array is private, and main is cleaner.
   theOrder.orderPizza();
   // Print the result
   theOrder.showReceipt();

   // Another happy customer!
   cout << "\nThank you for choosing City Pizza :) Have a great day! \n\n";

   return 0;
}



Related Solutions

1. Define a class called Odometer that will be used to track fuel and mileage for...
1. Define a class called Odometer that will be used to track fuel and mileage for an automobile. The class should have instance variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer’s total, and an accessor method...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Car Class Write a class named Car that has the following member variables: • year. An...
Car Class Write a class named Car that has the following member variables: • year. An int that holds the car’s model year. • make. A string object that holds the make of the car. • speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. • Constructor. The constructor should accept the car’s year and make as arguments and assign these values to the object’s year and make member variables....
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
Write a Circle class that has the following member variables: • radius: a double • pi:...
Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the circle, which...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and...
PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and complexNum of type double. Your class shall have following member functions Complex(); Complex(double, double); Complex add(Complex num1, Complex num2); Complex subtract(Complex num1, Complex num2); string printComplexNumber(); Write a driver program to test your code. Please make sure your code is separated into Complex.h Containing definition of the class Complex.cpp Containing the implementation ComplexTestProgram.cpp Containing main program Use the following directive in class definition to...
/*Design and code a class Calculator that has the following * tow integer member variables, num1...
/*Design and code a class Calculator that has the following * tow integer member variables, num1 and num2. * - a method to display the sum of the two integers * - a method to display the product * - a method to display the difference * - a method to display the quotient * - a method to display the modulo (num1%num2) * - a method toString() to return num1 and num2 in a string * - Test your...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT