CMSC 202 Fall 02 Project 2 Solutions

Solution 1

Solution 1 demonstrates how to do all prompting in main( ) and use mutators to store data into the Order and Pizza objects. It has the most code of any of the three solutions.

Solution 2

Solution 2 overloads the input operators for Order and Pizza. There is almost no code in main( ). It stores the prices and the list of toppings in the objects. This is a bit of memory waste (and a temporary pizza object must be instantiated in order to print the list of pizzas), but it's a better solution than solution 1. Given our current knowledge of C++, this is probably the best solution we can write.

Solution 3

Solution 3 is an "advanced" C++ solution that uses static data members and a static function. Static data members and functions belong to the class instead of being duplicated in each object. The advantage in this case, is that the prices and toppings are not stored in each Order and Pizza object (so memory is saved) and no temporary Pizza object is necessary to print the toppings. Static data members and functions are discussed in section 7.7 of the text.

Sorry! We could not find what you were looking for

Try going back to the main page here

 
4
4
0
0
0
0