1 / 19

計算機程式語言實習課

計算機程式語言實習課. 作業成績已上傳 (12/2) 程式碼務必直接寫在信件內容 可以夾帶 cpp 檔,不要只寄壓縮檔. http://tw.youtube.com/watch?v=QX2-9fS5TBY. 距離學期末只剩一個月囉 !. 函數 Function. 增加軟體的 再使用率 (Software Reuse) 對設計者而言:減少重覆性的程式碼 對使用者而言:別把輪子再發明一次 增加程式 可讀性 降低偵錯與維護成本 自由性. 函數 Function. What is Function? int abs( int n) ?

jack-holden
Télécharger la présentation

計算機程式語言實習課

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 計算機程式語言實習課

  2. 作業成績已上傳(12/2) • 程式碼務必直接寫在信件內容可以夾帶cpp檔,不要只寄壓縮檔

  3. http://tw.youtube.com/watch?v=QX2-9fS5TBY

  4. 距離學期末只剩一個月囉!

  5. 函數 Function • 增加軟體的再使用率(Software Reuse) • 對設計者而言:減少重覆性的程式碼 • 對使用者而言:別把輪子再發明一次 • 增加程式可讀性 • 降低偵錯與維護成本 自由性

  6. 函數 Function • What is Function? • int abs( int n) ? • void srand( int seed) ? • int rand( void ) ? • int main( void ) ?

  7. 函數 Function • 以下程式是否正確? int cnk(int n,int k) { int rlt; … return n,k,rlt;} 回傳值 only one!

  8. 函數 Function • 最大公因數 • 過河遊戲

  9. 遞迴 Recursive • 函式自己呼叫自己的行為 • 進入點? • 何時結束? 永遠不會結束? Orz... • 一定要設定結束條件!!!

  10. int gcd(int x, int y) { int t; while(y!=0) { t=x%y; x=y; y=t; } return x; } int recursive_gcd(int x,int y) { if (y==0) return x; return recursive_gcd(y,x%y); } 遞迴 Recursive

  11. int sub(int n) { if((n==0)||(n==1)) return n ; else return sub(n-1)+sub(n-2); } 遞迴 Recursive

  12. 遞迴 Recursive • 更多的例子 • 河內塔 • 踩地雷 • 老鼠走迷宮 • 麻將 • 數獨 • ...

  13. 遞迴 Recursive • 何時該使用遞迴? 何時該使用迴圈? • 能夠掌握程式runing狀態時 使用迴圈 • 無法掌握程式runing狀態時 使用遞迴 • 迴圈的過程有不同的執行路徑 • 需要記憶程式的狀態

  14. 物件導向 • 物件導向 Object-Oriented Programming) • 程序導向 procedure-oriented

  15. 物件導向 物件導向程式 繼承 多型 封裝 超載 類別 class 程式設計基礎 函數 fumction 結構 struct 條件 Ifelseswitch dowhilefor 迴圈 array 陣列

  16. 結構 struct • 如何在程式中定義”資料” • 例如:學生資料、座標、分數 //學生資料 void main() { string student_name[10]; char student_sex[10]; int score[10] } //分數計算 void main() { int num[10]; int up[10]; int down[10] }

  17. 結構 struct • 如何在程式中定義”資料” • 例如:學生資料、座標、分數 能不能把他們寫在一起呢?

  18. 結構 struct • 參考以下程式 struct student //結構宣告(定義規格) { string name; char sex; int score; }; void main() { ... }

  19. 結構 struct • 參考以下程式 struct student{ ...}; //結構宣告(定義規格) void main() { student s[10]; for (int i=0;i<10;i++) { cout << “name:”; cin >> s[i].name; cout << “sex:”; cin >> s[i].sex; cout << “score:”; cin >> s[i].score; } }

More Related