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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

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]

Trang 1

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

void display(ostream&)

const

Trang 2

the 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 3

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" 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

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

w