// pizza.h const int SMALL = 0; const int MEDIUM = 1; const int LARGE = 2; const int DEEPDISH = 0; const int HANDTOSSED = 1; const int PAN = 2; class Pizza { public: Pizza(); ~Pizza() {}; int getPepperoniToppings(); void setPepperoniToppings(int numPepperoni); int getCheeseToppings(); void setCheeseToppings(int numCheese); int getSize(); void setSize(int newSize); int getType(); void setType(int newType); void outputDescription(); double computePrice(); private: int size, type, pepperoniToppings, cheeseToppings; }; // pizza.cpp // // This program implements the Pizza class and creates several // pizza objects to test it out. #include #include "pizza.h" using namespace std; //======================== // Pizza // The constructor sets the default pizza // to a small, deep dish, with only cheese. //======================== Pizza::Pizza() { size = SMALL; type = DEEPDISH; pepperoniToppings = 0; cheeseToppings = 1; } //================================== // Accessors and Mutators Follow //================================== int Pizza::getPepperoniToppings() { return pepperoniToppings; } void Pizza::setPepperoniToppings(int numPepperoni) { pepperoniToppings=numPepperoni; } int Pizza::getCheeseToppings() { return cheeseToppings; } void Pizza::setCheeseToppings(int numCheese) { cheeseToppings=numCheese; } int Pizza::getSize() { return size; } void Pizza::setSize(int newSize) { size=newSize; } int Pizza::getType() { return type; } void Pizza::setType(int newType) { type=newType; } //================================== // outputDescription // Prints a textual description of the contents of the pizza. //================================== //================================== // computePrice // Returns: // Price of a pizza using the formula: // Small = $10 + $2 per topping // Medium = $14 + $2 per topping // Large = $17 + $2 per topping //================================== // -------------------------------- //# double Pizza::computePrice() { double price; switch (size) { case 0: price = 10.00; break; case 1: price = 14.00; break; case 2: price = 17.00; break; } return (price + ((cheeseToppings + pepperoniToppings)*2.00)); } // ====================== // main function // ====================== int main() { // Variable declarations Pizza cheesy; Pizza pepperoni; cheesy.setCheeseToppings(3); cheesy.setType(HANDTOSSED); cheesy.outputDescription(); cout << "Price of cheesy: " << cheesy.computePrice() << endl; pepperoni.setSize(LARGE); pepperoni.setPepperoniToppings(2); pepperoni.setType(PAN); pepperoni.outputDescription(); cout << "Price of pepperoni : " << pepperoni.computePrice() << endl; cout << endl; system("PAUSE"); }