#include #include using namespace std; #include "pizza2.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; } 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; } // 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; }