Presentation is loading. Please wait.

Presentation is loading. Please wait.

第九單元 Classes and data abstraction I

Similar presentations


Presentation on theme: "第九單元 Classes and data abstraction I"— Presentation transcript:

1 第九單元 Classes and data abstraction I
計算機程式 第九單元 Classes and data abstraction I 授課教師:廖婉君教授 【本著作除另有註明外,採取創用CC「姓名標示-非商業性-相同方式分享」台灣3.0版授權釋出】 本課程指定教材為 C++ How to Program, 7/e, Harvey M. Deitel and Paul J. Deitel, both from Deitel & Associates, Inc. © 2010。 本講義僅引用部分內容,請讀者自行準備。 本作品轉載自Microsoft Office 2007多媒體藝廊,依據Microsoft服務合約及著作權法第46、52、65條合理使用。

2 Why C++/OOP? Extensible language Software reuse Information hiding
Built-in data type User-defined data type Software reuse Information hiding Interface vs. implementation

3 Class Definition Format class c_name { public: member functions;
Class: Vehicle Format class c_name { public: member functions; private: data member; }; How to use (member selection operator)? Dot (a.x): object and reference Arrow (a->x): pointer

4 Example-1 p

5 Example-2 p.397

6 Example-2 (cont.) p.399

7 Example-2 (cont.) p.399, 402

8 Example-2 (cont.) p.402

9 Interface vs. Implementation
All-in-one: e.g., Fig. 9.2 Header + driver program: e.g., Fig. 9.1 Interface + implementation + driver program: Figs

10 p.397 Preprocess wrapper #ifndef TIME_H #define TIME_H … // code
#endif p.397 Time sunset; Time arrayOfTimes[ 5 ]; Time &dinnerTime = sunset; Time *timePtr = &dinnerTime;

11 Preprocess wrapper p

12 How to Make an Executable File?
Time.cpp implementation file Time.h class definition/interface main function (client source code) compiler Time class’s object code C++ standard library main function’s linker executable application that uses class Time Class Implementation Programmer Client Code Programmer Application User

13 When constructor and destructor are called
p.416

14 p.417

15 版權聲明 頁碼 作品 版權圖示 來源/作者 1-16 本作品轉載自Microsoft Office 2007多媒體藝廊,依據Microsoft服務合約及著作權法第46、52、65條合理使用。 2 Open Clip Art Library,作者:bugmenot,本作品轉載自: 瀏覽日期:2013/1/13。 3 Open Clip Art Library,作者:TheresaKnott,本作品轉載自: Open Clip Art Library,作者:netalloy,本作品轉載自: Open Clip Art Library,作者:Anonymous,本作品轉載自: Open Clip Art Library,作者:Machovka,本作品轉載自:

16 版權聲明 頁碼 作品 版權圖示 來源/作者 4-8, 10-11, 13-14
Open Clip Art Library,作者:aritztg,本作品轉載自: 12 C++ How to Program, 7/e,作者:Harvey M. Deitel and Paul J. Deitel, 出版社:Deitel & Associates,出版日期:2010,P.97。 依據著作權法第46、52、65條合理使用。


Download ppt "第九單元 Classes and data abstraction I"

Similar presentations


Ads by Google