任何人皆可以在任何一篇日誌下留言,用法如 xanga 差不多。
除了我(MK)以外,其實任何人(包括老師、同學)也可以編寫日誌的!如果你想編寫日誌,你必須先成為 WordPress 用戶,然後我可以把你加入成為本網誌的「投稿人」。
Blog Admin 19:50
任何人皆可以在任何一篇日誌下留言,用法如 xanga 差不多。
除了我(MK)以外,其實任何人(包括老師、同學)也可以編寫日誌的!如果你想編寫日誌,你必須先成為 WordPress 用戶,然後我可以把你加入成為本網誌的「投稿人」。
Test and Exam 19:42
日期︰2007年9月13日(星期四,Day 1)
時間︰第二節(四善)或第三節(四光、四正)
範圍︰中三所教過的 Pascal programming
溫習要點︰請溫習大家上學年 Miss Lui 派過給大家的筆記。
四正的測驗時間本來是中文堂。電腦科老師們已經向黃老師借了堂,當日的第五堂將會上中文。
Module A 19:26
原文︰http://student.puiching.edu.hk/viewtopic.php?topic=22167&forum=3&3
第三課 : Arithmetic in Pascal
重點:
1. 現實世界的數學符號不一定在pascal compiler內有相同的效果。 例如 x號 需要變成 *號; 大括號{}和中括號[]要變回小括號(); 除號分為 (1) 實數除real division / 和 (2) 整數除integer division div等等
2.數學函數的使用和規範 (argument type和function type的認識)。
3. 考考你: 要清楚明白pascal compiler對type的理解, 請你指出下列那一句pascal statement包含syntax error?
program type_mismatch_errors_demo;
{check which statement(s) has/have syntax error?}
var
a, b : integer;
c, d : real;
e, f : string;
g, h : char;
i, j : boolean;
begin
(* group one : numbers manipulation *)
a := 1 + 2 - 4;
b := 1 + 4 / 2;
c := 1 + 2 - 4;
d := 1 + 4 / 2;
(* group two : text manipulation *)
e := 'CHUN Wai Tung';
f := 'Mr.' + e;
g := 'a';
h := f;
f := g;
h := 'Chungsir';
f := 'a';
(* group three : boolean manipulation *)
i := TRUE;
j := i and FALSE;
i := (4>3) and j or ('a'>'e');
j := 1 or 4;
(* group four : mix type data manipulation *)
a := c;
d := b;
a := e;
d := h;
j := a;
end.
堂上小玩意: pascal的bitwise and, or, not operator …
堂上問過大家的IQ題:
若果pascal定義:
1 AND 4 = 0
1 AND 7 = 1
3 AND 7 = 3
11 AND 12 = 8
那麼…
6 AND 4 = ?
23 AND 70 = ?
100 AND 200 = ?
若果pascal定義:
1 OR 4 = 5
1 OR 8 = 9
1 OR 7 = 7
3 OR 9 = 11
那麼…
6 OR 4 = ?
23 OR 70 = ?
100 OR 200 = ?
若果pascal定義:
NOT 4 = -5
NOT 120 = -121
那麼…
NOT 2000 = ?
NOT -1 = ?
無獎遊戲… ![]()
不准打入機run, 要玩推理…
=========================================
Real number formatting exercise
冒號對各種類的值格式化 (format) 有什麼效果?可下載這個 program 試試。
| Code: |
var
x: real;
a: integer;
s: string;
begin
a := 352;
x := 42.35454;
s := 'Pui Ching';
writeln('----|----1----|----2----|----3----|----4----|----5----|----6');
writeln(a:5);
writeln(a:2);
writeln;
writeln('----|----1----|----2----|----3----|----4----|----5----|----6');
writeln(x);
writeln(x:5);
writeln(x:10);
writeln(x:5:3);
writeln(x:10:3);
writeln(x:5:6);
writeln;
writeln('----|----1----|----2----|----3----|----4----|----5----|----6');
writeln(s);
writeln(s:15)
end.
|
試試改動冒號後的數字,看看有什麼效果。
家課:Pascal programming Chapter 3(共二題)
Module A 19:01
原文︰http://student.puiching.edu.hk/viewtopic.php?topic=22167&forum=3&3
第一課 : type and simple program
重點:
1. 記著pascal是一種對type非常嚴格的程式語言, 講求門當戶對, 例如real number 4是不可以放在integer的variable之內的。每一種data type都有它自已的限制範圍, 例如 turbo pascal的integer type variable只可以處理-32768至32767之間的整數。
*** 一則關於資料型態故事的中文文章 ***
「1996 年 6 月,法國雅利安五號火箭才升空不到一分鐘,就自動銷毀了,直接與間接造成幾十億元的金錢損失,以及使雅利安計畫停滯達數月之久。對失敗的原因,調查委員會 這樣描述:「在主引擎點火後 37 秒,導向與高度的資訊完全喪失。」原因是:「內部參考系統軟體的規格與設計錯誤。」最後發現錯誤的地方出在某一行程式,要把 64 位元的數字裝填到 16 位元的位置 (應該是把一個屬於 double 型態的數值,存入一個 short 型態的變數裡面;譬如說 short n=exp(12); 就會發生這種情況),使得電腦溢流 (overflow) 爆掉了。」
2. 留心理解所有red alert紅色error提示句。 有不明白的可以上載到討論區查詢。 當pascal compiler (turbo pascal) 不明白你給出的指令的時候, 它會發出「紅色警號」。大家要學習好好和電腦「溝通」, 要注意有時候電腦沒有說你有錯, 你的問題可能還要大! No news IS NOT good news!
3. 要熟習純keyboard操作, 以下是必須用到的commands:
- CTRL + F9 (RUN)
- ALT + F9 (COMPILE)
- ALT + F5 (CHECK OUTPUT SCREEN)
- CRTL + F1 (ASK FOR DETAILS)
- F3 (OPEN FILE)
- F2 (SAVE FILE)
Class Demo : Finding the sum of integers 1 to 1000.
| Code: |
program test;
var
sum, i : longint;
begin
sum := 0;
for i := 1 to 1000 do
sum := sum + i;
writeln(sum);
end.
|
|
|
Classwork : Finding the sum of of all multiples of 7 from 1 to 1000.
若果你對這一條題目有問題, 我們鼓勵大家上pascal learning web多做一些淺的題目:
Exercise 2-1 Rectangle
Exercise 2-2 Sell Disks
Exercise 2-3 Letter
Exercise 2-4 Circle
Exercise 2-5 Age
| Code: |
program test;
var
sum, i : longint;
begin
sum := 0;
i := 1;
while i <= 1000 do
begin
sum := sum + i;
i := i + 1;
end;
writeln(sum);
end.
|
你們喜歡while loop的話便用while loop好了, 我比較喜歡for loop。
program print_ASCII_table;
uses
crt;
var
i : integer;
begin
clrscr;
for i := 0 to 255 do
begin
if (i>=32) then
write(' ', i:3, ':', chr(i),' ');
end;
writeln;
end.
小貼士: 若你想用keyboard直接打入一個ascii code, 可以按 ALT+該碼的對應ASCII VALUE (必須以NUMERIC KEYPAD輸入), 例如ALT-248是度數的符號、ALT-253是平方的符號。