Question
Write the following code, run it, fix it and describe what it does. // ConsoleApplication3FactoryPizzaExample.cpp : This file contains the 'main' function. Program execution begins
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 also prints the pizza name // * Comment each function - Explaining what it does // * Explain why this is a factory pattern
#include
#include
class Pizza { public: virtual double getPrice() const = 0; virtual ~Pizza() { cout << "Destructor called" << endl; } };
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
// Instantiate all available pizzas and print their prices, and names void pizza_information(PizzaFactory::PizzaType pizzatype) { unique_ptr
int main() { pizza_information(PizzaFactory::PepperoniOlive); pizza_information(PizzaFactory::DeluxeChicken); pizza_information(PizzaFactory::Hawaiian); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started