Вы находитесь на странице: 1из 18

4-5. .

, .. , ,
, .
,
, ,
. ,
.
Pascal
Pascal


. .

var
< >:< 1>;
<1>[,<2>,]:<2>;
var
a,b:integer;
ch:char;

26



.
,
, ,
.


.
27

,
.
, ,
.
, ,
,

,
( ) .

, , ,
-.
ORD(X), .
ORD(X) , .. ORD(X)=X
, . ORD(X)

,
0 1( ), 0 255(),
0 65535(). -
,
ORD(X) .
:
PRED (X) (
ORD (X)-1
ORD(PRED(X))=ORD(X)-1
SUCC (X) - ,
ORD (X)+1 ..
RD(SUCC(X)=ORD(X)+1.
,
Var

28

C: Char;
.........
:=5;

PRED(C) 4, SUCC(C) 6.

,
, PRED(C)
, SUCC(X) .
.

, , . .
1 ,
.

1.
,
1
1
2
2
4


Byte
Shorting
Word
Integer
longint


0..255
-128.127
0...65535
-32768...32767
-2147483648...
2147483647

, .. ,
WORD, BYTE(
), LONGINT INTEGER, ,
SHORTINT.
,
2. b, s, w, i, l
29

BYTE, SHORTINT, WORD, INTEGER, LONGINT, x


; vb, vs, vw, vi, vl, vx

2.

Abs (x)
Chr (b)
Dec(vx[,i])
Inc(vx,[i])
Hi(i)
Hi(w)
Lo (i)
Lo(w)
Odd(l)
Random(w)


X
Char



vx i,

i - 1
vx i,

Byte
Byte
Byte
Byte
Boolean

i - 1




TRUE ,

, False
,

Sqr(X)
Swap(i)
Swap(w)


Integer
Word

0 <= <w



, , -
, (

).

, , :
Var
A: integer;

30

X, y: real;
Begin
A:=32767;
X:= a+2;
Y:=longint (a)+2;
Writeln (x:10:0,y:10:0 );
End.


-32677

32769



FALSE() TRUE ().
:
Ord (false) = 0;
Ord (true)=1;
False<True;
Succ (False)=True;
Pred (true)=False;
,
, ,
...............
Var
i : Boolean;
. . . .
for i:=false to true do ...


3.
A

Not A

31

False

True

True

False

4.
A
False

B
False

A and B
False

False

True

False

True

False

False

True

True

True

5.
A
False

B
False

A or B
False

False

True

True

True

False

True

True

True

True

6.
A

A xor B

False

False

False

False

True

True

True

False

True

True

True

False

if I mod 7 = 0 then
if I mod 13 = 0 then
writeln(I);
if (I mod 7 = 0) and (I mod 13 = 0) then
writeln(I);

32


.
0..255.
,
ORD.
ASCII. 7- , ..
128 0 127.
8- ,
, 0..255.
0..127
ASCII. 128-255
.
031 .
, .
-
:
7.

Bel
Ht

7
9

:

:

Lf

10

8, 1
:
,
,

VT
FF

11

.
:

12

.
:
,
33

Cr

.
:

13

enter ( read
readln
;

Sub

)
:

26

ctrl+Z;
Esc

.
:

27

esc;
.
CHAR ,
:
CHR (B) CHAR BYTE
;
UPCASE (CH) CHAR;
, CH CHAR,
Ch:
Var c1,c2:char;
Begin
C1:=upcase (s);
C2:=upcase ( );
Writeln (c1,

, c2);

End.

UPCASE .
34


Type
, :
Type
< 1>=<1>;
< 2>=<2>;
...


, .

, :
Type
Colors = (red, white, blue);

.
, , ,
:
Type
= (, , , , , , , , ,
, , );
Var
:;
..........
If = then writeln(!!!);

35

. !
,
:
t
TypeMonth=(jan, feb, mar, may, apr, jun, jul, aug, sep, oct,
nov, dec);
Var
Month:TypeMonth;
..........
If Month =

aug then writeln( !);


:
0, 1 ..
65535 ,

WORD
0,1 ..

. :
Type
Colors =(black, red, white);
Ordenal = (one, two, three);
Days = (monday, tuesday, wednesday);


:
Ord (black)=0,, ord (white)=2,
Ord (one)=0, ... , ord (three)=2,
Ord (monday)=0, ... , ord (wednesday)=2,

36


Var
col: colors;
Num:ordenal;
Day:days;


Col:=black;
Num:=succ (two);
Day:=pred (tuesday);


Col:=one;
Day:=black;

..
,
,
ord(x). :

WORD

,
.
,
:
Col:=one;
Col:=colors (0);

37

Col:=0;

.

:
Var col: (black, white);


,
, -.
- :
<. .>..<. .>
:
Type
Digit = 0.. '9';
Dig2 = 48..57;

type,
:
Var
Date: 1..31;
Month: 1 .. 12;
Lchr:A..Z;


:
1. .. ,
;
2. .
38

, .

Type
Days = (mo, tu, we, th, fr, sut, sa);
Weekend = sa.. su;
Var
w: Weekend;
...................
W:=sa;

ord(w) 5, PRED(W) .

, ,
,
,
.
8.
,

4
6
8
10
8

Single
Real
Double
Extended
Comp

7...8
11...12
15...16
19...20
19...20

-45...+38
-39...+38
-324...+308
-4951...+4932
-2^63+1...
+2^63-1

4-
10 .
39

s- ; ,
.m- .
23 63 ,
7..8 single 19..20 extended .
()
,

,
, .
,
single, double, extended
. ,

8087, 80287
181087.
,


.

extended,

.
:
{$N+, E+}
Type
RealType= real;

40

Var
Epsilon:= realtype;
Begin
Epsilon:=1;
while 1+epsilon/2>1 do
Epsilon:=epsilon/2;
Writeln (epsilon);
End.

REALTYPE -:
1.08420217248550-0019, extended.

:
{$N+, E+}
Type
Realtype = real;
Var
epsilon, eps1: realtype;
Begin
Epsilon:=1;
Repeat
Epsilon:=epsilon/2;
Eps1:=epsilon+1;
Until eps1>1;
Writeln (2*epsilon)
End.

, REAL
. ,
REAL
REAL EXTENDED. REAL
, ..
.
41

, ,
SINGLE DOUBLE: REAL
2-3 .
,
.
COMP,
. COMP-
"" , 19.. 20
. COMP
:
,
.. COMP
:
.

, 3.
REAL , INTEGER-
.
9.

Abs(x)
Real, integer
ArcTan(x)
Real
Cos (x)

Exp (x)

Frac (x)

Int (x)

Ln (x)

Pi
Random
-



Real

Real
Real


()
()




= 3.141592653...

Random(i)

Integer

Integer

0<=x<1

42

Randomize
Sin(x)
Sqr(x)
Sqrt (x)

Real
Real, integer
real

0<=i<1

Real

Real


()

43