认识pascal语言

上传人:小** 文档编号:54435287 上传时间:2018-09-12 格式:DOC 页数:7 大小:59.50KB
返回 下载 相关 举报
认识pascal语言_第1页
第1页 / 共7页
认识pascal语言_第2页
第2页 / 共7页
认识pascal语言_第3页
第3页 / 共7页
认识pascal语言_第4页
第4页 / 共7页
认识pascal语言_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《认识pascal语言》由会员分享,可在线阅读,更多相关《认识pascal语言(7页珍藏版)》请在金锄头文库上搜索。

1、PASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 1 of 7Chapter 1: Introduction to PASCAL第一課:第一課: 認識認識 PASCAL 語言語言1.1General Structure of PASCAL ProgrammingPASCAL 程序的基本結構程序的基本結構PASCAL Programming consist of three parts: PASCAL 程序包括三部分:1.( Program heading 程 序 標 題 )program XXX(input, output);2.( Decl

2、aration part 說 明 部 份 )constXXX; varXXX; typeXXX; procedureXXX; functionXXX;3. ( Program body 程 序 本 體 )beginXXX1;XXX2; end.*The crossed parts do not include in the syllabus. 刪除部分不包括在課程內。1.1.1. Program heading 程序標題程序標題I.Program heading is a statement starting with the word “program” and a program name

3、. 程序標題以program一字開始,並附以程序名稱。II.The program name is defined by user. For example: 程序名稱是由用戶自己定義的。例如:program Test;PASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 2 of 71.1.2. Declaration Part 說明部分說明部分I.It used to define various entities in the program. It can be omitted if not needed. 這部分用作為程序中不同項目下定

4、義。如沒有需要,這部分可以刪去。II. Constant definition 常量定義A. Constants are fixed values that do not change in the program. For example: 常量是在程序中不會改變的固定值。例如:constpi = 3.1415; SchoolName = CNEC Lau Wing Sang Secondary School BoilingPoint = 100;B. Using constant definition can make the program modified and read more

5、easily. 用常量定義可以使程序更容易易修改及理解。III. Variable definition 變量定義A. A variable is an memory cell that hold a certain type of value. 變量是一個貯存格,用以貯存某一種數值類型。B. The value stored in a variable can be changed in the program. 變量所貯存的值可以在程序中更改。C. The variable must be declared in this part before use in the program. F

6、or example: 變量在被程式運用之前,一定要在這部分說明。例如:varAge : integer; Name: string;IV. Program Body 程序本體A. This part contains statements that tell the computer what to do. For example: 這部份包含一連句子,用來告訴電腦要怎麼做。例如:beginreadln( Name );writeln( Hello!, Name)end.PASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 3 of 71.2

7、Reserved Word 保留字保留字I.In PASCAL, there are some words that are predefined or special meaning are called reserved words. 在 PASCAL 語言中,某些字具預定或特別定義,叫作保留字。II. All the reserved words cannot be redefined and use for any other purposes: 所有保留字都不可以重新定義或作其他用途:Reserved Word 保留字andarraybegincaseconstdiv dodownt

8、oelseendfilefor functionifmodnotofor procedureprogramrecordrepeatstringthen totypeuntilvarwhile1.3 Identifier 標識符標識符I.An identifier is used to indicate following items in PASCAL: 標識符是用來表示 PASCAL 中的以下項目: A. program name程序名字 B. constant常量 C. variables變量 D. procedures過程 II. It can be classified as 它可以分

9、類為: A. ( standard ) identifier ( 標 準 )標識符 B. ( user-defined ) identifier ( 用 戶 定 義 ) 標識符III. Standard identifier 標準標識符A. It had predefined meaning but can be ( redefined ) in the program. 它是具有多定意義的字,但可以在程式中( 重 新 定 義 )。B. Since redefinition of standard identifier may cause confusion, it is absolutely

10、 not recommended! 由於重新定義標準標識符會做成混淆,所以應該避免。Standard identifier 標準標識符absassignbooleancharchrclose copyeoffalseinputintegerlength ordoutputrandomrandomisereadreadln realresetrewriteroundsqrtstr texttruetruncvalwritewritelnPASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 4 of 7C. User-defined identifi

11、er 用戶定義標識符1. There are some rules for user to create a user-defined identifier. 以下是用戶定義標識符的守則:a. It must be a combination of letters and ( digits ). 它一定是由字母或( 數 字 )組成。b. It must be started with a ( letter ). 一定要由( 字 母 )開始。c. It cannot consist of any blank space or ( special character ). 不能包括任何空格或( 特

12、 別 符 號 )。d. ( Reserved words ) cannot be used. 不可以用( 保 留 字 )。e. It can be either uppercase or lowercase. 它可以大寫或小寫。Invalid Identifier 無效標識符Valid Identifier 有效標識符Reason 原因1 My Name MyNameBlank space is not allowed 不可以有空格2 3rd_day day3first character cannot be digit 第一個字符不可以是數字3 hk$ hk_dollarSpecial ch

13、aracter is not allowed 不可以有空格4 procedure stepReserved word is not allowed 不可以是保留字Notes:Either uppercase or lowercase can be use for reserved word and identifier. 注意:注意:大寫或小寫都適用於保留字及標識符。PASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 5 of 71.4 Punctuation 標點標點 I.Semicolon 分號 ; A. after program hea

14、ding 程序標題的末端 B. as a separator in declaration part and program body. 作為說明部份及程序本體的分隔符。 C. Cannot be used before the reserved word “end“. 不可加於保留字end前。program SemicolonExample; constX = 123; beginwriteln(Hello); writeln(X) end.II. Colon 冒號 : A. Used as a separator between variables and their ( data typ

15、e) . 用作分開變量及其( 數 據 類 型 )之間的分隔號。program ColonExample; var X : integer;III. Comma 逗號 , A. Used to separate items, expressions or variables in a list. 用來分隔一連串的項、表式或變量。prgram CommaExample; varA, B, C, D : real; IV. Single quotation mark 單引號 A. Used to enclose a character or string. 用於字符或字串前後。prgram SQMe

16、xapmle; beginwriteln( Usingsingle quotation mark. );end PASCAL Ch.1 Introduction to PASCALCNEC LWS GiPPage 6 of 7V. Period / Full stop 句號 . A. place after the last “end“. 用放最後的end字。program FullStopExample; beginwriteln( The program so short! ) end.1.5 Data Type 數據類型數據類型 I.Integer Data type 整數數據類A. It can be positive, negative or ( zero ). 它可以是正數、負數或( 零 )。B. It cannot contain any ( decim

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号