Part 3 - Write the following code, run it, fix it and describe what it does. //
Question:
Part 3- Write the following code, run it, fix it and describe what it does.
// ConsoleApplication3FactoryPizzaExample.cpp : This file contains the 'main' function. Program execution begins and ends there. // // Factory Pattern // * Add code for a 4th pizza type: Cheese // * Modify the pizza information function, so it prints the pizza name // * Comment each function - Explaining what it does // * Explain why this is a factory pattern
#include using namespace std;
#include #include #include using namespace std;
class Pizza { public: virtual double gets Price() const = 0; virtual ~Pizza() { cout };
class PepperoniOlivePizza : public Pizza { public: virtual double getPrice() const { return 8.50; }; virtual ~PepperoniOlivePizza() {}; };
class DeluxeChickenPizza : public Pizza { public: virtual double getPrice() const { return 10.50; }; virtual ~DeluxeChickenPizza() {}; };
class HawaiianPizza : public Pizza { public: virtual double getPrice() const { return 11.50; }; virtual ~HawaiianPizza() {}; };
class PizzaFactory { public: enum PizzaType { PepperoniOlive, DeluxeChicken, Hawaiian };
static unique_ptr createPizza(PizzaType pizzaType) { switch (pizzaType) { case PepperoniOlive: return make_unique(); case DeluxeChicken: return make_unique(); case Hawaiian: return make_unique(); } throw "invalid pizza type."; } };
// Instantiate all available pizzas and print their prices, and names void pizza_information(PizzaFactory::PizzaType pizzatype) { unique_ptr pizza = PizzaFactory::createPizza(pizzatype); cout getPrice() // Currently this prints the enum #, and price // Fix this code so it prints the pizza name, not the enum #, and prints the price }
int main() { pizza_information(PizzaFactory:PepperoniOlive); pizza_information(PizzaFactory::DeluxeChicken); pizza_information(PizzaFactory::Hawaiian); }
FileName: Week17YourNamePart3FactPattern