Question: Can Someone help me. Create a class named Pizza (Pizza.h and Pizza.cpp) that stores information about a single pizza. It should contain the following: Private
Can Someone help me.
Create a class named Pizza (Pizza.h and Pizza.cpp) that stores information about a single pizza. It should contain the following: Private member variables to store the size of the pizza (make this a string - small, medium, or large), the number of cheese toppings, the number of pepperoni toppings, the number of ham toppings, and the cost (double) of the pizza. A Constructor that accepts pizzas size, number of cheese, pepperoni, and ham toppings and assign them to the appropriate member variables. A Copy constructor. A public method named calcCost() that calculates the cost of the pizza. This function should preferably be called inside the constructor of the class. Public member functions to get and set the member variables (mutators and accessors). NOTE HERE: inside any mutator you need to call the method calcCost()to calculate the new cost of the Pizza Pizza cost is determined by: o Small: $10 + $2 per topping o Medium: $12 + $2 per topping o Large: $14 + $2 per topping The class should also have the following overloaded operators:
o = Assignment operator: This operator should perform member wise assignment between Pizza objects.
o ++ Prefix and postfix increment operators: These operators should increase each of the three toppings by 1.
o -- Prefix and postfix decrement operators: These operators should decrease each of the three toppings by 1.
o > This operator will return a boolean true if the calling Pizza object has higher Cost than the argument Pizza object otherwise returns false.
o < This operator will return a boolean true if the calling Pizza object has lower Cost than the argument Pizza object otherwise returns false.
o == This operator will return a boolean true if the calling Pizza object has same cost as the argument Pizza object otherwise returns false.
o << couts stream operator. This will display the pizza size, quantity of each topping, and the pizza cost calculatedby calcCost()
o >> cins stream operator. This will prompt the user to enter Pizzas size, and quantity of each topping. You can add other member functions to the class if you need to Once the class is created, write a main/Driver program that does the following. 1. The program should first ask the user the name of a pizza file and how many pizzas are there in the file. Depending on the number of pizzas it should dynamically allocate memory to hold the pizza objects. The program should read the file and create the pizza objects. One example file is given below. The first column is the pizza size, the next 3 columns indicate number of cheese, pepperoni and ham toppings, respectively). 2. Display each Pizza objects information and the cost of each Pizza object using the << overloaded operator. 3. Using the overloaded operators (>, < ==, and =), sort the pizza objects in ascending order of their cost. Display the information of all the sorted pizzas objects. Note: If you need to overload new operators you are welcome to overload them in the Pizza class. 4. By using mutator member function, change the size of all the pizza objects to small. Using overloaded increment operator ++, increase the toppings of all the pizza objects by 1. 5. Using the overloaded operators (>, < ==, and =), sort the new pizza objects in ascending order of their cost. Display the information of all the sorted pizzas objects.
Pizza.h
#pragma once #include
class Pizza { private: string size; int cheese, pepperoni, ham; double cost; public: Pizza() {
} Pizza(string aSize, int C, int p, int h);// 3 arg constructor Pizza(const Pizza&); // copy constructor void calcCost(); friend ostream& operator<<(ostream&, const Pizza&); //overloading << };
Pizza.cpp
#include "Pizza.h" #include
Pizza::Pizza(string aSize, int c, int p, int h) { size = aSize; cheese = c; pepperoni = p; ham = h; calcCost(); } Pizza::Pizza(const Pizza &aPizza) { size = aPizza.size; cheese = aPizza.cheese; pepperoni = aPizza.pepperoni; ham = aPizza.ham; cost = aPizza.cost; }
// incomplete void Pizza::calcCost() { //compute cost here if (size == "small") { cost = 10 + 2 * (ham + cheese + pepperoni); } else if (size == "medium") { cost = 12 + 2 * (ham + cheese + pepperoni); }
else if (size == "large") { cost = 14 + 2 * (ham + cheese + pepperoni); } }
main.cpp
#include "Pizza.h" #include
int main() { string PizzaFile; int numPizza;
cout << "Enter the name of the file that contains the Pizza details"; cin >> PizzaFile; cout << "How many Pizza objetcs "; cin >> numPizza;
Pizza *PizzaObj = new Pizza[numPizza];
ifstream fin; fin.open(PizzaFile); string tmpSize; int aCheese, aHam, aPepperoni; for (int i = 0; i < numPizza; i++) { fin >> tmpSize >> aCheese >> aHam >> aPepperoni; // Here use mutator functions of PizzaObj[i] to set the size and the number of the toppings /* */ }
// Display the info for all the Pizza Objects // use overloaded <<
//sort Pizza objects based on cost. Use overloaded >,<,== etc
//Display the sorted Pizza objects
//Use mutator function to change size of all pizza objects to "small"
//sort Pizza objects based on cost. Use overloaded >,<,== etc
//Display the sorted Pizza objects system("pause"); return 0; }
pizza.txt
medium 2 0 3 medium 3 3 2 large 1 4 2 medium 2 0 3 large 1 1 2 medium 1 4 2 large 1 4 1 medium 2 3 0 medium 4 2 4 large 0 0 1 large 2 4 3 large 2 0 2 medium 0 3 0 medium 2 0 2 large 4 4 2 medium 1 4 1 large 1 1 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
