Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2 Pizza 15 points Implement a program that creates pizzas based on user order. First, create class called Ingredient with one instance variable description

Problem 2 Pizza 15 points

Implement a program that creates pizzas based on user order. First, create class called Ingredient with one instance variable description of type string which is set in the constructor and can be get using a getter function. Create the following classes that derive from Ingredient: TomatoSauce, Cheese, Dough, and Pepperoni; each with a constructor that passes the description argument to the base constructor. Use proper access modifiers!

Create a class Pizza which consists of a dynamically allocated array of Ingredient object pointers (a double pointer). The constructor expects the number of maximum ingredients as int which is used to dynamically allocate and initialize the array. Implement a destructor that deletes the Ingredient objects and the array. The class has a function void add(Ingredient* ingredient) which adds an ingredient to the pizza and a function to print its ingredients to the console.

Create an abstract class PizzaFactory with a pure virtual function called bake() that returns a Pizza* object pointer. Create the two subclasses CheesePizzaFactory and PepperoniPizzaFactory which both explicitly override the bake() function. Both functions should remain virtual. The CheesePizzaFactory instantiates Pizza and adds Dough, TomatoSauce, and Cheese to it. The PepperoniPizzaFactory creates a pizza and adds all ingredients including pepperoni to it.

Use the following main method which prompts a user to order a type of pizza and then instantiates the corresponding PizzaFactory for it. After the pizza is created by calling the bake() function, the ingredients of the pizza are printed by calling the listIngredients() function of the pizza object. Finally, the factory and the pizza objects are deleted.

int main() {

char choice;

cout > choice;

PizzaFactory* factory;

if (choice == 'p')

{

factory = new PepperoniPizzaFactory(); }

else

{

factory = new CheesePizzaFactory();

}

Pizza* pizza = factory->create(); pizza->listIngredients();

delete pizza;

delete factory;

return 0;

}

Sample Output:

Would you like a pepperoni or cheese pizza (c/p)? p

Pizza with:

Spicy Pepperoni

Chunky Tomato Sauce

Jalapeno Pepper Cheddar Cheese

image text in transcribedimage text in transcribed

Santa Monica College CS 52-C+Programming Assignment #5-00P/ Inheritance Points: 30 Instructions (3 points) 1. Write a commen at the top that contains the following information / cs s2 // Assignment #5 Properly indent, format and comment your code as necessary 2. Warning:-No late submission is accepted Points will be deducted for entirely commented files Name your files problem}.cpp, for example probleml.cpp, problem2.cpp, etc. Canvas may append-1, such as problem2-I.cpp which is akay Shopping Cart Implement a program that tracks custoeners' puarchases. Create the following classes. Use Problem1 12 points appropriate access modifers (instance variables should be private!) and data types for each. Don't Sorget to add getter and setter furctions. item: This class has the attrbutes [member variables) called title, description, and price. o Book: This class inherits from Item, It has an instance variable called pageCount. o Movie: This class inherits from Item. It has an instance variable called length o CD: This class inherits from Item. It has an instance variable called trackCount. . ShoppingCart: This class keeps track of items that were boueht, You may Emit the number of items in the cart. The cart should have functions to add an item and print the tems currently in the cart to the console. Customer: The customer class stores an id, the first name and the last name and a pointer to a shoppine cart object. . Finally, implement a nain function that creates a customer. Then add one item of each type to the customer's shopping cart and list the items in the cart on the console. Problem 2 Pizza 15 points Implement a program that creates pizzas based on user order. First, create class called Ingredient with one instance variable description of type sring which is set in the constructor and can be get using a getter function. Create the following classes that derive from Ingredient: TomatoSauce, Cheese, Dough, and Pepperoni; each with a constructor that passes the dexcription argument to the base constractor. Use proper access modifiers! Santa Monica College CS 52-C+Programming Assignment #5-00P/ Inheritance Points: 30 Instructions (3 points) 1. Write a commen at the top that contains the following information / cs s2 // Assignment #5 Properly indent, format and comment your code as necessary 2. Warning:-No late submission is accepted Points will be deducted for entirely commented files Name your files problem}.cpp, for example probleml.cpp, problem2.cpp, etc. Canvas may append-1, such as problem2-I.cpp which is akay Shopping Cart Implement a program that tracks custoeners' puarchases. Create the following classes. Use Problem1 12 points appropriate access modifers (instance variables should be private!) and data types for each. Don't Sorget to add getter and setter furctions. item: This class has the attrbutes [member variables) called title, description, and price. o Book: This class inherits from Item, It has an instance variable called pageCount. o Movie: This class inherits from Item. It has an instance variable called length o CD: This class inherits from Item. It has an instance variable called trackCount. . ShoppingCart: This class keeps track of items that were boueht, You may Emit the number of items in the cart. The cart should have functions to add an item and print the tems currently in the cart to the console. Customer: The customer class stores an id, the first name and the last name and a pointer to a shoppine cart object. . Finally, implement a nain function that creates a customer. Then add one item of each type to the customer's shopping cart and list the items in the cart on the console. Problem 2 Pizza 15 points Implement a program that creates pizzas based on user order. First, create class called Ingredient with one instance variable description of type sring which is set in the constructor and can be get using a getter function. Create the following classes that derive from Ingredient: TomatoSauce, Cheese, Dough, and Pepperoni; each with a constructor that passes the dexcription argument to the base constractor. Use proper access modifiers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

2. What type of team would you recommend?

Answered: 1 week ago

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago