#include #include using namespace std; #include "pizza3.H" // "class" variables const string Pizza::allToppings[NRTOPPINGS] = { "mushrooms", "onions", "green pepper", "pepperoni", "sausage", "anchovies" }; const double Pizza::smallPrice = 4.99; const double Pizza::medPrice = 6.99; const double Pizza::largePrice = 9.99; const double Pizza::smallToppingPrice = 0.79; const double Pizza::medToppingPrice = 0.99; const double Pizza::largeToppingPrice = 1.29; // default constructor Pizza::Pizza ( ) { nrToppings = 0; } // static class function void Pizza::ListToppings ( ) { for (int i = 0; i < 6; i++) cout << "\t" << allToppings[i] << endl; } double Pizza::GetPrice( ) const { double total; if (size == "small") total = Pizza::smallPrice + nrToppings * Pizza::smallToppingPrice; else if (size == "medium") total = Pizza::medPrice + nrToppings * Pizza::medToppingPrice; else // size == "large" total = Pizza::largePrice + nrToppings * Pizza::largeToppingPrice; return total; } // output operator as a friend ostream& operator<< (ostream& out, const Pizza& p) { double price = p.GetPrice(); out << setw(6) << p.size << " pizza\t$"; out.setf (ios::showpoint | ios::fixed); out << setprecision (2) << setw (6) << price << endl; out << "\t"; for (int i = 0; i < p.nrToppings; i++) { out << p.toppings[i]; if (i != p.nrToppings - 1) out << ","; } out << endl; return out; } // input operator as a friend istream& operator>> (istream& in, Pizza& p) { cout << "What size? "; in >> p.size; cout << "How many toppings? "; in >> p.nrToppings; in.ignore(); for (int i = 0; i < p.nrToppings; i++) { cout << "Topping: "; getline(in, p.toppings[i]); } return in; }