that receives a reference to an ostream object and sends to that object information about the pizza in the following order - diameter, original number of slices, number of slices eaten[r]
Trang 1Workshop 9 LEARNING OUTCOME
Upon successful completion of this workshop, you will have demonstrated the ability to adhere
to object-oriented programming principles including encapsulation, polymorphism and
inheritance when writing code
PIZZA CLASS
Design and code a class named Pizza that holds information about a pizza Upon instantiation, a
Pizza object receives a double defining the diameter of the pizza Initially, the object is
unsliced and uneaten
Include the following member functions in your design:
• a slice modifier
void slice(int)
that receives the number of slices to be made and slices the object into that number of slices
• an eat modifier
void eatSlice()
that consumes a single slice
• a display query
void display(ostream&)
const
Trang 2the pizza in the following order - diameter, original number of slices, number of slices eaten - and format
14" 8 slices 4 eaten
Include the following helper function in your design
• an insertion operator
ostream&
operator<<(ostream&, const
Pizza&)
• that receives a reference to an ostream object and a reference to a Pizza object and sends
to the ostream object information about the pizza in the format described above
Note that this function need not be a friend of your Pizza class The function can call the
display function to access the private data
DELUXEPIZZA CLASS
Derive from Pizza a class named DeluxePizza that holds information about a deluxe pizza Upon instantiation, a DeluxePizza object receives a double defining the diameter of the pizza and a null-terminated string describing the added toppings Initially, the DeluxePizza object
is unsliced and uneaten
Include the following member function in your design:
void display(ostream&)
const
Trang 3the pizza in the following order - diameter, original number of slices, number of slices eaten and a description of the added toppings - and in the following format
14" 8 slices 4 eaten
mushrooms, green peppers
For your class to function properly, you will need to include a copy constructor, an assignment operator and a destructor