PowerPoint 簡報

Download Report

Transcript PowerPoint 簡報

計算機程式
第九單元 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條合理使用。
1
Why C++/OOP?
• Extensible language
o Built-in data type
o User-defined data type
• Software reuse
• Information hiding
o Interface vs. implementation
2
Class Definition
Class: Vehicle
• Format
class c_name {
public:
member functions;
private:
data member;
};
• How to use (member selection operator)?
o Dot (a.x): object and reference
o Arrow (a->x): pointer
3
Example-1
p.404-405
4
Example-2
p.397
5
Example-2 (cont.)
p.399
6
Example-2 (cont.)
p.399, 402
7
Example-2 (cont.)
p.402
8
Interface vs. Implementation
• All-in-one: e.g., Fig. 9.2
• Header + driver program: e.g., Fig. 9.1
• Interface + implementation + driver program: Figs. 9.39.5.
9
Preprocess wrapper
#ifndef TIME_H
#define TIME_H
… // code
#endif
p.397
Time sunset;
Time arrayOfTimes[ 5 ];
Time &dinnerTime = sunset;
Time *timePtr = &dinnerTime;
10
Preprocess wrapper
p.409-410
11
How to Make an Executable File?
Class Implementation
Programmer
Time.cpp
implementation
file
Client Code
Programmer
Time.h
class
definition/interface
main function
(client source code)
compiler
compiler
Time class’s
object code
C++ standard library
object code
main function’s
object code
linker
executable application
that uses class Time
Application
User
12
When constructor and destructor are called
p.416
13
p.417
14
版權聲明
頁碼
1-16
作品
版權圖示
來源/作者
本作品轉載自Microsoft Office 2007多媒體藝廊,依據Microsoft服務合約及著作權法第
46、52、65條合理使用。
2
Open Clip Art Library,作者:bugmenot,本作品轉載自:
http://openclipart.org/detail/18378/glossy-media-player-buttons-by-bugmenot,
瀏覽日期:2013/1/13。
3
Open Clip Art Library,作者:TheresaKnott,本作品轉載自:
http://openclipart.org/detail/810/boeing-b47e-by-theresaknott,瀏覽日期:2013/1/16。
3
Open Clip Art Library,作者:netalloy,本作品轉載自:
http://openclipart.org/detail/76801/royal-motorcycle-by-netalloy,瀏覽日期:2013/1/16。
3
Open Clip Art Library,作者:Anonymous,本作品轉載自:
http://openclipart.org/detail/23878/blue-bike-by-anonymous-23878,瀏覽日期:2013/1/16。
3
Open Clip Art Library,作者:Machovka,本作品轉載自:
http://openclipart.org/detail/2827/yellow-car-by-machovka,瀏覽日期:2013/1/16。
15
版權聲明
頁碼
4-8, 10-11,
13-14
12
作品
版權圖示
來源/作者
Open Clip Art Library,作者:aritztg,本作品轉載自:
http://openclipart.org/detail/3422/mouse-by-aritztg,瀏覽日期:2013/1/10。
C++ How to Program, 7/e,作者:Harvey M. Deitel and Paul J. Deitel,
出版社:Deitel & Associates,出版日期:2010,P.97。
依據著作權法第46、52、65條合理使用。
16