pascal問題

2006-12-05 5:25 am
我想問下pascal可唔可以轉background既顔色。
同埋readkey點先可以read到keyboard右手邊個九個數字鍵?

回答 (2)

2006-12-15 12:41 am
✔ 最佳答案

圖片參考:http://hk.yimg.com/i/icon/16/1.gif
以下的教學應該可以幫到你。


Pascal 輸入 / 輸出

引言
標準輸入
標準輸出



引言
一個程序必須能夠輸出它所計算出來的結果;否則,我們便沒法知道程序替我們達成了甚麼。同樣地,一個程序亦需要輸入來引導它的計算。Pascal 系統提供了標準的函數來幫助程序編寫員把資料送入程序(輸入)和顯示結果(輸出)。最容易使用的是 readln 和 writeln 函數,分別用作輸入和輸出的。有經驗的程序編寫員通常都會情願使用 read 和 write 函數來續字輸入或輸出。
標準輸入
Pascal 利用流群來達成輸入與輸出的。流群就象一個緩衝器,用來暫時存放輸入與輸出的資料。 標準輸入流群是 read 或 readln。 輸入函數 "read" 或 "readln" 輸入函數 read 或 readln 從輸入流群中越過白空間並摘取資料。它只摘取符合類型的字符並把其他的字符進行自動轉化。最後得到的是一組字串。雖然這樣會使它失去續字讀入的靈活性,但在處理上便變得容易一些了。



標準輸出
在 Pascal 裡,輸出流群的運作和輸入流群相同。 標準輸出流群是 write 或 "writeln。
輸出函數 "write" 或 "writeln"
從某方面看來,輸出是較輸入容易處理。簡單來說,輸出運算符 << 是把資料放在輸出流群以等待送往用戶處。 輸出運算符 << 還可以用來把輸出格式化。

一個簡單的輸入與輸出的範例:
id, score : integer; write('Enter student ID and score: '); read(id); read(score); write('Student ID: ', id); writeln(' score: ', score);
較複雜的範例:

尸轉為寸

program main; {Convert inches to feet and inches Input: inches Output: feet and inches} const {inches to feet conversion factor} in2feet = 12; var inches : integer; {number of inches} feet : integer; {number of feet} begin write('Enter number in inches: '); readln(inches); {Convert inches to feet and inches} feet := inches div in2feet; inches := inches mod in2feet; write(feet); write(' feet ', inches); writeln(' inches ') end.
較複雜的範例:

program main; {Convert inches to feet and inches Input: inches Output: feet and inches} const {inches to feet conversion factor} in2feet = 12; var inches : integer; {number of inches} begin write('Enter number in inches: '); readln(inches); write(inches div in2feet); write(' feet ', inches mod in2feet); writeln(' inches ') end.


進一步的範例:

Pea Counting Program

program main; {Demonstrate the features of I/O functions Input: number of pods, number of peas per pod Output: total number of peas} var number_of_pods, peas_per_pod, total_peas : integer; begin writeln('Press return after entering a number.'); writeln('Enter the number of pods:'); readln(number_of_pods); writeln('Enter the number of peas in a pod:'); readln(peas_per_pod); total_peas := number_of_pods * peas_per_pod; write('If you have '; number_of_pods); writeln(' pea pods'); write('and ', peas_per_pod); writeln(' peas in each pod, then'); write('you have ', total_peas); writeln(' peas in all the pods.') end.
範例程序的輸出:
Press return after entering a number. Enter the number of pods: 10 Enter the number of peas in a pod: 9 If you have 10 pea pods and 9 peas in each pod, then you have 90 peas in all pods.
2006-12-06 12:42 am
d := b + (trunc(x)+1)*d; writeln(d:0:0);


收錄日期: 2021-04-12 23:58:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061204000051KK04259

檢視 Wayback Machine 備份