1 / 60

計算機程式語言實習課

計算機程式語言實習課. 認識助教. 曾彥翔 ( Isfun ) 台北市立大安國小 畢業 台北市立金華國中 畢業 台北市立和平高中 畢業 淡江大學 資訊管理系 畢業 實驗室 E689 E-mail : helldeathscythe@gmail.com C++ online : http://helldeathscythe.myweb.hinet.net/ 興趣:羽球、電玩、漫畫 專長:軟體工程、人工智慧. 認識課程. 實習課占總成績多少 ? 作業 5% 點名 5% 分組報告 5% 上機考 10% 實習課點不點名 ?

jason
Download Presentation

計算機程式語言實習課

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. 認識助教 曾彥翔( Isfun ) 台北市立大安國小 畢業 台北市立金華國中 畢業 台北市立和平高中 畢業 淡江大學 資訊管理系 畢業 實驗室 E689 E-mail :helldeathscythe@gmail.com C++ online :http://helldeathscythe.myweb.hinet.net/ 興趣:羽球、電玩、漫畫 專長:軟體工程、人工智慧

  3. 認識課程 • 實習課占總成績多少? • 作業 5% • 點名 5% • 分組報告 5% • 上機考 10% • 實習課點不點名? • 計算機程式語言是什麼? • 資工系一定要會寫程式嗎?

  4. 問題 bug error 手無吋鐵的初學者 C++ Java 身精百戰的程式設計師... 毫無技巧的莽夫!? 經驗 技能 認識課程 C++:Microsoft Visual C++ 、Dev C++

  5. 問題 bug error 手無吋鐵的初學者 助教 教授 作業 考試 經驗 技能 認識課程 C++ online :http://helldeathscythe.myweb.hinet.net/

  6. 認識你的競爭對手 • 資工系 全台灣幾乎每所大學都有資工系 • 程式設計 • 工學院 • 電機系 • 機械系 • 航太系 • 理學院 • 數學系 • 物理系 • 資訊學門 • 資訊工程系 • 資訊管理系 • 資訊傳播系 • 資訊圖書系

  7. 分組報告 • 分組 • 題目如下 • enum語法 • beep語法 • poke語法 • peek語法 • sprintf語法 • puts與printf語法

  8. 教授名言 • 為什麼別人能這麼快就把程式寫完,我卻一直原地踏步? • 台上十分鐘,台下十年功 • 別看別人瞬間就把題目秒殺,他坐在電腦前的時間絕對超乎你想像! • 寫程式不會debug,就像游泳不會換氣 • 英文能力能夠彌補某方面的專業能力不足 • 助教不一定都是對的,相信自己的經驗

  9. 正式上課

  10. C語言 • Programming or codes • 指揮電腦執行人類所需的演算法 • 一系列指令的集合 • 機器語言、組合語言、高階語言 • C++是一種高階程式語言 B C(Ritchiie,Bell Lab) C++(Stroustrup,Bell Lab)

  11. C語言 編譯程式 Compiler Dev C++,VC++ C/C++ language Source Code Hello.cpp Binary Code Hello.exe

  12. C語言 編譯程式 Microsoft Visual C++ 6.0 Bloodshed Dev-C++http://www.bloodshed.net/devcpp.html

  13. C編譯環境 #include <stdio.h> int main() { … return 0; }

  14. C編譯環境 • 程式內容中有許多符號 • 「#」之後的東西是要給compiler看的 • 「{ }」是要把一段程式碼包起來用的 • 「;」是指程式結尾,如同文法中的。 • 「//」表示註解 給設計師看的 • 「/*」和「*/」表示註解 給設計師看的 • 「\n」特殊字元

  15. printf 語法 • 起手式 printf 輸出在螢幕上 • Hello World #include <stdio.h> int main() { printf(“hello world”); return 0; }

  16. 解決程式結束畫面停留問題

  17. system 語法 執行dos指令 system( const char* ); 用途 • 呼叫其他程式 • 執行dos指令 • ... 稍後詳談… system(“pause”);

  18. 換行 • 即按下Entre的意思 • 「\n」特殊字元,表示換行(new line) • 「\a」特殊字元,讓系統發出”嗶”響鈴 • puts();的效果!? printf(“hello world\n”);

  19. scanf 語法 • 顯示數字 #include <stdio.h> int main() { printf(“the number is %d”,11+13); system(“pause”); return 0; }

  20. scanf 語法 • 顯示數字 • “%d”是顯示格式的指令,意味「以十進位表示後面的參數」 ,即顯示11+13的值 • “%d”中的d是取自十進位「decimal」 printf(“the number is %d\n”,11+13);

  21. scanf 語法 • 螢幕輸出  鍵盤輸出 • 將鍵盤輸入的”資料”讀入電腦 • 變數x接收資料 11 X

  22. scanf 語法 • 變數 • 如同數學中的 x,y,z • 但是使用變數時,必須先宣告(ps.) 變數型態 變數名稱 int x ; X 宣告

  23. scanf 語法 • 輸入數字 #include <stdio.h> int main() { int num; scanf(“%d”,&num); printf(“the number is %d\n”,num); system(“pause”); return 0; }

  24. 運算 • 加法器 #include <stdio.h> int main() { int num1,num2; printf(“num1=”); scanf(“%d”,&num1); printf(“num2=”); scanf(“%d”,&num2); printf(“%d+%d=%d\n”,num1,num2,num1+num2); system(“pause”); return 0; }

  25. 程式流程的選擇 • if…then…else • switch • goto 程式流程的迴圈 • do…while • while • fot

  26. 給阿發老師敎~ XD

  27. 巨集 • 除了int以外,數值還有很多種表示方式 • 共用的常數,如 圓周率 ASCII code • 方便設計師更容易撰寫程式 • 只要程式碼遇到巨集所定義的字通通自動替換 #define 巨集名稱 常數 #define 巨集名稱 字串 #define 巨集名稱 函數

  28. 巨集 #include <stdio.h> #define begin { #define end } int main() begin int num1,num2; printf(“num1=”); scanf(“%d”,&num1); printf(“num2=”); scanf(“%d”,&num2); printf(“%d+%d=%d\n”,num1,num2.num1+num2); system(“pause”); return 0; end

  29. 計算三角函數 #include <stdio.h> #include <cmath> int main() { int num; scanf(“%d”,&num); printf(“sin(%d)=%d\n”,num,sin(num*3.14/180)); system(“pause”); return 0; }

  30. 計算三角函數 #include <stdio.h> #include <cmath> int main() { int num; scanf(“%d”,&num); printf(“sin(%d)=%d\n”,num,sin(num*3.14/180)); printf(“sin(%d)=%d\n”,num,cos(num*3.14/180)); printf(“sin(%d)=%d\n”,num,tan(num*3.14/180)); system(“pause”); return 0; }

  31. 計算三角函數 #include <stdio.h> #include <cmath> #define pi 3.14 int main() { int num; scanf(“%d”,&num); printf(“sin(%d)=%d\n”,num,sin(num*pi/180)); printf(“sin(%d)=%d\n”,num,cos(num*pi/180)); printf(“sin(%d)=%d\n”,num,tan(num*pi/180)); system(“pause”); return 0; }

  32. 計算三角函數 #include <stdio.h> #include <cmath> #define pi 3.1415926535897932384626433832795 int main() { int num; scanf(“%d”,&num); printf(“sin(%d)=%d\n”,num,sin(num*pi/180)); printf(“sin(%d)=%d\n”,num,cos(num*pi/180)); printf(“sin(%d)=%d\n”,num,tan(num*pi/180)); system(“pause”); return 0; }

  33. 巨集函數 • 同理,巨集函數就是定義常用的函數 #include <stdio.h> #define product(a,b) a*b int main() { printf("%d\n",product(3,7); return 0; }

  34. 巨集函數 #include <stdio.h> #define add(a,b) a+b int main() { printf("%d\n", add(1,2) ); printf("%d\n", add(3,4) ); system(“pause”); return 0; }

  35. 巨集函數 #include <stdio.h> #define add(a,b) a+b #define product(a,b) a*b int main() { int a = add(1,2); int b = add(3,4); printf("%d\n", product(a,b) ); return 0; }

  36. 巨集函數 • 只要程式碼遇到巨集所定義的自通通自動替換 #include <stdio.h> #define add(a,b) a+b #define product(a,b) a*b int main() { printf( "%d\n",product( add(1,2) , add(3,4) ) ); return 0; }

  37. 巨集函數 #include <stdio.h> #define pi 3.14 #define circum(r) 2*pi*r #define area(r) pi*r*r int main() { int r; scanf(“%d”,&r); printf(“原周長=%d\n”,circum(r)); printf(“面積=%d\n”, area(r)); system(“pause”); return 0; }

  38. 巨集函數 #include <stdio.h> #define say(name,message) printf("%s說:%s\n",name,message) int main() { char n[10],m[50]; printf("NAME:"); scanf("%s",&n); printf("Message:"); scanf("%s",&m); say(n,m); return 0; }

  39. system 語法

  40. system 用途 執行dos指令 system( const char* ); 修改檔名 流水號 system(“ren pic0.jpg pic1.jpg”); system(“ren pic1.jpg pic2.jpg”); system(“ren pic2.jpg pic3.jpg”); ...

  41. 程式的風格與習慣 • 空白與縮排 • (a) int main() { int a,b,c; a=5; b=4; c=3; } • (b) int main() { int a,b,c; a=5; b=4; c=3; } • (c) int main() { int a,b,c; a=5; b=4; c=3; }

  42. if (n>0) { if (a>b) { z=a; } } else { z=b; } if (n>0) { if (a>b) { z=a; } else { z=b; } } If (n>0) if (a>b) z=a; else z=b; 程式的風格與習慣 • 計算機語言歷史上著名的"Dangling Else“

  43. 程式的風格與習慣 • if 的有效範圍C 的發明人曾經強調else會承接最接近的 if保留字。在 C 語言上已經闡述其特性,所以所有的 C 編譯器都會以相同的方法來處理 Dangling Else。 • { } 的使用 • 如果指令只有一個,可以省略{ } • { } 內寫幾條指令都可以

  44. 程式的風格與習慣 int main() { int a=2,b=2; if (a==1) if (b==2) cout << "a“ << endl ; else cout << "b“ << endl; cout << "c“ << endl; }

  45. Number Types 1 byte = 8 bits

  46. Number Types 1 byte = 8 bits

  47. 記憶體溢位 int main() { int a; cin >> a; cout << a <<endl; if (a > 3000000000) cout << "too big" << endl; else cout << a << endl; return 0; }

  48. 字元

  49. 字元 int main() { int n; char a,b; cin >> a; cin >> b; n= abs(b-a) ; cout << a << "與" << b << "相差" << n << "個字母\n"; system("pause"); return 0; }

  50. 作業 • 撰寫一簡易計算機可執行+, -, *, /運算 CAL> 5.5 + 3.3  8.8 CAL> 5.5 - 3.3  2.2 CAL> 3.5 * 3  10.5 CAL> 6.4 / 2  3.2 CAL> 3.3 / 0  Divided by zero CAL> 2.5 ^ 4  unknown operator: ^ CAL> 0+0  Bye! (結束執行)

More Related