Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式.

Similar presentations


Presentation on theme: "Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式."— Presentation transcript:

1 Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式

2 Windows Processing Design2 畫面輸出與鍵盤輸入 C++ 是以 C 語言為基礎發展的程式語言 支援物件導向的程式語言 程式基本架構 #include // 標頭 void main(void) // 程式的起始 { int X; // 宣告變數 cout > X; // 讀取鍵盤資料 return 0; // 回傳值 }

3 Windows Processing Design3 畫面輸出與鍵盤輸入 con~ 程式執行過程 (Compiler) User (Source Program) Computer (Execute File) Compiler and Linker Header

4 Windows Processing Design4 畫面輸出與鍵盤輸入 con~ Type 1.integer ( 整數 ) ex : 500 2.char ( 字元 ) ex : ‘ A ’ 3.float ( 浮點數 ) ex : 1.414 4.bool ( 布林值 ) ex : True or False 5.String ( 字串 ) ex : “ Teacher ” Operator +,-,*,/,%,=,&&,||,!,++,--,*=,+=,-= … X

5 Windows Processing Design5 程式流程 規劃程式的流程 結構化的程式 If else statement if ( True ) { … } else if { … } else { … } 判斷式 True False Program

6 Windows Processing Design6 程式流程 con~ Switch statement switch(x){ case 1: a=1;break; case 2: a=2;break; case 3: a=3;break; default: … } 判斷式 a=1 a=2 a=3 default Break No Break

7 Windows Processing Design7 程式流程的迴圈 重複程式的流程方法 While statement while (True) { … } Do statement do { … }while(True) 判斷式 Statement true false

8 Windows Processing Design8 程式流程的迴圈 con~ For statement for( 初始值 ; 判斷式 ; 運算式 ) { … } 比較三個程式迴圈的不同 1.while{ … } 2.do{ … }while() 3.for(;;;){ … } 判斷式 Statement 運算式 初始值 Exit

9 Windows Processing Design9 函數的基礎 Function definition 1.function header 2.function body 兩個部分構成 int max( int a,int b,int c) { … return 整數 ; } Function body Function header 傳回型態 函數名稱 參數宣告

10 Windows Processing Design10 函數的基礎 # include int max(int a,int b,int c){ int max = a; if(b>max) max = b; if(c>max) max = c; return (max); } void main(void){ int show = max(1,2,3);} Main( ) Max()

11 Windows Processing Design11 指標與陣列 指標 & : 位址運算子是取出物件位址的運算子 int x = 100; int* ptr = &x; ● ptr 指向 int 的指標型態 ● *ptr 變成 x 的型態和值 500 號 100 500 號 X ptr

12 Windows Processing Design12 指標與陣列 con~ Function Call and Pointer void swap(int* x,int* y){ int temp = *x; *x = *y; *y = temp;} void main(void){ swap(&a,&b); } &a&a&b&b Swap XY

13 Windows Processing Design13 指標與陣列 con~ Array ( 陣列 ) int x [4]; int* ptr; p = &x[0]; or p = x; p+1; p-1; NULL ( 空指標 ) X[0] X[1] X[2] X[3] ptr *ptr *(p+1)

14 Windows Processing Design14 字串 字串值 “ ABC ” char str[4] = { ‘ A ’, ‘ B ’, ‘ C ’, ‘ \0 ’ }; char str[4] = “ ABC ” ; Pointer 操作 char* ptr = &str; ABC\0

15 Windows Processing Design15 字串 con~ 由指標所產生的字串 char* ptr = “ ABC ” ; 處理字串的標準涵式庫 #include strcpy(),strcmp(),strlen() … ABC\0 ptr

16 Windows Processing Design16 類別 Object ( 物件 ) Class 的定義 1.builtin type 2.user-defined type class student { public: int no; // data member int id; }; no id

17 Windows Processing Design17 類別 con~ 使用 Class 1. student csie={30,12345678}; 2. csie.no = 20; csie.id = 87654321; 3. student* ptr = &csie; ptr->no = 35; ptr->id = 98765432; no id ptr

18 Windows Processing Design18 類別 con~ 不保證完全初始化 不保證資料的保護 Date hiding - 不該公開的資料則不公開 (private) Construtor ( 建構元 ) - 必須與 Class 同名不可 - 防止不完全的初始化 私人成員 公用成員

19 Windows Processing Design19 類別 con~ Class student{ private : int no; int id; public: student(int x,int y){ no = x; id = y;} } Student csie(40,123456789); no id

20 Windows Processing Design20 類別 con~ Member function ( 成員函數 ) - method ( 方法 ) class student{ private: … public: … void show(){ … } void … } no id

21 Windows Processing Design21 類別 con~ Class 建立 class student{ public: student(int x,int y); void show(); }; student::student(int x,int y){ … } void student::show(){ … } 傳回型態 x::func( 引數 ) {// … }

22 Windows Processing Design22 類別 con~ HeaderMain( ) Member functionClass Include “ 自訂 ”

23 Windows Processing Design23 利用 BCB 開發程式 開啟 1.File -> New -> Console Wizard 2.File -> New -> Header File

24 Windows Processing Design24 利用 BCB 開發程式 con~ 畫面

25 Windows Processing Design25 利用 BCB 開發程式 con~ 執行 存檔 File -> Save All


Download ppt "Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式."

Similar presentations


Ads by Google