1. Trang chủ
  2. » Tiểu sử - Hồi kí

Lập trình hướng đối tượng: Workshop 9

3 12 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 53,15 KB

Nội dung

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]

(1)

Part E – Polymorphism Workshop 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

(2)

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 - and format

14" slices 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:

• a display query

(3)

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 and a description of the added toppings - and in the following format

14" slices eaten mushrooms, green peppers

Ngày đăng: 10/03/2021, 14:35

w