[Pascal – TUT] Posts 2: The basic components of Pascal
1. Charset, key word, name
the. Charset, sign in Pascal
26 Latin small letter: the,…,from
Underscores: _
Ministry of decimal places: 0,…,9
The mathematical symbols: + – * / = < > ( )
The special symbols: . , ‘ : ; [] ? %
@ | ! & # $ {}
Blank space- how characters.
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
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.
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
2. Semicolon and caption
After a command must have a semicolon.
Example: Write(‘Nhap so a:'); Readln(the);
Example: {This is the caption}
(* This is also a comment *).
– 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:
…
<ten_hang_n>=<gia_tri_hang_n>;
Example:
CONST a=5;
ch=’Q’;
…
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.
– Integer
* User-defined type:
TYPE <ten_kieu> = <cac_thanh_phan_cua_kieu>;
Example:
TYPE Hoaqua=(man,With,two,oi);
that =(buoi,thapcam);
…
– Variable declaration syntax:
Example:
VAR a:integer;
b,c:real;
by:Fruit;
(* with Hoaqua is the data type styles defined *)
…
4. Arithmetic, Expressions, Statement
*/ 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
DC have name no more calculations, at nguoai sd have a '-‘ to insulate, Then run k DC
Kong has another name flashed calculations, There are few signs sd ” – ” then it without knowing correct error
Based in the know how Pascal sir!??
using sqrt(x) nhé.
sqrt(x)
Example sqrt(4)= 2
symbols mean sir div >?
div meaning integer portion divided nhé. CEO 5 div 3 get 1.
I want to get excess to split 2 digits after the comma, then how ạ?
as are light writeln(with:0:2);
Width with both parts decimal digits is limited as yet sir? Or select any number of well sir?
sign [‘0’..’9′] What is it?
An array of characters from a character ‘0’ to the character ‘9’
I'm writing now
then i see an error
then e insert into the program or want to create more 1 type j in the middle(trong free pascal)
You use the keys to move the mouse pointer to where to insert.
Write a program to calculate the average of 3 integers entered from the keyboard. Average score according to specifications: reserved 6 spot and take 2 decimal
Sign ‘, What does it mean for example
Writeln (‘ total 2 number is ‘, b:6:2);
It is a sign to identify 1 Chain.
For some real style:
::
;Example: write(the:4:5);
the:4:5 What is it?
It means take 4 integer part, 5 the number of decimals
+13 What does that mean