[Pascal – TUT] Posts 2: The basic components of Pascal

1. Charset, key word, name

the. Charset, sign in Pascal

26 Large Latin alphabet: The,…,From
26 Latin small letter: the,…,from
Underscores: _
Ministry of decimal places: 0,…,9
The mathematical symbols: + – * / = < > ( )
The special symbols: . , ‘ : ; [] ? %
@ | ! & # $ {}
Blank space- how characters.
b. Tag
The keywords are reserved words of Pascal that programmers can use them in the design program to program. Do not use keywords to set for personal names as variable names, type names, function name ...
Some of Pascal keywords include:
And External Mod Shr
Array File Nil String
Begin For Not Then
Case Function Object To
Const Goto Of Type
Constructor If Or Unit
Div Implementation Packed Until
Do In Procedure Uses
Downto Inline Program Var
Else Interface Record Virtual
End Label Repeat While
Set Shl With Xor
c. Name
The name for the set of the program name, constant, type, variable, subroutine ... name is divided into 2 kind.
– Standard PASCAL name was put before, for example the function SIN, COS, LN,... Constant PI, INTEGER, BYTE, REAL…
– Name user-set.
+ Using the letters, the digits and underscore to
to name
+ Starting with the letter or an underscore ( _ )
then the letters or digits.
+ There is no space between name
+ Not to coincide with keywords.
+ The maximum length of the name is 127 characters, However
should set such that the compact and meaningful name.
+ Pascal did not catch the name coincides with
Standard name, but then the meaning of the standard name
not valid anymore => do not put the same name as the standard
Noted: Pascal does not distinguish uppercase and lowercase letters in keywords, Standard name or name. For example, "BEGIN" or "Begin" or "Begin" is the same. But we must learn the habit of writing in a consistent manner throughout the program name.

pascal

2. Semicolon and caption

