流程圖 if 流程 X>10 Raptor http://raptor.martincarlisle.com/ Raptor flow chart 1 if else 流程 x>y Raptor flow chart 2
練習 寫一個程式, 輸入西元年份 yy, 輸出該年是否閏年 yy is divisible by 400 yy is divisible by 4 but (not divisible by 100) Raptor flow chart 3 Switch Case 概念 mm... Raptor flow chart 4
switch 流程 mm=1 days = 31 break mm=2 days = 28 break default 練習 : 處理整數成績 Raptor flow chart 5 for 流程 i=0 i<10 i++ 練習 : 計算 1 到 100 的偶數和 Raptor flow chart 6
while 流程 i=0 i<10 i++ Raptor flow chart 7 do while 流程 i=0 i++ i<10 Raptor flow chart 8
關於迴圈 (Loops) 迴圈之基本要素 控制變數初值設定 檢驗條件 控制變數改變 三種迴圈敘述之不同 常見錯誤 Off by one ( 少一次 ) 無窮迴圈 迴圈與執行效率 練習 寫一程式, 要求使用者不斷輸入及 Echo 學生成績, 直到輸入為負時為止 印出學生總人數及平均成績 Raptor flow chart 9 結構化程式 goto Raptor flow chart 10
虛擬 / 偽代碼 (Pseudo Code) 幫助思考程式流程 沒有程式語言正式, 省略細節, 易寫易懂 限定使用結構化程式流程控制, 容易以程式語言改寫 較流程圖方便 紙筆追蹤測試 (Tracing an algorithm) Raptor flow chart 11 Euclid 輾轉相除法 輸入正整數 a & b 只要 ( b <> 0 ) { r = a b 後的餘數 ; a = b; b = r; } gcd = a; 測試數據 1: a=12, b=56 2: a=120, b=18 3: a=105, b=13 4: a=356, b=220 5: a=2136, b=3312 練習 :1+2+...+n <= limit Raptor flow chart 12
練習 : 判斷是否質數的篩檢法 要判斷 x 是否質數, 可用 d (2... x), 逐一檢查是否能整除 x 如果都不能整除,x 便是質數, 否則 x 就不是質數 函式 isprime(x) 印出 1 到 100 的所有質數 Raptor flow chart 13 Raptor: Flowchart programming 輸出 Adding block / symbols 變數 Raptor Flowchart 14
Enter an statement x 0 Raptor Flowchart 15 Create output symbol 輸入 scanf 輸出 printf 選擇 if, switch 廻路 for, while Raptor Flowchart 16
Running 執行 速度 大小 Raptor Flowchart 17 Add Toggle breakpoint Raptor Flowchart 18
Generate 3GL (C++/C#) Generate executable file Raptor Flowchart 19 練習 :Digital Clock Raptor flow chart 20
Graphic window opening and closing procedures Open_Graph_Window( X_Size, Y_Size ) Close_Graph_Window Set_Window_Title("Title") Drawing procedures Put_Pixel( X, Y, Color ) Draw_Line( X1, Y1, X2, Y2, Color ) Draw_Box( X1, Y1, X2, Y2, Color, Filled/Unfilled ) Draw_Circle( X, Y, Radius, Color, Filled/Unfilled ) Draw_Ellipse( X1, Y1, X2, Y2, Color, Filled/Unfilled ) Draw_Arc( X1, Y1, X2, Y2, StartX, StartY, EndX, EndY, Color ) Clear_Window( Color ) Flood_Fill( X, Y, Color ) Display_Text( X, Y, String Expression, Color ) Display_Number( X, Y, Number Expression, Color ) Freeze_Graph_Window Update_Graph_Window UnFreeze_Graph_Window Graphic window "size" functions Get_Max_Width Get_Max_Height Get_Window_Width Get_Window_Height Raptor flow chart 21 Keyboard input procedure Wait_For_Key procedure call Delay_for(0.2) // 0.2 sec Clear_Console Draw_Circle(X, Y, 7, Blue) Mouse input procedures Wait_for_Mouse_Button( Button ) Get_Mouse_Button( Button, X, Y ) Mouse input functions Mouse_Button_Pressed( Button ) Mouse_Button_Released( Button ) Get_Mouse_X Get_Mouse_Y Keyboard input functions Key_Hit Get_Key // ASCII Get_Key_String Is_Open To_Character (n) To_ASCII (ch) Redirect_Input ("file.txt") Redirect_Input (True) Redirect_Input (False) Redirect_Output ("file.txt") Redirect_Output (False) Raptor flow chart 22
Function Basic math: sqrt, log, abs, ceiling, floor Trigonometry: sin, cos, tan, cot, arcsin, arccos, arctan, arccot Miscellaneous: Length_Of, Random Draw_Bitmap( Load_Bitmap("abc.bmp"),x,y,w,h) Mouse input procedures Wait_for_Mouse_Button( Button ) Get_Mouse_Button( Button, X, Y ) Mouse input functions Mouse_Button_Pressed( Button ) Mouse_Button_Released( Button ) Get_Mouse_X Get_Mouse_Y Sound Play_Sound(wav) Play_Sound_Background("snd.wav") Play_Sound_Background_Loop("snd.wav") Raptor flow chart 23 Graphics window query function color = Get_Pixel ( X, Y ) Set_Font_Size(Size) Get_Font_Height Get_Font_Width Random_Color //0 15 Random_Extended_Color //0-241 Closest_Color (R,G,B) //0-255 Draw_Bitmap (Bitmap, X, Y, W, H) Get_Pixel Returns 0 for Black, 1 for Blue,, 16 for White RAPTORGraph Colors Black, Blue, Green, Cyan, Red, Magenta, Brown, Light_Gray, Dark_Gray, Light_Blue, Light_Green, Light_Cyan, Light_Red, Light_Magenta, Yellow, White How to animate an object in RAPTORGraph Place the following inside of a loop Draw an object relative to an X,Y point with the drawing procedures Delay_For some small time period Draw the object again in white (i.e. erase it) Update the X,Y point where you are drawing by some small offset Raptor flow chart 24