, , , , . , , , . , .
.
[3].
, , , . , , - . , , .
, . , TYPE. TYPE , .
. 1.
. 1
type
day = (mon, tue, wed); color = (white, red, blue)
day color , day : mon, tue, wed; color : white, red, blue.
, 3, 4. 1.
.
, . ( ) , , .
, , , . , ( ) .
, , , . ORD(X), . ORD(X) . ORD(X) 0 false 1 true. ORD(X) 0 255.
PRED(X) SUCC(X). PRED(X) . SUCC(X) .
|
|
, , .
,
BYTE 1 0... 255
SHORTINT 1 128... 127
WORD 2 0... 65535
INTEGER 2 32768... 32767
LONGINT 4 2147483648... 2147483647
FALSE TRUE. :
ORD (FALSE) = 0;
ORD (TRUE) = 1;
FALSE < TRUE;
SUCC (FALSE) = TRUE;
PRED (TRUE) = FALSE.
. 0... 255. , ORD. ASII (American Standard Code for Information Interchange ). 7 , . . 128 0 127. 8 , , 0 255. 0... 127 ASCII. 128... 255 . ASCII [1-4].
CHAR , :
CHR(B) BYTE ;
UPCASE(CH) , CH CHAR; CH.
. .
for c:= a to z do write(c),
char, :
abcdefghijklmnopqrstuvwxyz.
97, 65. 0... 31 . 32... 64 .
, . ASCII #:
#97 = chr(97) = a ( a),
#0 = chr(0) = ( ),
#32 = chr(32) = ().
, 1 31 (), ^ ( 1... 26) ( 27... 31):
^A = #1 = chr(1) 1.
^B = #2 = chr(2) 2,
^[ = #27 = chr(27) 27,
^G ( 7), ^I ( 9), ^J ( 10), ^M ( 13).
, , , , , .
|
|
single, double extended .
4 10 :
s ; ( ); m .
m 23 ( single) 63 ( extended) , 7... 8 single 19... 20 extended . () , , , .
, , . , , ( ) .
const. , (=) . :
const m = 14.0.
m:= 1 , 14.0:= 1.
, . , . :
<>: <> = <>
<> ; <> ; <> .
:
year: integer = 1995;
year, integer, 1995.
, , . . , .
.
, .
:
const
year: word =1989;
x: real = 0.01;
min: integer = 0;
:
const
mass: array [min..max] of real; { }
a, b, c: byte = 0; { }
x: real = pi; { }
var namef: string [22] = prog.pas; { }
, . , . , , TYPE, :
type color = (White, Red, Blue, Yellow, Purple, Green, Orange, Black);
sex = (male, female);
workday = (mon, tues, wed, thur, fri, sat);
boolean, :
type boolean = (false, true);
. 2.
. 2
:
|
|
type workday = (mon, tues, wed, thur, fri, sat);
free = (sat, sun);
- , sat . .
, . FOR, CASE. , , , . . , . . . , , , . . , , :
type
colors = (blak, red, white);
ordenal = (one, two, three);
days = (monday, tuesday);
var
col: colors;
num: ordenal;
day: days;
: ORD(black) = 0, ORD(white) = 2, ORD(one) = 0.
:
col:= black; num:= succ(two); day:= pred(tuesday);
:
col:= one; day:= black;
, :
var
col: (black, white, green);
, , . read write. , . , - , . .
1. , , , , .
. days, , .
program zadacha1; { }
uses crt; {uses }
type { }
days = (mon, tue, wed, thu, fri, sat, sun);
var
day, today: days; { }
begin { }
clrscr; { }
today:=tue; { }
writeln( );
for day:= today to sun do { }
begin { - sun}
case day of { }
mon:writeln();
tue:writeln();
wed:writeln();
thu:writeln();
fri:writeln();
sat:writeln();
sun:writeln()
end;
end;
write( );
if ord(today) = 0 then day:=sun { }
else day:=pred(today);
case day of
mon:writeln();
tue:writeln();
wed:writeln();
thu:writeln();
fri:writeln();
sat:writeln();
sun:writeln()
end;
end.
uses . , . , . uses crt; , clrscr ( ), crt.
|
|
today:= tue , read write .
3.
. , , . , , , char .
, , -.
.
type (. 3).
. 3
, . . :
type
digit = 0.. 9;
dig2 = 48.. 57;
, ( ) . , , .
TYPE, :
var
date: 1.. 31;
month: 1.. 12;
date month . .. , .
, , .
type
days = (mo, tu,th, fr, sa, su);
weekend = sa.. su;
var
w: weekend;
........
w:= sa;
ord(w) 5, pred(w) .
. .
2. , 6 49.
program sportlotto;
{ 6 49}
type
num = 1.. 49;
var
i: 1..6; loto: num;
begin
randomize;
for i:=1 to 6 do
begin
loto:=random(49)+1;
writeln(Nr.,i:2,loto:6)
end
end.
num. num 1 49. loto num. i . , . Randomize .
, . , 7 (. 23).
, . , , . , , i integer, , , 1.. 6, . , . - , . . , , , , .
3. .
, .
|
|
program rabweek;
type
day = (mo,tu,we,th,fr,sa,su);
workday = mo..fr;
var
den: workday;
time: integer;
begin
time:= 0;
for den:= mo to fr do time:= time + 8;
write (time)
end.
day ( ). workday workday mo fr. () , mo, tu, we, th, fr. den workday. , mo fr , su, . time 8. , , 40 .
: , , . . , , , .
.
( ) . . , . , . , . , . , , . , .
b[1], b[2],..., b[40] b; [1], c[2],..., c[40] . b[12] b, c[39] . 40 , b[41], . , :
a [ i + 2 ], b [2 * (i + 1) + 1].
, , . , , .
, , . ,
var
a: array [1.. 40] of real;
b,c: array [1.. n] of real;
d: array [5.. 20] of integer;
p: real;
: a, b, c, d . array , . : 1) ( a, b, c , d ); 2) , , : 1.. 40, 1.. n, 5.. 20. . , . , .
df cf
df: array [1.. 10] of real;
cf: array [1.. 10] of real
, :
df,cf: array [1.. 10] of real.
, , .
df cf 10 . , , .
:
var K: array [n.. m] of integer.
? n m. , - . n m , . n m , .
. , .
program pri;
const n = 1; m = 10;
var
i: integer;
k: array [n.. m] of integer;
begin
for i:= n to m do read (k[i]);
for i:= n to m do write (k[i] * pi)
end.
, . . , pri , , . , , , , . , . , .
, , :
type
ar = array [n.. m] of integer.
k: ar.
:
< > = array [<. . >] of < >
< > ; array, of (, ); <. . > () , ; , , ; < > .
, longint.
<>, of, , , :
type
mat = array [0.. 5] of array [2.. 2] of real,
:
type
mat = array [0.. 5, 2.. 2] of real.
:
type
color = (red, green, blue);
truthtable = array [boolean] of boolean;
height = 0..200;
var
square: array [color] of height;
matrix: array [2..8] of array [2..8] of integer;
table: truthtable;
truthtable boolean. square color heigth. matrix 2.. 8 , , , 2.. 8 . table truthtable, boolean.
, .
, , , ( ) , 65520 .
.4.
. 4
packed, , , , ; : , .
mat [i][j] j i mat. mat [i,j]. mat , mat [i,j] , j c i . . n , n, n .
, :
:=
,
A [ i ]:= B [ i ]
( i, ), .
. , ,
if a = b then...
, :
for i:= 1 to 5 do
if a[i] <> b[i] then...
for... to... do. , for i:= 2 to 7 do index[i]:= 0; index 0.
, ; , :
type
colors = (white, red, black);
const
colst: array [colors] of string[5] = (white, red, blak);
vector: array [1..5] of byte = (0, 0, 0, 0, 0);
, , . :
const
matr: array [1..3, 1..5] of byte = ((0, 1, 2, 3, 4),
(5, 6, 7, 8, 9),
(10, 11, 12, 13, 14))