#include #include using namespace std; #include "pizza1.H" // default constructor Pizza::Pizza ( ) { allToppings[0] = "mushrooms"; allToppings[1] = "onions"; allToppings[2] = "green pepper"; allToppings[3] = "pepperoni"; allToppings[4] = "sausage"; allToppings[5] = "anchovies"; smallPrice = 4.99; medPrice = 6.99; largePrice = 9.99; smallToppingPrice = 0.79; medToppingPrice = 0.99; largeToppingPrice = 1.29; nrToppings = 0; } // mutators void Pizza::SetSize (string s) { size = s; } void Pizza::SetTopping (string t) { toppings[nrToppings++] = t; } void Pizza::ListToppings ( ) const { for (int i = 0; i < 6; i++) cout << "\t" << allToppings[i] << endl; } double Pizza::GetPrice( ) const { double total; if (size == "small") total = smallPrice + nrToppings * smallToppingPrice; else if (size == "medium") total = medPrice + nrToppings * medToppingPrice; else // size == "large" total = largePrice + nrToppings * 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; }