1 / 48

電腦與問題解決

電腦與問題解決. 高慧君 台北市立南港高中 2010 年 4 月. 教學目標. 培養學生演算法思維的技巧 ( 垂直思考 ) 。 培養學生運用電腦解決問題的能力。 授課重點 引導學生如何分析問題 引導學生如何擬定解題策略 引導學生如何 ( 運用電腦 ) 實作解題過程. 軟體應用與電腦解題. 第三單元:電腦軟體 ( 應用軟體實作 ) 人類運用電腦來解決特定的問題,例如:上網查資料、使用試算表來統計與分析資料等 第五單元:電腦與問題解決 ( 程式設計 ) 人類設計電腦程式來解決問題,電腦可取代人力,完成資料的自動化處理. 為何選 Visual C#.

halen
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. 電腦與問題解決 高慧君 台北市立南港高中 2010年4月

  2. 教學目標 • 培養學生演算法思維的技巧(垂直思考)。 • 培養學生運用電腦解決問題的能力。 • 授課重點 • 引導學生如何分析問題 • 引導學生如何擬定解題策略 • 引導學生如何(運用電腦)實作解題過程

  3. 軟體應用與電腦解題 • 第三單元:電腦軟體(應用軟體實作) • 人類運用電腦來解決特定的問題,例如:上網查資料、使用試算表來統計與分析資料等 • 第五單元:電腦與問題解決(程式設計) • 人類設計電腦程式來解決問題,電腦可取代人力,完成資料的自動化處理

  4. 為何選Visual C# • 免費:Visual C# 2008 Express • C#是C Like語言 • 本質上是C的語法,但是沒有C++那麼難 • 提供主控台應用程式:易學易用 • 支持視窗軟體(Windows)的開發

  5. 教學內容 • 傳統主題:基礎程式設計 • 輸入與輸出 • 變數與陣列 • 運算式 • 流程控制 • 新興主題:mp3鬧鐘 • 視窗程式開發 • 多媒體程式開發

  6. 新增專案

  7. 操作環境介紹 執行程式 程式碼編輯區

  8. 程式進入點 Main()

  9. 程式碼 Console.WriteLine() 是一種資料輸出的方法 Console.ReadLine() 是一種資料輸入的方法

  10. 執行程式

  11. 資料的輸入與輸出

  12. 輸出資料到螢幕 • Console.Write(); • Console.WriteLine(); ※智慧型輸入 在打程式碼過程中,會自動顯示出物件的屬性方法供你選擇,很方便。

  13. 由鍵盤輸入資料 • Console.Read(); • Console.ReadLine();

  14. 由文字檔案輸入資料

  15. 變數與陣列

  16. 常用的資料型態 • 整數:int(32位元), long(64位元) • 小數:float, double • 字串:string • 布林值:bool • 控制項物件:Button, Label

  17. 陣列的宣告 • 語法1 (固定長度) 資料型別[ ] 陣列名稱 = new 資料型別[陣列大小]; 例如:int[ ] score = new int[10]; 例如:Button[] Disk = new Button[] {disk1, disk2, disk3} • 語法2 (不定長度) ArrayList 陣列名稱 = new ArrayList();

  18. 運算子

  19. 指定運算

  20. 算術運算 • 加 + • 減 - • 乘 * • 除 / • 取餘數 %

  21. 關係運算

  22. 邏輯運算

  23. 遞增及遞減運算 • 遞增運算(++) • 遞減運算(--)

  24. 流程控制

  25. 循序結構 • 程式的執行順序,是由程式的第一行敘述開始,由上而下逐步執行到最後一行。

  26. 選擇結構 if (條件式) { 敘述區塊1; } else { 敘述區塊2; }

  27. 重複結構 條件式: while (條件式) { 敘述區塊; } 計數式: for (int i=初值; 條件; 增值) { 敘述區塊; }

  28. 解題練習

  29. 範例1:輸入與輸出 任務)請使用者輸入姓名與年齡。 static void Main(string[] args) { string YourName; int age; Console.Write("請輸入你的名字:"); YourName = Console.ReadLine(); Console.WriteLine("Hello, {0}", YourName); Console.Write("請輸入你的年齡:"); age = Int.Parse(Console.ReadLine()); Console.WriteLine("{0}您好!您是{1}歲", YourName, age); Console.ReadLine(); }

  30. 範例2:檔案讀取 任務)讓使用者輸入一個成績,判斷是否及格。 using System.IO; FileInfo file = new FileInfo("c:\\grade.txt"); StreamReader sr = file.OpenText(); int score1, score2, score3; double average; score1 = int.Parse(sr.ReadLine()); score2 = int.Parse(sr.ReadLine()); score3 = int.Parse(sr.ReadLine()); average = (score1 + score2 + score3) / 3.0; Console.WriteLine("平均是{0:f}分", average); Console.Read(); sr.Close();

  31. 範例3:選擇結構 任務)讓使用者輸入一個成績,判斷是否及格。 int Score; Console.WriteLine(“您好,請問您的國文成績是幾分?”); Score = int.Parse(Console.ReadLine()); if (Score<60) { Console.WriteLine(“不及格囉~您的國文是{0}分”, Score); } else { Console.WriteLine(“恭喜及格~您的國文是{0}分”, Score); }

  32. 範例4:重複結構 任務)讀入檔案的10個分數。使用for語法。 using System.IO; FileInfo file = new FileInfo("c:\\grade.txt"); StreamReader sr = file.OpenText(); for (int i=1; i<=10; i++) { Console.WriteLine(sr.ReadLine()); } Console.Read(); sr.Close();

  33. 範例5:重複結構 任務)讀入檔案的不定個數的分數。使用while語法。 using System.IO; FileInfo file = new FileInfo("c:\\grade.txt"); StreamReader sr = file.OpenText(); while (sr.Peek() > 0) Console.WriteLine(sr.ReadLine()); } Console.Read(); sr.Close();

  34. 範例6:陣列 任務)讀入檔案中的10個分數。 using System.IO; FileInfo file = new FileInfo("c:\\grade.txt"); StreamReader sr = file.OpenText(); int[ ] score = new int[10]; for (int i=0; i<10; i++) { score[i]= int.Parse(sr.ReadLine()); } Console.Read(); sr.Close();

  35. 範例7:陣列 任務)讀入檔案中的不定個數的分數。 using System.IO; FileInfo file = new FileInfo("c:\\macdonald.txt"); StreamReader sr = file.OpenText(); ArrayList score = new ArrayList(); while (sr.Peek() > 0) { score.Add(sr.ReadLine()); }

  36. 視窗軟體實作 mp3鬧鐘

  37. 新增視窗應用程式專案

  38. 從功能表的「工具─選擇工具箱項目」選取Windows Media Player選項。

  39. 拖曳「一般─Windows Media Player」控制項到表單中

  40. 拖曳「所有Windows Form─DateTimePicker」到表單中設定「Format:Time」、「ShowUpDown:True」

  41. 程式邏輯 • 設定鬧鐘時間,選取欲播放的MP3歌曲 • 按下「開始」按鈕,程式會縮小到工作列。 • 待時間到時,程式會放大並播放MP3歌曲。

  42. 事件:調整表單大小 private void Form1_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { notifyIcon1.BalloonTipText = "哈哈,看不到我了吧"; notifyIcon1.ShowBalloonTip(3000); this.ShowInTaskbar = false; } // end if }

  43. 事件:點擊常駐列圖示 private void notifyIcon1_DoubleClick(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; }

  44. 事件:按下選歌按鈕 private void button1_Click(object sender, EventArgs e) { OpenFileDialog myFD = new OpenFileDialog(); myFD.Filter= "聲音檔(*.mp3)|*.mp3"; if (myFD.ShowDialog() == DialogResult.OK) { textBox1.Text = myFD.FileName; axWindowsMediaPlayer1.URL = myFD.FileName; axWindowsMediaPlayer1.Ctlcontrols.stop(); } // end if }

  45. 事件:按下播放按鈕 private void button2_Click(object sender, EventArgs e) { axWindowsMediaPlayer1.Ctlcontrols.play(); }

  46. 事件:按下停播按鈕 private void button3_Click(object sender, EventArgs e) { axWindowsMediaPlayer1.Ctlcontrols.stop(); }

  47. 事件:按下開始按鈕 private void button4_Click(object sender, EventArgs e) { timer1.Start(); this.WindowState=FormWindowState.Minimized; this.ShowInTaskbar = false; }

  48. 事件:計時器 private void timer1_Tick(object sender, EventArgs e) { if ((dateTimePicker1.Value.Hour == DateTime.Now.Hour) && (dateTimePicker1.Value.Minute == DateTime.Now.Minute) && (dateTimePicker1.Value.Second == DateTime.Now.Second)) { if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; } notifyIcon1.BalloonTipText = "醒醒!!"; notifyIcon1.ShowBalloonTip(5000); timer1.Stop(); axWindowsMediaPlayer1.Ctlcontrols.play(); // Start the music! }

More Related