the. Semi-colon
Semi-colon ( ; )for which separate statements.
After a command must have a semicolon.
Example: Write(‘Nhap so a:'); Readln(the);
b. Caption
Captions can put any position in program, but must be within braces { and } or (* and *).
Example: {This is the caption}
(* This is also a comment *).
3. Hang, type, variable
the. Hang
Hang is a constant quantity during program execution. There are two types of constants are constants standard and user-defined constants.
– Hang standards by Pascal predefined constants, eg constant PI, only constant color RED = 4, ...
Users do not need to redefine if deemed unnecessary. Constants are predefined in Pascal Unit. Need reference guide (help) for each Unit for the Unit has been defined constants..
– User-defined constants through the declaration.
Syntax:
CONST <ten_hang_1>=<gia_tri_hang_1>;

<ten_hang_n>=<gia_tri_hang_n>;
Example:
CONST a=5;
ch=’Q’;
b. Type
A data type is a set of values ​​that a variable of that type can get and a set of calculations can apply on those values. There are two types of standard type styles and user-defined types.
*/ Some standard data types:
– Integer

data types in Pascal

– Type of real

data types in Pascal

– Character style / string
data types in Pascal* User-defined type:
Syntax:
TYPE <ten_kieu> = <cac_thanh_phan_cua_kieu>;
Example:
TYPE Hoaqua=(man,With,two,oi);
that =(buoi,thapcam);
c. Variable
– Variable is a memory cell in the memory of the computer, the variable's value can change during program execution. Program management via variable variable variable names and each corresponding to a certain type of data.
– Variable declaration syntax:
WHERE <ten_bien>:<kieu_du_lieu>;
Example:
VAR a:integer;
b,c:real;
by:Fruit;
(* with Hoaqua is the data type styles defined *)

4. Arithmetic, Expressions, Statement

the. Arithmetic
*/ On numeric calculations

Phép toán 	Ý nghĩa 		Ví dụ
------------------------------------------------------
- 			Lấy đối số 		Đối số của 2 là -2
+ 			Cộng 			10 + 9 -> 19
- 			Trừ 			10 - 9 -> 1
* 			Nhân 			10 * 9 -> 90
/ 			Chia 			10 / 4 -> 2.5
Div 		Chia lấy phần nguyên 	10 div 3 -> 3
Mod 		Chia lấy phần dư 	10 mod 3 -> 1
(Div và Mod chỉ áp dụng cho kiểu nguyên).

*/ Some function, procedures

Hàm 		Ý nghĩa 			Ví dụ
------------------------------------------------------------
ABS(x) 		Trị tuyệt đối x 	Abs(-2) -> 2
SQR(x) 		Bình phương x 		Sqr(2) -> 4
SQRT(x) 	Căn bậc hai x 		Sqrt(9) -> 3
EXP(x) 		Hàm e^x 			Exp(3) -> e^3
LN(x) 		Hàm ln(x) 			Ln(2) ->ln2
SIN(x) 		Hàm lượng giác 		Sin(PI) -> 0
COS(x) 		Hàm lượng giác 		Cos(PI) -> 1
ARCTAN(x) 	Hàm lượng giác 		Arctan(0) ->0
INC(x) 		Tăng x lên 1 đơn vị <=> x:=x+1;
DEC(x) 		Giảm x xuống 1 đơn vị <=> x:=x-1;
SUCC(x) 	Cho giá trị tiếp theo của x succ(5) cho KQ 6
PRED(x) 	Cho giá trị trước đó của x PRED(5) cho KQ 4
ROUND(x) 	Làm tròn lên 		Round(8.6) -> 9
TRUNC(x) 	Làm tròn xuống		Trunc(8.6) -> 8
ORD(x) 		Lấy mã ASCII ký tự  Ord(‘a’) -> 97
CHR(x) 		Cho ký tự có mã ASCII Chr(65) -> ‘A’
ODD(x) 		Kiểm chẳn lẽ 		Odd(5) -> True

*/ Some logical operations
AND, OR, XOR, NOT.

X 		Y 		X OR Y		X AND Y 	X XOR Y 	NOT X
---------------------------------------------------------------------
FALSE 	FALSE 	FALSE 		FALSE 		FALSE 		TRUE
FALSE 	TRUE 	TRUE 		FALSE 		TRUE 		TRUE
TRUE 	FALSE 	TRUE 		FALSE 		TRUE 		FALSE
TRUE 	TRUE 	TRUE 		TRUE 		FALSE 		FALSE

Noted:

– The calculations compare (<> other, = Equal, > bigger, < less >= Greater or equal, <= Less than or equal) always returns type Booland.
– The logical operations are applied on integer, Based on the binary representation of the integer.

b. Expressions
– The expression is part of the statement include constant, variable, interconnected functions by the operations and parentheses.
Example:
(-b+sqrt(delta))/(2*the)
– Ordering perform calculations in Equation:

1. The expression in parentheses
2. Allows call
3. Not, –
4. *, /, DIV, MOD AND
5. +, -, OR, XOR
6. =, <>, <=,>=,<,>,IN

– Conventional priorities

+ Rule 1 : The operations will have a higher priority
will be counted before.
+ Rule 2 : In the same operation with the order
First, the calculation will be done from the left
turn right.
+ Rule 3 : Section in brackets from the inside out
is calculated to be a value.

c. Statement

– The statement identified a program of work that must perform to process the data described and declared. Have 2 Category statement:
+Single statement: As the statement contains no other statements.
+The command structure: including the compound statement, fork command control command selection, iteration statements,…
Noted: Compound statement is a group of commands to perform single row and placed in the BEGIN and END pairs keyword; (END accompanied by semicolons).

*/ Some menu commands:
– Assignation:

Syntax: <ten_bien>:=<expression>;
Example: the:=5+4/3;
b:=c+d/e;

Noted:
+ When a value is assigned to variable, it will replace the previous value of the variable Saved.
+ The expression on the right and left of statement would have to have the same type of data.

– Read data command

Read data command is command assign values ​​to variables when we entered from the keyboard. Have 3 Useful form
• Read(Bien1, Bien2, ..., BienN);
{available space or enter key to visit
admissions data for variables}
• Readln(Bien1, Bien2, ..., BienN);
{must use the enter key to turn enter
which data for variables}
• Readln;
{Getting machine stopped waiting clicked the enter key
usually to stop the screen lets you view the results}
Noted: We should not read command to enter data for the boundary which should enter readln command for entering the data for the variables with read command might lead to the break command (ie some orders not executed).

– Orders write data to the screen:
Have 3 Useful form:

• Write(Value1,Value2,…,VALUENET);
{ write the items out, the cursor is located at the end of the line}
• Writeln(Value1,Value2,…,VALUENET);
{ write the items out, the cursor is located at the top of the next line}
• Writeln;
{ just put your cursor down to the next line}
which: the value is the variable, constant, value or string
characters (must be enclosed in single quotes).
{Private Forums ‘ It is made by writing 2 sign ”}

Write a prescribed manner:
– For some real style:
:<width>:<number of decimal places>;
Example: write(the:4:5);
– For other data types:
:<width>;
Example: write(b:4);{and b is an integer}
Noted: As the number of variables digits than the width
Among them will be exported to the entire.
Example: b has a value of 12345.
When we write a write command(b:4);
12345

– Some other commands
• Clrscr; The command clears the screen and put the cursor on the upper left corner
• Gotoxy(x,and); place the cursor to the coordinates (x,and)
x: column from 1->80; and: goods from 1->25

Original article at: vietsource.net