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...
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...
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...
Write a small Java class called StoreAddStuff that uses generics to store two variables of type...
Write a small Java class called StoreAddStuff that uses generics to store two variables of type T passed in during construction, then returns their sum through a non-static method.
Define a class called Goals that has the following requirements in c++: a function called set...
Define a class called Goals that has the following requirements in c++: a function called set that takes 3 int parameters that are goals for "fame", "happiness" and "money". The function returns true and saves the values if they add up to exactly 60, and returns false otherwise (you may assume the parameters are not negative) a functions satisfies that takes 3 int parameters and returns true if each parameter is at least as large as the saved goal, false...
Write a class called Animal that contains a static variable called count to keep track of...
Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member variable are allowed Create accessor and mutator functions to set/return numerator denominator Create a function to set a fraction Create a function to return a fraction as a string ( common name ToString(), toString())  in the following format: 2 3/4 use to_string() function from string class to convert a number to a string; example return to_string(35)+ to_string (75) ; returns 3575 as a string Create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT