Открыть Электронные книги
Категории
Открыть Аудиокниги
Категории
Открыть Журналы
Категории
Открыть Документы
Категории
:
- . .,
- . ., .
- . iD.M .
- . ,,
- . .,
. . ,
- . ,
. . .
- . ,,
- . ,.
- . ,,
- . ,
,
,
,
: , ,
,
,
..
2002
681.3.06(075.8)
32.973-018
201
:
.. ( ); ,
(.
.. )
201
..
: . - 2- ., . . - .: - . .. , 2002. ~ 416 : .
(. .)
ISBN 5-7038-1957-1
- .
,
,
.
.
.
(1- 2001 ) -
(UML).
Delphi, .
,
. .. .
, ,
. .
681.3.06(075.8)
32.973-018
ISBN 5-7038-1957-1
.. , 2002
. .. , 2002
1.
8
10
12
1.
1.1.
1.2. ,
1.3.
1.4.
1.5.
1.6. .
12
12
13
14
20
23
24
2.
2.1.
2.2.
2.3. .
2.4.
2.5.
2.6. -
2.7. .
28
28
30
31
38
40
42
45
3.
3.1.
3.2. .
3.3.
3.4.
3.5. .
3.6.
50
50
52
56
58
63
69
4.
4.1.
4.2. .
77
77
87
4.3. . .
4.4. .
4.5.
.6. .
4.7.
4.8.
5.
5.1.
5.2. .
5.3.
5.4.
5.5.
5.6.
5.7.
5.8. . .
96
104
113
120
127
136
144
144
:.
150
156
159
162
166
168
179
6. .
6.1. MS DOS
6.2. Borland Pascal
6.3.
6.4.
6.5.
6.6. DOS . . . .
188
188
190
196
201
207
209
7.
7.1.
7.2.
7.3.
7.4.
7.5.
7.6. .
212
212
218
223
226
238
8. MS DOS
8.1.
8.2.
8.3.
8.4. .
8.5.
8.6. .
8.7. .
8.8.
8.9. .
254
254
260
262
264
267
279
285
293
300
247
2. -
303
9.
9.1.
9.2. -
9.3.
9.4. -
303
303
305
306
312
10.4. .
314
314
316
.
11.1.
11.2.
11.3.
11.4.
11.5. .
11.6. .
11.7. .
11.8. .
12.
12.1.
12.2.
12.3.
12.4.
319
321
327
327
330
332
334
336
344
348
354
360
360
365
367
373
1.
2. MS DOS
. scan-
4. Delphi Pascal Borland Pascal 7.0
5. Windows
Delphi
384
384
385
386
387
391
413
414
. -, -
. ,
20 , .
,
, . -,
, , :
-
- .
, - ,
. ,
, .
. ,
. , .
, . -
20- . ..
. ,. ,
.
,
, ,
.
( ),
,
.
,
. ,
, . ,
-
, ,
. .
.
,
,
.
.
,
Borland Pascal
.
,
. , ,
,
- .
, .
.
.
Delphi Pascal Borland Pascal 7.0. ,
, -
, UML (Unified
Modeling Language - )
- .
. . , ..
, ,
:
- . , . .
, - . ,
.. .
,
,
, .
1971 .
,
.
, ',
. ,
, -
.
.
Turbo (Borland) Pascal, Borland Internation ().
. ,
MS DOS - 7.0, :
,
;
;
;
- ;
.
. -
,
.
Delphi,
. ,
,
,
10
:
' .
{) (),
, .. .
,
.
, , ,
, . ,
.
Delphi
,
, .
Delphi
Delphi Pascal ,
.
4 5.
,
.
1.
1.
:
- ;
-
;
~ ,
,
(
, );
- QQC^dibntHWQ ,
.
- .
1.1.
,
.
,
. ,
, - , ,
. . ,
( , , . .).
, :
,
, , 12
(,
,
^+-ibP
(,
,
. 1.1. ,
,
.
,
-
,
(. 1.1).
19.201-78, .
1.2. ,
, , .. ,
,
(
).
1.1. ,
.
, .. ,
.
- - .
- - ,
.
. :
13
I.
S = X ,
S ~ ; , b - .
.
, ,
, (
), .
, , ,
. .
. ,
,
, ,
.
,
.
.
,
.
. ,
, .
,
,
.
1.3.
.
,
( ).
.
.
.
:
, .
.
14
/.
,
.
() ,
.
,
. ,
, .
,
. ,
, , ,
.
,
. , ,
,
.
:
,
~ ',
,
- ;
, :
-
- .
.
19.701-90,
. . 1.1.
,
. ,
, . ,
,
.
, ,
. 15
1.1
( J
(,
. .)
I
i
j
'
, ,
1 \
::;{
, 3
1.
,
:
-
(. 1.2, );
-
(. 1.2,6);
' - ,
, (. 1.2, ).
16
/. <
I
2
^-'--^
1
"
. 1.2. :
(), () - ()
,
:
-
(. 1.3, );
' ~
,
(. 1.3, );
{ ) -
(. 1.3, ).
. 1.3, , ,
.
- ,
[4, 8]. ,
,
^ ,
.
.
.
.
- ,
, .
.
.
.
. 1.2.
L2,
.
17
I.
1
2
3
"
>^ "^
1=1
i=nl,n2,h
.1.3. :
(-), - (-) (--)
.
. -
18
/.
< 1>
< 2>
....
<>
< 1>
<2>
-
' <>
<>
-
j
!
[^
' -
|
1
1.2
<>
<1>: < 1>
<2>: < 2>
-
<> =
<n>,<k>,<h>
<>
-
<>
_.?1>
.
, . :
)
225
225-125 = 100
125
125
100
25-100 = 25
100-25 = 75
75-25 = 50
50-25 = 25
25
25
25
13
13-4=9
9-4=5
5-4=1
1
1
1
4
4
4
4
4-1=3
3-1 = 2
2-1=1
. ,
,
, .
.
,
().
- . ,
, npoBcpiQ' ,
.. -. ,
()
.
, .. , .
, .
19
I.
. 1.4 ,
.
:=-
:=-
:
,
- ^
>
:= -
:= -
-
-
.
,
/
,
/
.
( J
(. 1.6).
. 1.4.
,
,
,
, .
.
. ,
,
, ,
, ,
.
1.4.
,
.
,
.
20
/.
<>.| J^
<>
. 1.5.
. 1.5
.
.
- ^
, .
( ). - ,
.
, .
.
. ,
,
. 11 Pascal
, .
, , .obj.
21
/.
(. 1.6, ).
, ,
.
, , ,
, ,
. ,
.
,
, ,
.
.
.
/ .
- .
3.2.
:
.
,
. ,
.
, .
,
.
1.5.
, ,
, , ,
.
:
,
;
, ,
;
( /
).
23
I.
,
.
-- .
,
. , ,
.
, .
,
..
,
, ,
(. 1.6, ).
, ,
,
. .
.
, .. ,
.
.
- , -
5i
^^^^
. 1.6. ()
()
22
I.
, ,
,
, .
1.6. .
- ,
.
,
.
.
^1 [4, 9].
.
, . ,
. , ,
. ,
, - ,
, .
1.3, , 8
(+1)-1
=-
>1, > 0.
>1 .
.
.
[xj, 2] , f(X]) < < f(x2). ^ = (]+2)/2
, , (^)
. ,
Xj 2 .
.
24
/.
L .
:
, , eps.
.
X, .
.
2. .
:
1 , f(xl) < .
2 , f(x2) > .
[1, 2].
.
3, 1. 1
, f(xl) < . ,
X > , , , , 1=1,
, ,
1, .
1:
1:=1
- f(xl) >
1:=1/2
-
.
4, 2. 2
1, .
2:
2:=1
- f(x2) <
2:=2*2
-
.
5, .
[1, 2].
:
- x2-xl>eps
[1, 2].
-
.
25
1.
6, .
, f(x]) ^ ^ f(x2)
:
xt:=(xl +2)/2
f(xt) >
2 := xt
1 :=xt
-
.
, ,
.
:
, , eps.
1:=1
- f(xl) >
1:=1/2
-
2:=1
- f(x2) <
2 := 2/2
-
- 2-1 > eps
xt:=(xl +2)/2
f(xt) >
2 := xt
1 := xt
-
-
xt, .
.
,
,
.
, ,
.
26
/.
1. , 10
, :
Fi = 2 = l , F n = Fn.i +Fn.2
> 2. .
2. ,
, ,
^:
1 = 12
I + 3 = 4 = 22
14-3 + 5 = 9 = 32
1 + 3 + 5 + 7 = 16 = 42 . .
.
2.
, , -,
.
, ,
.
2.1.
, ,
. , ,
, .
- ,
(, ) , .
- ,
, .
,
.
. - () .
,
:
::= - ,
I - .
,
, .
( ),
,
(< , >).
, <>,
, :
28
2.
<> ::= <3> < > | < >
< > ::= < > <> | <>
<> ::= I 1 I 2 I 3 I 4 I 5 I 6 I 7 I 8 I 9
<3> ::= + | , < >
,
.
.
.
, -
, -
. , ,
. ,
.
. 2.1 ,
<>. ,
.
.
, ,
,
.
Borland Pas<cal 7.0 :
, (a..z, A..Z)
( _ ), ;
, ,
: ^- . .;
(0...9);
, :
+ - * / = : << >> [ ]
{ } ( ) ^ @ $ #
<= >= := (* *);
(
):
"^
. 2.1.
<>
29
1.
absolute
end
for
inline
interface
interrupt
label
forward
fidnction
goto
mod
nil
not
if
and
external
array
begin
case
const
file
div
do
downto
else
type
unit
until
uses
while
with
of
set
shl
shr
implementation
or
in
private
string
then
to
procedure
program
public
record
repeat
var
xor
. ,
.
.
.
. 2.2.
<>.
<>
( , , . .). Borland Pascal
(
) , ,
: , 121, Parametral, _ . .
. 2.2.
.
.
, ,
,
.
2.2. 1^
Borland Pascal : ,
.
,
program - .
( , ..).
begin ...end . 30
2.
,
~ ;.
end, , .
,
.
, Borland Pascal ,
, 1.2:
Program example; { }
{ }
Var a,b:integer;
{ }
{ }
Begin
Write (' :'); {
}
Readln(a,b);
{ }
while a<>b do
{- ^}
if a>b then a:^a'b
{ a>b, a:=a-b}
else b:-b-a;
{ b:=b-a}
Writeln(*Hauou \a); {
End.
{ }
example.
(. 2.3).
,
.
Borland Pascal .
2.3. .
,
.
, Borland Pascal,
.
.
.
.
:
31
I.
, , 25, 6.12,
0.12510 (. );
- $,
, $64;
- true () false ();
- ,
'', ASCII (
. 2),
#, #65 (
);
~ , 'ABCD'
(. 4.5);
(. 4.7);
- nil (. 7.1).
. 1.
.
2. -
^
, , , , : 0.5, -3.85 .
, .. .
, : 1.5-10 1,5 10 ~*^,
0.523 0,5x102^.
:
.
,
(, 2+5.1*
2 5.1).
const. ().
(. 2.3) ,
^ Const /~
2.
, , (. 2.4)
abs, chr, hi, length, lo, ord, odd, pred, round, sizeof, str, succ,
trunc (CM. 1).
;
Const min='23; =45;
aI6=$J0;
chl=#94;ch2='a';
stroka= *end\vl-[3,6,8..9];
center=(max'min) div 2;
{ }
{ }
{ }
{ }
{ }
{}
. - ,
.
,
, (. 2.4).
.
, ,
.
. 2.5 Borland Pascal.
.
()
. .
^/ ,
, -
.
,
. :
- . . 2.1;
Boolean - false (0) true
(1), ;
Char ASCII
(. 2). 255 ,
Var
. 2.4.
< >
33
JT
*-
I-
|-
h
L
. 2.5.
. , ,
, , ,
. .
(. 2.6).
2.1
34
Integer
-32768..32767
2 ( )
Shortlnt
.128..127
1 ( )
Longlnt
.231..231 -1
4 ( )
Byte
0..255
1 ( )
Word
0..65535
2 ( )
2.
-G^y^^^^^^^'^-C^vr^^bQf
. 2.6. < >
,
. ,
, :
Var D:(Mon,The,Wed,Thu,Fri,Set,Sun); ...{ D
}
.
, . , *1 , The - 1
. .
,
, , :
Day=(Mon,The,Wed,Thu,FrhSet,Sun); { }
Var D.'Day;.., { }
.
, :
Data=L31; { }
Var DataN:Data;..,
, ,
:
VarDataN:L.31;...
,
.
,
.
, ,
.
,
. . 2.2
Borland Pascal.
35
L
2.2
Real
,,
11..2
-39...+38
Single
7...8
-45...+38
Double
15...16
-324...+308
Extended
19...20
-4951...4932
10
Comp
19...20
-263+1... 2^^-!
. , :
, Real,
( {$N+} );
Real .
.
. Borland Pascal
.
const (. 2.7).
,
const .
.
,
, :
. 2.7.
< >
36
2.
Const a:real=5, ;...
:=('])/;.,.
.
,
, .
var,
absolute. . 2.8
, ,
.
1. . absolute
word, .
{, (. 7.1).
.
:
Var : word absolute $0000:$OOFF;
L:array[L.2] of char absolute 128:0;...
, ,
.
2. .
absolute ..
, absolute,
, . ,
, , .
:
Var c:byte;
:real absolute ;...
. I | \J_y
^AbsoIuteVrH
. 2.8. <
>
37
1.
, absolute, ,
.
5.5.
2.4*
.
, . :
: + (), - (), * (
), / ( ), div ( ), mod (
) -
, - ;
: > (), < (), = (), ( ),
>= ( ), <= ( ) - ,
, , ;
: and (), or (), ( ), not
() - ,
- ;
: and (), or (), ( ), not
(), shr ( ), shl ( ) -
, - ;
: + ( ) -
, - (. 4.5);
: + (), - (), * (
), - ; in (
), ~ (. 4.7);
: @ (
), - (. 7.1).
. 2.3 ,
2.3 .
.
1
@, not
(.
2
*, /, div, mod,
1)
(. 5).
and, shr, shl
.
+, -, or, xor
3 ,
.
,
4
>, <, o, =, <=,
,
>=, in
,
38
2.
.
, . :
1) +/ ,
, ;
2) (a+b)/c*d , + ,
(!) d.
, .
1.
, : 6 div 4 =1,
6 mod 4 = 2. ,
, :
Var /, n:integer;...
mod 2;...
:
6/4=1.5.
2.
:
) , - ,
;
- ;
)
,
; . ,
double, extended real,
extended .
.
, , ,
. ~ , true,
, false - .
, -
, , ,
^ :
(-)>1'10
(')<1'10
{ }
( =}
, ,
(. . 2.2),
39
I.
( . 2.7).
.
boolean.
,
, . , ,
, [, ],
:
(> =) and (< =).
.
. - .
,
:
5 shl 4 - 5
4 , 2^ =
= 16. , - 80.
.
2.5.
, (. 2.9).
, ,
, .
,
.
:
) Var a,b,c:real;
Begin ...
c:=(a*a'Sin(b)J/(a+25J); ...
) Var v: boolean; a: integer; b:real;
Begin a:=8;b:--]J;
v: =(a>5)and(b> =8); {v false}...
. 2.9.
< >
40
2.
, ,
.
:
;
;
;
;
.
, . :
Var
L:longint; { longint}
,: extended; { extended}
Linteger; { integer}
R:real; { real}
Begin...
R:=I*E/(x-^L);... { ,
, extended,
, R real,
}
End,
, .
:
() -
, ;
Round(x) -
, ;
Ord(x) - ;
Cltr(x) - ASCII .
:
)
Varn,nl:integer;xn,xk,h:real;
Begin
xn:=I;xk:=5.7; h:=OJ;
n:'=Round((xk'Xn)/h);
nl:=Trunc((xk'Xn)/h);
{n 16}
1.
) Var c:char; x,y:integer:
Begin x:=3;
y:= Ord(*A*);{y 65 -
ASCII}
. = Chr(Ord('A*)-^x); ... { 'D'}
,
,
.
, :
Var h'.char;
... h:=Char(65); ... {h ''}
,
, ,
.
. (
)
. (
) .
:
Month=(Jan,FabMcir,ApKMayJun,JulAug,Sep, Oct,Nov,Dec);
Var M:Month;
A,B:mteger;
C'char;
L:longint;
Begin
A:=10;
C-'E';
B:==Integer(C); { 69 - E - 2 }
: =Month(A'2); { Sep}
L:=Longint(M);.... { 8}
2.6. -
.
Read ReadLn (. 2.10).
, boolean, (string).
( )
.
,
.
42
2.
rU
Read V i
L^/ReadLnVI
. 2.10.
< >
, .
, , , .
Enter.
Enter,
#13, #10.
ReadLn,
, ,
, . Read,
, ,
. cyecteo ,
char ( string, . 4.5),
.
:
)
Var a,b,c:real;
Begin
Read(a,b);
:integer;
{
}
ReadLn(c,n);,,. { ,
}
#13 #10
. 2.11.
h0^
0-
U/writeLn\j
<1
2.
WriteLn
.
2.1.
2-1-+=0 , - .
:
-bVd
,2 =
'
2
d = ^ - 4.
:
:
, ,
d := b^ - 4
:= / (2)
X, := - + V d / (2)
2 := - - V^d / (2)
|, 2
.
.
Program ex;
Var a,bx,xl,x2,e,d:real; { }
Begin
WriteLnC : ');
ReadLn(a,b,c);
{ }
d:=b*b'4*a*c; { }
:=/(2*);
{ }
xl:=-e^sqrt(d)/(2'^a):
{ xj}
x2:^'e'Sqrt(d)/(2^a);
{ 2}
WriteLn('xl= \1:6:2, *2= \2::2); { }
End
2.7. .
,
.
- , -
,
= | - |.
45
1.
.
, .. ,
> = | - | .
. :
1001 11. ,
, .
.
(;^0):
5 = /.
, ,
5, = , / ( - , ) .
:
(
);
( );
,
, ( );
,
( );
( ).
. ,
. ,
.
, -
.
2.2. 1/3
real.
46
2.
Program ex;
Var ,12,,4,5,6,:1;
Begin
y-l;
yl-y/3;
WriteLnCyl = ',yl:16:14); { yl=0.33333333333348}
y2:=sqrt(yl};
y3:=sqr(y2);
4:=/14;
5:=4*]4;
WriteLnCy6^ \6:16:14):
WriteLn(y = \y:16:14);
End
{ 6=1.00000000000182}
{ =1.06000000000000}
1/3 real:
,/3 = |1/3 - 1| = I 0.33333333333333 - 0.333333333333481 = 0.15-10-'2,
5,/ = 0.15 10-12/(1/3) = 0.45-10-10
,
real, :
= 1 - 1 = 11 - 1.00000000000182| = 0.182.1 -1',
5 = ' = 0.182.10-11/1= 0.182.10-11.
2.3. , ch^ - sh^ = 1.
, .
, = ( +-)/2,
2 = (>^--^)/2,
= 1^-2^ ], 2 .
Program ex;
Var X, , yly y2:real;
Begin
Write (' x: *);
ReadLn(x);
yl: ='(exp(x)-^exp('X))/2;
47
1.
2:=(() - ('))/2;
y:=^sqr(yl) - sqr(y2):
WriteLnCyl^\yl:13:ll):
WnteLn(y2=\y2:13:ll);
WriteLn(y=^\y:13:ll);
End.
x = 5, 6, 7, ..., 14, , = 1,
. =15 =0 (!!!). ,
, = , 5, 10, 14, 15,
20 . 2.4
. , ch sh
X . , .
, , =15
. , ch
sh X, ,
.
,
, ,
(. . 2.2)
:
ch^ X - sh^ X = (ch X - sh x)(ch x + sh x ) ,
.
2.4
1,2
1=1.00000000000
2=0.00000000000
1=74.2099485248
2=74.2032105778
10
1=11013.2329201
2=11013.2328747
1=601302.142083
2=601302.142082
14
15
20
48
1=1634508.68623
2= 1634508.68623
1=242582597.704
2=242582597.704
, 5
1.00000000000
=0,
6=0%
0.99999999989
=0.00000000011
5=0.000000011%
1.00008608813
=0.00008608813
6=0. 008608813 %
=0.14689281583
6=14.689281583%
=1
6=100 %
=1
6=100 %
1.14689281583
0.00000000000
0.00000000000
2
3.5.
1. 2.3 double.
.
2. ,
sin^ X + cos2x= 1.
,
. ?
3.
, -
, .
, .
,
. Borland Pascal,
, ,
,
.
3.1.
(. 3.1)
, . . ,
, . ,
:
true, , then,
- , else.
(
jf) .
Borland Pascal
, begin...end.
;. end
. else
, .
if
then
else
i.
. 3.2.
() else.
, , ,
(. 3.2) :
[/'<1> then
if < 2> then
< ]>
else < 2>;
:
else if,
. 3.2, .
, . 3.2, , :
//'<1> then
begin
if < 2> then
< 1>
end
else < 2>;
3.1. ,
, :
|| < 1;
1 < || < 2;
4
.
1I ^'
.
, , 51
1.
. 3.3.
, ,
.
. 3.3.
:
Program ex;
Var x,y:real;
Begin
WriteLnC .');
ReadLn(x);
ifabs(x)<=l then y:=abs(x)
{ }
else
ifabs(x)<=2 then
y:=sqr(x)
{ }
else y:-4;
{ }
WriteLnCTIpu x= \ x:8:5, * y=^ \ y:8:5);
End.
3.2, .
1.4,
,
.
52
3,
,
.
,
, ,
, ,
. .
,
. :
( );
.
,
. :
.
, ,
,
.
,
.
3,2. ,
. .
. ,
, .
, ,
,
.
, ,
.
. 3.4 ,
:
Program ex;
Var ,'1;
Begin
Write : *);
ReadLn(A,B,C);
if (A<=0)or(B<^0)or(C<^0) then
WriteLn(' .')
else
if(A+B<=C) or (A+C<^B) or (B+C<^A) then
WriteLn( . *)
53
1.
^ < ^
"
" i
P:=(A+B-fC)/2
I
S:=\/P(P.A){P.B)(PnC)
I
/
{
. 3.4.
else
begin
tf(A^B)and(B=C)then
WriteLn( ,')
else
if(A^B)or(A=C)or(B^C)then
WriteLn( , *)
else WriteLn( , *);
P-(A+B+C)/2;
S:=sqrt(P*(P'A) ""(P-B) ""(P-C));
54
J.
, 8=0.43
, S=1.98
, S~5.56
2.5
2.5
, 8=3.00
1 3.1
2.6
, 8=4.03
'
>0
-1.5
>0
>0
>0
^ .
3.1
End
. 3.1
1. , ,
, (, )
(. 3.5). .
2. , , < .
, ,
:
(
. 3.5.
1
^ X < ;
X ^ ^ ;
I X ^.
55
L
3. f(x) [-1, 1]
x^+l. , f(x)
XQ. .
3.3.
,
.
. 3.6.
3.3. ,
.
,
():
:
1 - y=sin(x)
2 - y=cos(x)
3 - =()
. . 3.7 .
, .
Program ex;
Var x,y:real; Kod:byte; Key:boolean;
Begin
WriteLn(' :');
WriteLn(4 - sin(x)');
WriteLnC2 - cos(x) ');
WriteLn(*3 - exp(x) *);
ReadLn(Kod);
>( case y-A h*/ of JTA/
-
else
'
end
3.
(
Kod=l
Kod
Kod=2 " ^ ^ v - ^ Kod=3
y:=sin(x)
y:=cos(x)
y=Q>
Key:=false
Key
>
J
1
^
(
. 3.7.
Write('Beedume :');
ReadLn(x);
Key:=true; { }
case Kod of
1:
y:-sin(x);
2: y:=cos(x);
3: y:=exp(x);
else Key:=false; { }
end;
if Key then
WriteLn(^npu x= \x:12:6, y= \y:12:6)
else
WriteLnCBeeden ,');
End
57
1.
3.4.
.
1.3,
:
- (. 3.8, )\
- (. 3.8, );
(. 3.8, ).
Borland Pascal . -
-
. -
.
- -
(. 3.6).
-. -
. 3.9. .
, .
. ,
.
,
.
-. ,
, ..
- * - <K=nl.n2,h>
1
(
while V-*^
do
. 3.9. <->
58
3'.
repeat
\*\
until
V-*J
. . <->
. -
. 3.10. ,
;.
. , ()
.
. 3.11.
. 1
, 2 - .
, . to,
.
downto,
.
, .
. - ,
Borland Pascal, ,
( +1 -1).
3.4.
.
.
, .
,
1 .
*^
|.(;:>1"7-'^"""'
L^^downtoV
. 3.11.
< >
59
1.
(
. . 3.12
. .
S:=0
:
i:=l,n,l
S:=S+i
"
Program ex;
Var
/, , S: integer;
Begin
WritelnCBeedume n');
ReadLn(n);
S:=0;
for /;=/ to n do
S:=SH;
WriteLn(' \ n / \ S);
End,
3.5. ,
1 - 1/ + 1/2 - 1/^ + ...
S ().
. 3.12.
, ,
, .
, ^ -
. , ,
I
Tj^+i ~ - n+1- .
, ,
|s-sj^kn+iU
S - , S^ ~ .
,
,
:
1 <
. 3.13 .
, , 60
3.
, , -,
.
,
.
,
-.
S=S+R
:
, ~ .
S=0 S=S+R,
,
S=l, R=l.
.
-
. 3.14, .
:
Program ex;
. 3.13.
Var S,R,X,eps:real;
Begin
WriteLnC x : *);
ReadLn(X,eps);
ifabs(x)>l then { x > 1, }
begin
S:=l;
R:=I;
while abs(R)>eps do
begin
R:='R/X;
S:=S+R;
end;
61
I.
. 3.14. :
-
-; - -
i.
else Writeln(THd ');
End,
3.4.
3.5. .
,
, , ..
,
.
,
,
.
3.6.
f(x) [, ] .
,
, ,
. ,
,
- [,], -
(, , . 3.15).
5 = (b-a) / n.
SI,
,
,
S1 .
,
,
,
, .
b X
=6
. 3.15.
63
/
a,b,eps /
S1:=0
Sl:=10''
r^i:=l,n,lVn
n:=5
S2:=S1
n:=2n
1
d:=(b-a)/n
x:=a
^
. 3.16.
- , ,
, , S1,
S1 S2. ,
S1 S2 s.
S2 ,
.
f(x) = ^ - 1 . 3.16.
, .
Program ex;
Var , b,Sl,S2,d, eps,x:real:n, i.'longint;
Begin
WriteLnC a, b :');
ReadLnfa, b, eps);
S1:=1E+10;
n:=5;
64
3.
repeat
S2-S1;
:=*2;
d:^(b'a)/n;
:=;
S1-0;
for i:=l to do
begin
S]:=SI+x*X'l;
x:=x+d;
end;
SJ:=SJ*d;
until abs(Sl-S2)<eps:
WriteLnCI=\Sl:10:6);
End
eps
[0,2] I (. 3.2).
2/3.
.
eps, .
.
3.7. ,
f(x) [, ] .
,
, .. ,
.
, , , .
.
.
.
,
3.2
eps
Al
5i,%
640
0.660420
0.006
0.9
0.001
5120
0.665885
0.0002
0.06
0.0001
40960
0.666569
0.00004
0.012
0.01
65
1.
,
,
.
. 3.17
.
. 3.18
f(x) = ^ - 1.
, ,
,
-, .
-
. 3.17.
j
/
/
a,b,eps
fa:=a*a-l
fb:=b*b-l
-^^2-<fa*fb>0
' "
. 3.18.
66
. 3.19. ^ :
~ 45**; - 45**
. ,
, (. 3.19), , ,
.
,
,
eps (
3.6).
, 45.
,
, .
1.
arctg X = X - ^/ + 5/5 - ^/7 + ...
10*^, 10"^.
.
2. ,
.
F, = l,
Fn = F.-1 + F,-2
> 2.
3. [0,4].
=^^. 10'^, ""*.
.
4. , ,
.
__,
,,
5. :
68
3,
, 3.3. :
, , ,
-. -
, . ,
, :
Program ex;
Var a,bjjajb,eps,x:real;
Begin
WriteLnCBeedume a, b : *);
ReadLn(a, b, eps);
fa:^a*a-l;
Jb:^b''b'l;
iffa*fb>-0 then WriteLn(* . *)
else
begin
x:=(b'a) *abs(fa)/abs(fa'fb)+a;
while abs(f)>-eps do
begin
{ }
iffaj<0 then
begin b:=x; Jb:=f; end
else begin a:=x; fa:=f; end;
:-() *abs(fa)/abs(fa'fb)'^a;
f:-x*x-l;
end;
WriteLnCnpu x= \ x:9:6, ' y= \ f:10:8);
end;
End
,
(. 3.3). =1,
.
,
3.3
eps = Ay
5, %
0.01
0.997260
-0.00547195
0.003
0.3
0.001
0.999695
-0.00060948
0.00031
0.03
0.0001
0.999966
-0.00006774
0.000034
0.003
67
3,
3.6.
,
.
,
, ,
.
.
goto .
.
, (. 3.20).
label (. 3.21).
, .
:
Break - ;
Continue - ,
;
Halt (<, >) - ,
. ,
, .
, , ,
- .
,
;
Exit- (. 5).
,
Halt.
-*/^ label - j
-*/
goto V-H
. 3.20.
<
>
. 3.21.
< >
69
1.
.
1.3,
,
. ,
, ,
: , , -
.
3.8. ,
sin
, h [, ].
.
( J
,
/
7
,
/
a,b,h /
.
n:=(b-a)/h+l
:=
,
^1:=1,\ .
,
y:=sin(x)
.
<0
. 3.22.
/
x:=x+h
/
IZZJ
break
goto,
goto
/
1
, break -
,
( )
( .
3.22).
break
. 3.22.
( ) ( )
70
3.
X,
/
/
/"
1
/
'
. 3.23. :
- break; -
, , ,
, (. 3.23, )
:
- ,
. ,
,
, (. 3.23, ).
.
g o t o :
Program ex;
Var /, n: integer; x,y, a, b, h:real;
Label konec;
{ }
Begin
Write (* a,b,h:');
Readln(a,b,h);
n:=round((b'a)/h-^I.5); { }
x:=a;
for i:=l to n do
begin
y:=sin(x);
71
1.
ify<0 then
begin
WnteLn(y== \y:8:6,' := \x:6:3);
goto ; {
, }
end;
x:=x+h;
end;
WriteLnC ,');
:
{, }
End
break:
Program ex;
var in:integer; x,y,a,b,h:real;
Begin
Write (* a,b,h:');
Readln(a,b,h);
n:=round((b-a)/h-^J.5); { }
x:=a;
for i:=l to n do
begin
y:=sin(x);
ify<0 then
begin
WriteLn(y= ',y:8:6,' x= \x:6:3);
break; { }
end;
end;
{, break}
ify>-0 then WriteLn(' ,');
End.
:
Program ex;
var ,, , 6, h:real;
Begin
Write a,b,h: *);
Readln(a,b,h);
x:=a'h;
repeat
72
J.
x:=x+h;
y:=-sm(x);
until (x+h>b) or (y<0); { }
ify<0 then WnteLn(y= \ :8:, ' :=', :6:3)
else WriteLn(* . *);
End
,
, , .
goto
break
. ,
,
.
,
continue.
3.9.
,
10 ,
50.
,
.
,
,
,
-.
. 3.24.
goto, continue
if.
- . 3.24.
.
10 , 50
73
I,
.
goto:
Program ex;
Var i,s,a:integer;
Label cycl;
Begin
i:=J;
s:=0;
while i<=10 do
begin
Read(a);
ifa>50 then
begin
WriteLn(' 50 *);
goto cycl; { }
end;
s:=s-^a; {, }
cycl: end;
WriteLn(s);
End
continue:
Program ex;
Uses crt;
Var i,s,a:integer;
Begin
i:^l;
S:=0;
while i<=10 do
begin
Read(a);
ifa>50 then
begin
WriteLn(' 50*);
continue; { }
end;
s:^s^a;
i:=i-^l;
end;
WriteLn(s);
End
74
3,
Program ex;
Uses crt;
Var hs,a: integer;
Begin
i:-l;
S:^0;
while i<=10 do
begin
Read(a);
ifa>50 then
WriteLn(' 50*)
else
begin
s:=s-\ra;
i:=^i+I;
end
end;
WriteLn(s);
End
. . goto continue
. ( continue
.
,
goto,
.
. ,
.
,
. ,
, - .
, - .
. -
(. 3.25),
goto. ,
:
,
.
75
L
(
-.
/ /
sin(x)
/
/
/
/
^"
/__t/
Program ex;
Var x:real;ch:char;
Begin
repeat
Write(' x: ');
ReadLn(x); { Read,
(. 2.6)}
WriteLn(* \ sin(x):8:4);
WriteLn(*poo^cum? (/)
*);
ReadLn(ch);
until ch= * V
End.
.
1.
goto Borland Pascal
.
. 3.25.
, goto,
, goto,
,
[3, 4, 9].
2. break continue
,
, . ,
- .
.
Halt Exit
,
.
1. ,
, ^ =
= X - sin X [,] h.
2, ,
= (in ) / tg X [, ] h.
,
.
76
4.
: , , ..
. Borland Pascal
:
- ;
- () ;
- ;
- .
4.1.
- .
^
.
.
. 4.1.
.
(boolean, char, integer,
, ), longint
.
: ,
, - .
, - , .
<^>0&
77
I.
"
-8 1
12 54
" N
-5
-4
-3
-5
"ii'l
[]
46 83
54 0 "93]
255
4,
, .
. :
Const : arrayfl..5Jo/real = (0,-3,6,7.8,3.789,5.0);
b: arrayfboolean, L.5,]ofreal = ((0,-3.6,7.8,3.789,5.0),
(6.1,0,-4.56,8.9,3.0));
{ :
false,! " ' bfaise,2= "3.6, bfaise,3 = 7.8, ..., b ^^ue,! = 6.1, ..}
c:array[1..3,0..1,-2..1]ofbyte = (((3,6,9,6),(0,4,3,9)),
((5,7,3,1),(45,8,0,2)),
((5,9,2,3),(1,5,8,4)));...
.
~ .
.
.
,
, :
Var , : array[boolean] of real;
... a:-b;...
, , :
mas =[boolean] of real;
Const a:mas=(3.6, -5.1);
Var b: mas;
... b-a;...
. , ,
.
, :
Vara:array[char,boolean]ofreal; { }
... a[^A\true]:=5.1;... { ^^}
,
[3], , , ,
, a[i] (. 4.3).
. ,
,
79
I.
1
1 3.5 -5.1
3
0
4
8.4
5
-0.3
4.9
1
3.5
-5.1
3
0
4
5
8.4 |-0.3
1 ^^
[3]
a[i] -
. 4.3. () ()
.
, :
Var a:array[L.6] of integer;...
for /V=7 to do a[i]:=i;... { i=l a| 1,
i=2 a2 2
i=3 ' ..}
,
, . ,
, : -
, - .
, ,
, , , . ,
, - , :
mas=array[boolean] of real; { }
Const a:array[L.2]ofmas^((3.6,-5,l),(7.0,-4.2)); {
}
Var b:mas;
Begin b:=a[IJ;... { b }
- . - ,
, :
Var a:array[L.5] of real;
Begin
for i:-l to 5 do Read(afiJ); { }
ReadLn;
{ ,
(. 2.6)}
, , : |, 2, , 4, -
Enter
.
80
4.
:
^) 2_-6_8_56_34 J - J Enter;
6)2 J
-6 J
8 J
56 J
34 J
-
.
:
Var a:arrayfl..5, LJ] of real; { a 5 7 }
Begin
for /;=7 to 5 do
{ : aj, 2, , 4, )
begin
forj:-l to 7 do
{ i- :}
Read(a[iyj]);
{aj j , aj 2, a,-3, aj 4, aj 5, a^ 5, aj 7}
ReadLn; { }
end;...
4.L
(5) .
.
.
.
, . .
imax .
, , .
,
imax (. 4.4).
, 2 5,
. ,
. ,
.
. 4.5 .
- ,
, ,
. /,
81
1.
|3.5|
imax
1
2
1 3.5 -5.1
3
0
4
8.4
5
-0.3
amax
8.4
max
L "J*
a
UU
1
2
3.5 -5.1
3
0
4
8.4
5
-0.3
LiJ
. 4.4, :
- ; -
,
. .
. 4.5.
82
Program ex;
Var a:array[l.,5] of real;
amax:real;
/, imax:byte;
Begin
{ }
WriteLn(* 5 : *);
{ }
for /.-=7 to 5 do Read(a[i]);
ReadLn;
{ }
amax:=aflj;
imax:-J;
for i:=2 to 5 do
ifa[i]>amax then
begin
amax:=a[ij;
imax.'^i;
end;
{ }
WriteLnC : *);
for /.=; to 5 do Write(a[i]:5:2);
WriteLn;
{ }
WriteLnC \
:5:2, \ \ imax);
End
4.
1
2
3
4
19.8
25.7 1
12.0
16.9
. 4.6. () () 4.2
4.2.
(4,5). .
, , 4 5 (. 4.6, ).
,
(. 4.6, ).
,
, . 4.6.
J
. -
. i
/
7
1 4. i-
/
(4,5) /
.
,
=1,4,1
j
1
j
i- ,
.
\
B[i]:=0
. . 4.7
r*^j:=I,5,l\-,
(
i- ).
1 B[i]:=B[i]+ 1 j
.
11
-^t'ji
1 h
Program ex;
1
1
;
Var : array[L .4J5J of real;
/
B:array[1..4] of real;
/
ij:byte;
Begin
{ j
WriteLn(* Mampuify : *);
for i:=J to 4 do
{ }
begin
. 4.7.
forj:^l to 5 do Read(A[iJ]);
ReadLn;
end;
_m_J
83
L
WriteLn(*:');
for i:=^l to 4 do
{ }
begin
B[i]:=0;
{ }
forj:-l to 5 do BfiJs^BfiJ-^AfiJJ; { }
forj:=I to 5 do Write(A[ij]:7:2);
( }
WriteLnC \B[i]:7:2); { }
end;
End
. ,
.
, .
Borland Pascal
.
1. ,
:
Const d:array[l,JO] of char ^0\
'8\ V*);
, ,
:
Const d:array[L.10] of char =
VI23456789';...
2. ,
,
:
Var S: array[LJl] of char;...
S:- '*;
3.
, :
Var S: array[1 10] of char;...
for i:=l to 10 do Read(S[i]); { ABODE FILN J }
4. ,
, - , Write
WriteLn:
WriteLn(S); { }
5.
() , +.
, 84
4.
, , :
WriteLn(stl + ' * + st2): { }
, .
.
4.3. 40 , ;
, .
. ,
.
:
:
ABC DE
: ABC_DE__FGH.""
FGH
:
. ,
, .
.
, , , ,
( . 4.8). ,
,
, . ,
,
.
, ,
, . ,
, . ,
, .
"
"
true
false
F G
XZZZL
F G
. 4.8.
85
1.
Program Stroka;
Var ij\n:byte; key: boolean;
s:array [L.41] of char; { - }
Begin
WriteLnC 40 :
*);
i:-l;
{ , 40 }
Read(s[i]);
while (i<40) and (s[i]o\') do
begin
i:-i+l;
Read(sfiJ);
end;
ReadLn;
ifsfij= \ ' then n:=i'l else n:=i; {
}
Writef'BeedeHHaM : *); WriteLn(s);
j:=0; { }
key:=false; { " "}
for i:=J to do
ifs[i]^* * then { }
begin
if key then { }
begin
key:=false; { }
j:=j+J:
{ }
s[j]:^s[i];
end;
end
else {}
begin
key:=true; { " "}
s/jj:=sfi];
end;
if key thenj:=j+l;
{ }
{ ,
}
S[/]:'= \ V { }
WriteLn('npeo6pa3oeaHHaM ');
for i:=J toj do Write(s[i]); WriteLn;
End.
86
4.
4.2. .
,
, :
;
;
;
.
, ,
, .
.
}.
.
.
,
.
,
.
, ,
, ,
, , 2*i+l.
.
,
, : ,
, , ,
, ,
,
, , .. ,
, .
4,4.
(),
< 40, .
, .
, ,
. ,
,
.
, Borland Pascal
^ . . ,
.
87
1,
s:=s+A[i]
kol:=kol+l
I
. 4.9.
, 3
,
(. 7).
S 1,
,
.
,
,
S, 1
.
. (
,
,
.)
,
.
. 4.9.
.
Program ex;
Var a:array[L JO] of integer; s, kol /, n:integer;
Begin
WriteLn(* <=40*);
Readlnfn); { }
WriteLn(* \ , * :
*);
for i:=l to do Read(a[i]);
ReadLn; { }
WriteLnf* *);
for i:'=J to n do { 10 }
if mod 10) =0 then WriteLn(a[i]:5)
else Write(a[i]:5);
WriteLn;
kol:-0;
{ , 3}
s:-0\
{ }
88
4,
for i:=l to do
if(a[i] mod 3)=0 then { 3}
begin
kol:=kol+l\ { 1}
s:-s-a[i]; { }
end;
ifkol='0 then { , }
}, , *)
else WriteLnC ^ 1:3,
^ , 3-*,(s/kol):7:2);
End
4.5. (), <10,
,
, .
, .
,
2, 4, 6 ..
: div 2, ,
: 2*i.
kol, 0.
, kol .
kol
.
Program ex;
Var a:array[L. 10] of integer; kol Lj, n: integer;
Begin
WriteLnCBeedume <=10*);
ReadLn(n); { }
WriteLnCBeedume \, * *);
for i:=l to do ReadfafiJ); { }
WriteLnC ');
for i:=l to n do Write(a[i]:3); WriteLn; { }
kol:-0; { }
for i:-l to div 2 do
ifa[2*i]<0 then
{ , }
kol:=kol+l; { 1}
ifkol-=0 then
WriteLnC *)
else
WriteLnCKouecmo 1-\ 1:3);
End
89
L
.
,
. ,
.
,
,
.
.
.
4.6. (), < 10, .
, .
. ,
, ,
. ,
.
:
.
:
- , ,
- . . (. 4.10).
, ,
. , ,
,
, . ,
i
. 1
I 2\|
0.5
-2.1
9.8
I 2\1
=4
=5
. 4.10. :
- ; -
, i
90
4,
3 . 5 ^ ^ 0.5]-2.1 9
. 4.11. :
- , ,
; - :
- ,
, ,
. ,
(. 4.11).
. ,
, .
,
, ,
.
. 4.12.
.
Program ex;
Var a:array[l.,10] of integer;
/, k n:integer;
Begin
WriteLnf' <= 10');
ReadLn(n);
WriteLn(* \n,' *);
for i:^l to n do Read(a[i]);
ReadLn; { }
WriteLnCBeedume :
*);
ReadLn(B); { }
WriteLnC ');
for i:-l to n do Write(a[i]:5);
FTrteZw; { ^}
k:-0; { }
91
I.
/
(), /
{
/"
/
" /
N.
(!
. 4.12. :
- ; -
for /:=i to do
begin
ifA[i]>^B then
begin
A[k]:^A[i];
end
end;
ifk^O then WriteLnCBce . . ^)
else
92
4.
begin
WriteLnC % , * :^);
for i:-l to do Write(a[i]:5);
WriteLn;
end;
End,
.
(., , 4.3).
.
,
, , ,
. . ,
, .
,
, . ,
,
(. 4.2), , .
4.7.
(), < 40, ,
.
, .
.
i,
,
.
, .
Program ex;
Var a,b:array[L,40] of integer;
/, k n:integer;
Begin
WriteLn(* <=40*);
ReadLnfn);
WriteLn(* \, * *);
for i:=] to do Read(a[i]);
ReadLn;
WriteLn(* : ');
fori:=ltondo
Write(a[i]:3);
WriteLn;
93
1.
;=0;{ }
for i:-l to do
ifa[i]>0 then { > 0}
begin
k:=k+l; { }
b[k]:-a[i]; { }
end;
ifk=-0 then
WriteLnCB A . *)
else
begin
WriteLnC ');
for i:^l to do Write(b[i]:3); WriteLn;
end;
End,
.
,
,
, ,
.
, .
, .
,
.
.
.
, .
.
, ,
, ,
(. 4.19).
-,
(. 3.6): - ,
- .
, .
4.8. ,
.
, ..
,
. 3.6 ,
.
94
4.
,
, goto
break, .
,
- :
. ,
, ,
.
Program ex;Var : array[L, 100] of integer;
iJ,n: integer;
Begin
WriteLn(*Beedume n <= J00');
ReadLn(n);
WriteLn(* \n, * *);
for i:=I to n do Read(a[i]);
ReadLn;
WriteLnC ');
for i:=I to n do Write(a[i]:5); WriteLn;
i:-l; { }
while (afij>=0) and (i<n) do i:=i+l; {
- }
ifi<-n then
WriteLnCnepebiu ^,afij:5,
* %'4)
else WriteLnCTuKux , ;
End
1. (), < 50.
, ,
,
.
, .
2. (), < 40,
, . ,
,
. ,
, ,
.
3. , (), < 30,
-20 130, 95
I.
.
.
Flag True,
, False, . ,
.
4. (), < 20, .
,
,
. ,
.
5. D(n), < 10, .
,
. ,
. .
4.3. . .
-
. -
. ,
.
,
, .
, . ,
, - ,
.
t(n).
( -).
. t(n)
g(n), ,
t(n)
lim
= const 0.
n->oo g(n)
t(n) = 0[g(n)].
96
4.
, f(rt) = 20"* - ^ + 5 - 6,
"*, f(n) = (^),
lim
->
24 - + 5 - 6
=2.
j|4
,
,
. ,
O(const) ,
, 0() -
, 0(v?-) -
. .
,
,
.
,
(, . .), -
, ^
() , ,
, .
. ,
.
,
,
, .
.
:
;
;
( ).
.
4.9,
(), < 20, , .
.
.
.
.
.
. -1 97
1,
7.8 -6.3
5.8
,^
2-
!^
1.2
8.4
4.5
8.4
4.5
5.8
1.2
imin
amin
imin
5.8
7.8
8.4
IF] []
amin
4.5
n-3
4-
amm
1
n-2
3-
[ID
amin
mwm^f^
wtm^xi^f^
imin
on
amin
5-
imin
7.8
imin
[] H
^^^
. 4.13.
, , -2 , ..
, , (.
4.13).
. 4.14.
, .
Program sortl;
Var a:array[L.20] of real;
y, /, w, imin:mteger;
mm:real;
Begin
WritelnCBeedume n<=20: *);
Readln(n);
Writeln(' : *);
for i:=^l to n do Read(a[i]);
Readln;
forj:-l to n-l do { }
begin
mn:^4i[j]; { }
imin:^j; { }
for i:-jH to do { }
ifa[i]<min then {
}
98
4.
begin
min:a[i]; {
}
imin:-i
{
}
end;
{
}
a[imin]:=a[j];
a[iJ:=ntin;
end;
for i:=] to n do Write(a[i]:6:2);
Writeln;
End.
,
.
:
-1, -2, ..., 1 , ..
(-1)/2 .
,
0(2).
.
.
. 4.14.
.
,
:
( - )
, .
,
. ,
; :.
aj :, aj^.], :
] . ,
.
aj (. 4.15).
,
. , ,
. ,
99
1.
( J
1 7.8 -6.3 5.8
1.2
8.4
4.5 1
"> ^">
7
/
i:=2,n,l
1-
2-
1.2
.
-6.3
1.2
31
^\/
5.8
-6.3
5.8
7.8
4.5
B:=A[i]
[0]:=
MJ
jH-l
4.5
7.8
MJ
A[i]>B
.
AD+1]:=AD]
j:=j.l
n-l
-
5.8
%%
-2
0+1]:=
4-
-6.3
1.2
4.5
$\1\\
-3
/
[-6.3
1.2
4.5
5.8
7.8
8.4 1
. 4.15.
()
/
j
. 4.16.
.
, 0.
.
. 4.16.
, .
Program sort2;
Var a:arrayfO.,20J of real; .real;
ij\n:mteger;
Begin
WriteLn(* n<=20,');
100
4,
ReadLn(n);
WriteLnC .');
for /V=7 to do Read(a[i]);
ReadLn;
for i:-2 to n do { }
begin
B:-a[i]; { i- }
afOJ:=^B; { [0] - }
j:=i'l;
{ i j}
while B<a[/J do {
i-ro }
begin
^//"^^/'"^/// { }
;=-7;
{ j 1}
end;
[/+1]:=;
{ , }
end;
WriteLnC :');
for i:=l to do Write(a[i]:6:2);
WriteLn;
End
,
.
i-ro 1
i-1 , .. i/2 . i
2 , .. -1 ,
1 /2 . ,
(-1)(/2 + 1)/2 = (^ + - 2)1
.
^^), ,
. . ,
.
, , ,
,
-1. , 0^(n).
,
,
: 1, 2, 3, ..., -1 , , (-1)/2
, . .
, .
, , Oj^(n2).
,
, .
101
1.
.
, .
, .
, , ,
: ,
(. 4.17).
. 4.18. , .
1-
-6.3
5.8
1.2
2-
-6.3
1.2
3-
^-^
-2
4-
-
-6.3 1.2 4.5 5.8 7.8 8.4
. 4.17.
102
4.18.
4.
Program ex;
Var : array[L.20] of Real;
ij,nj,k: integer;
b:real;
Begin
WriteLn(* N< =20');
ReadLn(n);
for i := 1 ton do Read(a[i]);
ReadLn;
WriteLnC :');
for i := J to n do Write(a[i]:7:2);
WriteLn;
k:-l; { , }
i;=7; { , 1}
while koQ do { }
begin
:-0; { }
forj:-l to 4 do { }
if (^^^'^ ^f^^^ { , }
begin
{ }
b:=a[j];
a[i+lj:^b;
:=-^1; { 1}
end;
i;=/+i; { 1}
end;
WriteLn(' *);
for i := J to do Write(a[i]:7:2);
WriteLn;
WriteLnC \ i:3);
End
. ,
. ,
, , -1
, . .
0^().
, ,
-1, -2, ...1 , . . (2-)/2
, ,
(2).
,
.
, , ,
103
4.
:
:=0
i:=l, , 1
max i- .
?^,
:=+1
i- -
-
-
.
-
(. 4.1).
.
i- - :
] = 1,, 1
A[kJ]:=A[ij]
-.
.
.
Program ex;
Var : arrayfI..JO,LJOJ of integer;
, max, n, m, k, i,j: integer;
Begin
WriteLnC n,m<=10');
ReadLn(n,m);
WriteLnC \n:4,' no \m:4,' ');
for i:'=l to n do
begin
forj:=l to m do ReadfafiJJJ;
ReadLn;
end;
WriteLnC :');
ReadLn(B);
WriteLnC ');
for i:=l to n do
begin
forj:=l to m do Write(a[iJ]:4);
WriteLn;
end;
k:=0;
{ }
105
1.
, ,
, .
,
, .
^^).
. ,
0(2). ,
, ,
. ,
0( log2 ).
, ()
[3,5]. 7.5.
4.4. .
. ,
, , ,
, . ,
.
.
,
.
,
.
4.10. , A(n,m),
< 10, m < 10, , .
:
:
.
.
.
.
, .
.
, 4.6.
104
1.
for i:=l to do
{ }
begin
max:-a[ij];
{ }
forj:-l to do { }
if a[ij]>max then max:-afiJJ;
ifmaxoB then { }
begin
{ }
:=+1;
{ }
forj:=l to do afkjj:=afi,jj; { }
end;
end;
ifkoO then { }
begin
(' *);
for i:^l to do
begin
forj:^l to m do Write(a[iJ]:4);
WriteLn;
end;
end
else
WriteLn(*Bce ');
End
. ,
,
.
. . 4.19
. ,
, ,
, .
: .
. :
for i:=l ton do
forj:-l to m do
< a[iJ]>
:
forj:=l to do
for /.=7 to n do
< a[ij]>
106
4,
4 4+
11
Jf
. 49. :
~ ; ~ ; - ;
- ; - ; ~
, .
(. 4.20).
,
. , ,
[,] , :
2,1
3.1
4,1
5,1
^ : i + j = +1
X
X
1.4
1,2
2J
3.2
5,2
7^\
3.4
3,5
4,3
5,3
, ^ [, ],
) : ! - j ' ^ p - k ,
) : i + j = + .
:
) : s ~ - | |,
) : s = - | + I - ( + ).|
2.5
4.5
5,4
5,5
: i = j
. 4.20,
107
L
1
10
11
12
13
14
15
4.1L ,
, . 4.21.
. 4.21.
. ,
, - .
:
- (i-l)*n + - j + 1,
- n*(i -1) + j ,
i - , j ~ .
,
.
,
, . ,
, .
Program exi
Var : array[1..3J.A] of integer;
k ij:integer;
Begin
k:-l;
for i:=l to 3 do
if (i mod 2)=0 then { }
forj:-4 downto 1 do { }
begin
^^ ; :=+1;
end
else
{ }
forj:=l to 4 do
{ }
begin
afiJJ:=k; k:-k+I;
end;
WriteLn(' :');
for i:=l to 3 do
begin
forj:=l to 4 do Write (a[iJJ:3) ;
WriteLn;
end;
End
108
4.
1,1
12
1,3
1,4
!,5
1,1
1,2^^1
2,1
22
2,3
2,4
2,5
2^
%2-^ |2^^'
1 \?v*
1 ii
J
;J>^
:7,*l
'^ 4
'^ s
^P
4,1
42
^fi?
A*
4,;5
5,1
52
1 " 1
..^-. .;i
X
m
1,5
-^,5
:'
4>
':0'0 4J
^
5.1 5 . ^
4, 5,5
1 ..'
:,pS'^,:t
. 4.22. :
- ; -
.
, ,
, .
, ,
(. 4.22).
,
.
4.12. ,
(. 4.23),
, [,].
,
.
1.3
. , [,
] 1
, , ^4':7^\ ]
, , , -
3,3 O^i^
. ;}
4.2 4,3 4,4 \
^
.
.
5.1 5,2 5,3 5,4 5,5
1 wviii-"mi"ii
Program ex;
. 4.23.
Var a:array[LJ5,L,15] of integer;
s,nXpXj:integer;
,
Begin
WriteLn('Beedume n< ==15 *);
[2,3]
109
1,
ReadLn(n);
WriteLnC \/() \/ ():*);
for i:=J to doforj:=^l to n do ReadfafiJJ);
ReadLn;
WriteLnC p,k:');
ReadLn(p,k);
WriteLn(*McxodHbiu ');
for i:=l ton do
begin
forj:=ltondo
Write(a[iJ]:4);
WriteLn;
end;
s:-0; { }
for i:-l to do { }
begin
forj:l to i'p-^k-l do { }
s:=s+afiJJ;
for j:-p^k'i-^l to n do { }
s:^s+a[ij];
end;
for i:=p+l to n do { }
begin
forj:-l to p+k-i'l do { }
s:-s+a[ij];
for j.'-i'p+k'l to do { }
s:=s+afiJJ;
end;
WriteLn(VyMMa \s);
End
.
. , ,
- ,
.
4.13. ,
, , . (
(. 4.24), =6
D
^
S = Sj+Sj
. 4.24.
4,
x[i,l]
x[i,2]
S:= S+x[i,2]-xk
xk:=x[i,2]
x[U]
x[i,2]
S:=S+x[i,2]-x[i,l]
xk:=x[i,2]
x[i,l] x[i,2]
S X-
. 4.25. i-ro :
- ; - ;
- ();
S - , -
.) .
.
,
. ,
,
, .
(. 4.25).
,
.
Program ten;
Var : array[1. .100J..2] of real;
iJ,n,k: integer;
xk,SyW:real;
Begin
Write('Beedume : *);
Readln(n);
WriteLnC . *);
for i:==I to n do ReadLn(x[iyl],x[i,2]);
{ }
yV=7; :=1;
while <>0 do
begin
:=0;
for i:=J to n-j do
ifx[ij]>x[i-^lj]then
begin k:=k-^I;
{ }
w:=x[ij]; x[ij]:^x[i-^lj];
x[i+l,l]:==w;
w: =xfi, 2J; x[l 2]: =xfi+J, 2J; xfi+ 7,2J: =w;
end;
111
end;
{ }
S:'=x[l,2]'X[lJ];
( }
xk:=x[]JJ;
{ }
for i:=2 to do
ifxfi, 1]> =xk then
{ }
begin S: =S-^xfi,2]'X[i, 1];
xk:=x[i,2J;
end
else ifx[i,2J>xk then { a}
begin S: =S+xfi, 2J'Xk;
xk:=xfi,2J;
end;
Write In (' \ S:6:2);
End.
1. D(n,m), , m < 20.
, ,
. -
,
.
2. A(n,m), , m < 15. ,
(),
,
. ,
0. ,
.
3. ,
D(n,n), < 15,
D[iJ]=
I sin(i+j)
1
I (i+j)/(2i+3j)
npHi<j;
npHi=j;
npHi>j,
i - , a j - .
,
, ,
. ,
, .
112
4.
4.5.
,
4.1, ,
.
, ,
: , ,
. Borland
Pascal - ,
.
. 4.26.
- ,
255 . ,
- 255 .
, ,
:
, :
Var Sly S2:string[40]; { 40 }
S3:strmg:
{ 255 }
, :
S40 = strmg[40]; { - 40 }
ST = string; { - 255 }
Var SJ,S2: S40; { S40}
S3:ST;
{ ST}
4.27, ,
,
,
. ,
.
. ,
,
/ string V j -
^
\J^
I | v L /
. 4.26.
< >
113
1.
^ 255
0 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
[si
lAJ |_
_^
^II
1 1 1 )
V
. 4.27.
, -
, :
Const S:strmgf40]= V
SJ:string= '*;... { }
.
, () .
.
, . .
, st[l] s[i].
, - ,
.
.
, i - , S3 -
, S3 :
1) /. = byte(S3[0]); { }
2) i:-ord(S3[0]): { }
, Length,
.
.
.
CTpoity-, :
S1:- 'ABCD V { }
52.= ' V
{ }
5.-=57;
{ CTpoiQ^ }
. - ,
-.
114
4.
,
. ,
. :
*fdc'+ 'ghj V { ' fdcghj'}
S4+ Vvv V
{ S4 'vvv'}
-
.
.
: = , , >, <, >=, <=.
. ,
ASCII .
,
#0. ,
, false true.
,
.
,
S4:='ABCD';
S3:='ADFH';
C:='L';
:
S4
S4
S3
S3
= S3
> S3
> S4
=
{
{
{
{
false}
false}
true}
false}
- . -
Read (ReadLn) Write (WriteLn), :
ReadLn(S]);
WriteLn(Sl):
ENTER.
, ,
.
.
ENTER,
, , , .
Enter,
, , .
115
L
.
.
1. Length(st):word- st, :
n:=Length(stl);
{
}
w, , ,
d, -
, :
:=-5.67;
Str(x:7:3,sl);
{ ' -5.670'}
,
.
5. Val(St, , Code) - St
.
Code : ,
, , st
.
116
4.
,
, :
Var S:strmg; Code:mteger; a:real; ...
.repeat
Write('Beedume a:');
ReadLn(S);
{ }
Val(S,afCode); { }
ifCodeoOthen
WriteLn(' *);
until Code-0;...
{ }
6. Copy(St,index,count):string - St
count , index, :
S1 = 'qqqEEEEEEuuuuu';
S:= Copy(SlJ,6);
{ ''}
7. Pos(St2,Stl):integer -
St2 Stl. ,
, :
S] = 'qqqEEppEEuuuuu':
i:= Pos('EE\Sl);
{ i=4}
8. UpCase(ch):char - ,
ch, ,
ch, .
,
4.3 .
4.14. 40 , ,
. .
,
.
. Pos,
,
, .
, ,
(. 4.28).
.
Program ex;
Var st:string[40];
k:byte;
117
I.
1.
delete
(St, 1,1)
k:=length{st)
:st[k] = 'J>
1
delete
(st,k,l)
. 4.28.
Begin
WriteLnC <= 40 ');
ReadLn(st):
Write (* :');
WriteLn(^);
k:-posC^^ \st); {, ?}
while <>0 do { }
begin
delete(st,k,l);
{ }
k:=posC^^ ^,st); {, ?}
end;
ifst[l]= ^^^ then delete(stJJ);
{ }
:;= length(st);
ifst[kj= ^^^ then delete(st,kj); { }
WriteLn(':');
iflength(st.)<>0 then WnteLn(st)
else WriteLn(' codepjfcana .');
End
118
4.
45. , ,
, , , - ,
, . :
1956 => .. 45
- .
. .
,
. Pos,
1. ,
. !^.
, .
2. - .
, ,
, !^,
.
. ,
.
.
. 4.29.
Program stroka;
Var st,strez,strab:string[40]:
cl, c2, c3, n, old, code:word;
cl
[T|
St T""^
1| 1 a 1HI 01 1 | | | | | | | | [ [ )( | | | |
^
2
|1|9|5||
1 4 1
strab
^
''
||||
| | | | | () | 1 1 ] 9] 5 |]
1 1
""^^
bxaxastrez j ^
|||||||
\.\2^
t ] 1 1 1 1 1 II
. 4.29.
119
I.
Begin
WriteLn(' . - .');
ReadLn(st);
while sto^^ do { , }
begin
cl:=Pos(' ',^/);{ }
strez:=Copy(stJ,c] + lJ+ \ V { ,
}
strab:=Copy(st,cl+2,Length(st)-cJ-l);
{
}
c2:=Pos(' \strab); { }
strez:=strez+strabfc2+lj+ \ V {
}
Delete(strabJ,c2+l);
{ }
c3:=PosC \strab); {onpmQ^HQM }
Delete(strabJ,c3);
{ }
Val(strab,n,code);
{ }
old:=2001'n;
{ }
Str(old,strab);
{ }
strez:=strez-^ ' '+strab;
{ }
WriteLn(strez);
{ }
WriteLnC . - . ');
ReadLn(st);
end;
End.
4.6. .
, ,
.
4.16. ,
. .
.
, . , .
, ,
, , ,
. ,
.
.
Program strokal;
Var St: string;
p, spos: integer;
120
4.
Begin
WriteLn(' ');
ReadLn(st); { }
:=0;
{ }
ifst[Length(st)] <> ' ' then st:=st-^ ' V { ,
}
while Length(st)<>0 do
begin
spos:^ Pos(' \ St);
ifspos>5 thenp:=p+J;
{ }
Delete(st,l,spos);
{ }
end;
WriteLnCB \ p, ' (), . ) ;
End.
4.17. ,
.
.
.
, .
Program Stroka;
Var mbyte; s, si, s2:string;
Begin
WriteLnCBeediwie );
ReadLn(s);
WriteLnC : ) ;
ReadLn(sl);
WriteLn(' : ) ;
ReadLn(s2);
n:=Pos(sl,s);
{ }
while > do
begin
Delete(s,n,Length(s 1)); { }
Insert(s2,s,n);
{ }
n:=Pos(sl,s); { }
end;
WriteLn(Teymam : \s);
ReadLn;
End
4.18. ,
. ,
.
121
1.
1.
,
. ,
, ,
,
.
. ,
.
. ,
, ,
,
, .
, ,
. ,
, . ,
,
. ,
, ,
.
Program Stroka2;
Var nsl, ns2, ks, nl, 2, dll, dl2,ns ,dls, i, w:byte;
s, si, s2:string;
Begin
WriteLn(* '); Readln(s);
ks:=0; { }
for /.= 1 to Length (s) do
if(s[i]=' ') or (i=length(s)) then { }
ks:=ks-\-l: { }
WriteLn('Beedume ');
ReadLn(nl,n2); { }
while (nl>ks) or(n2>ks) (1=2) do { }
begin
WriteLnC \ks:5,
\ .
. *);
ReadLn(nl,n2); { }
end;
ifnl>n2 then
{ }
begin w:-nl; 1:=2; n2:=w; end;
ns:=l;
{ 1}
dls:=0; { 0}
ks:=0; { 0}
122
4.
for i:^l to Length(s) do {no }
begin
if(sfij=' ') or (i=Length(s)) then { }
begin
if (i=Lengt/t(s)) and (sfij <>' ') then {
}
dls:=dls+l; { }
b:=ks+l;
ifks=nl then { }
begin { }
ns 1: =ns; dll: =dls;
end;
ifks=n2 then { }
begin { }
ns2:=ns; dl2:=dls;
end;
dls:=0; { }
ns:=i+l; { }
end
else
dls:=dls+l; { }
end;
sl:=Copy(s, nsJ, dll); { }
s2:=Copy(s, ns2, dl2); { }
Delete(s, ns2, dl2);
{ }
Insert(sl, S, ns2);
{ }
Delete(s, nsl, dll);
{ }
Insert(s2,s,nsl);
{ }
WriteLnf' : \ s);
End.
2.
.
. , , .
. -,
. - ,
.
, ,
,
.
Program StrokaS;
Var ks, nl, 2, i, kbyte; 5, si .string;
MasStr:array[L. 100] ofstring[20];
{ }
123
L
Begin
WriteLnC '); Readln(s);
ks:^0; { }
ifs[length(s)]<>' ' then 5;='+' V { ,
}
{ }
while s<> *' do
{ }
begin
b:=ks+l;
{ }
k:=Pos(' \s); { }
masStr[ks]:=Copy(sJ,k); { }
Delete(sJ,k);
{ }
end;
{ }
WriteLn('Beedume ');
ReadLn(nl,n2); { }
while (nl>ks) (2>) (]=2) do { }
begin
WriteLn(' \ks:5,
\ . ');
ReadLn(nl,n2); { }
end;
sl:=MasStrfn]J;
{ }
MasStrfnlJ: =MasStrfn2J;
MasStr[n2]:=sl;
{ }
for /;=7 to ks do s:=s-^MasStr[iJ; { }
Delete(s,Length(s),l);
{ }
WriteLnC : \ s); { }
End
4.19. , .
MasStr[n], <100.
.
-.
.
. 99 ,
,
.
.
1. - .
124
4,
.
. .
,
.
, - .
(n-fl)/2 , ..
().
2.
. ^ ,
. .
,
. ,
. , , ,
, - . ,
, .
, ,
.
. 4.30 ,
10 . 5-
, : 1 ...4 6... 10.
- 2-, 5- , 8-,
5- .
. .
1
2 .3
1-
1
2-
3-
11
11
10
9 10
1
9 ^10
~1
1 I \
6^7
4-
10
I ,
. 4.30.
10
125
1.
. ,
, ..
= 2J-1, j=l, 2, 3 .., log2 .
,
, ,
(log2 +1)/2, .. 0^,p(log2 ),
,
.
. ,
, .
.
Program ex;
Var MasStr:array[L. 100] ofstring[22];
n, k, I: integer; st:strmg[22];
key:boolean;
Begin
n:=l;
WriteLnC 100 - ');
ReadLn(MasStr[n]);
while (MasStr[n]<> 7 and (n<100) do
begin
n:=n+l;
ReadLn(MasStr[n]);
end;
ifn<100 then :='1; { }
WriteLnC .');
ReadLn(st);
:=1; key:=false;
while ('>=0) and not key do {
}
begin
1:-(') div 2+;
{ }
ifst=MasStr[l] then key:-true
{ }
else
{ }
if s(>MasStr[l] then k:-lH
{ }
else n:-l'l;
{ }
end;
if key then
WriteLn(' . \1)
else WriteLnCCmpoKa .');
End.
126
4.
1. 80 , ,
, . ,
, .
. ,
.
2. 40 , ,
, . ,
, .
. -
.
3. , 40 .
, , . ,
,
, . ,
0.
.
4. , , .
, ,
. .
5. ,
, 4.
,
.
4.7.
. .
.
Borland Pascal ,
.
, -
.
.
(. 4.31).
,
255.
127
l.
integer
. 4.3L
longint, < >
255.
.
.
.
,
, :
set \
I
^ ^0 1
I
4.
[2100] - 2 100;
/"/, 2, i.. 7] - , 1,2,3,4,5,6,7;
[red,yellow,green] - ,
.
.
.
:
setnum =set of byte;
Const S:setnum=[LJOJ; { ,
,
1 10}
.
,
, : ^
. ,
- ,
.
. Borland
Pascal . 4.1
.
4.1
AuB
Borland Pascal
'
((
J )
,
,
1
~
,
,
,
,
129
I.
:
[1,2] + [3,4] = [U,3,4];
[1..10] * [3,8,9,15,23,45] = [3,8,9];
[1..15] - [3,8,9,15,23,45] = [1,1,4..7,10.4];
[red,blue,green,black] * [bIue,magenta,yeIlow] = [blue].
.
.
. . 4.2
,
Borland Pascal.
.
,
in (. 4.32). ,
in
. in,
,
.
. 4.32.
< > .
4.2
Borland Pascal
130
TRUE
FALSE
<>
<=
- j
>=
4.
[*% ''] = ['% ''] - TRUE;
[4, 5, 6] = [4..6] - TRUE;
['c%'b'] = ['% 'b% '] - FALSE;
[2,3, 5,7] <= I1-9] - TRUE;
[3, 6..8] <= [2..7, 9] - TRUE;
[3, 6..8] <= [2..7, 9] - FALSE;
[5..8, 9.2] >= [6, 8,11] - TRUE;
10 in [2, 4, 6, 8,10,12,14] - TRUE;
in [1, 3, 5, 7, 9] - TRUE =1,3,5
FALSE =2,4,6
,
.
, , :
*^~// { }
Read(n);
while not Eofdo
begin
S:=S+[n]; { }
Read(n); { }
end;...
,
:
, , :
fori:='a4o
'z'do
if i in S then Write(i:3);
.
4.20. , ,
, ..
.
, :
:
rA'..'Z','a'..'z','J] .
,
, :
['A'..'Z','a'..V,'J/0'..'9'].
,
, .
131
1.
Program ex;
Var St: string;
key: boolean;
i: integer;
Begin
WriteLn(* ');
ReadLn(st);
ifstflj in f^A\. 'Z^'a\, 'z\^__7 then { }
begin
i:=2;
key:=true;
while (i<=length(st)) and key do { }
ifst[i] in \. 'Z\'a\. 'z\ 1 ^'0\. '] then inc(i)
else key: =false;
if key then WriteLn(' \st,' - . *)
else WriteLnf' \st,' .');
end
else
JVriteLnCCmpoKa \st,' .');
End.
4.21.
.
, .
, 9, ,
, .
Program ex;
Var n:longint;
st:string;
mnoj:setof'0\.'9';
i: integer; j:char;
Begin
WriteLn(' : ');
ReadLn(n);
Str(abs(n),st);
mnoj:-[];
{ }
for i:=l to length (st) do
mnoj:=mnoj-^[st[i]]; { }
WriteLn(' \n,' : *);
forj:= ''to '9'do
{ , }
if j in mnoj then Write(/+' ');
End
132
4.
4.22. , ,
,
, , :
;
;
;
.
ASCII.
.
:
resl - , ,
res2 - , ,
res3 - ,
res4 - , ,
mnsl - , .
.
.
mnsl.
,
resl = res2 = res3 = mnsl,
a res4 .
,
:
1) , ,
, ,
:
resl mnsl;
2) , , res4
() :
res4 U (res3 n mnsl);
3) res3 ()
:
res3 U mnsl .
, , res2
,
:
res3 \ res4.
133
I.
Program ex;
Type setchar=set of char;
Const G: setchar - ['\'\\'\'\'''\'\^\'^];
{
}
Var resl, { , }
res2, { , }
res3, { }
res4, { , }
mnsUsetchar; { }
st,slovo: string;
ch: char;
ik:integer;
first: boolean;
Begin
WriteLn(' :');
ReadLn(st); { }
st:=st'^ * V { }
first:"^true; { }
while st<> " do { }
begin
k:=pos(* \st);
slovo:=Copy(stJ,k'l);
{ }
Delete(stJ,k);
{ }
{ , }
mnsl:=fj;
{ }
for i:=l to '1 do
ifslovofij in G then
{ , }
mnsl:=mnsl+fslavefiJJ; { }
{ }
if first then { , }
begin
resl:=mnsl; { }
res2:=mnsl; { }
res3:-mnsl; { }
res4:-[];
{ }
first:=false;
{ }
end
else
{ , }
begin
resl:=resl*mnsl;
{ }
res4:='res4+res3*mnsl; { }
res3:=res3-^mnsl;
{ }
end
end;
res2:=res3'res4; { }
134
4.
{ }
WnteLn(*DiacHbie, : *);
for ch:=#0 to #255 do ifch in resl then Write(ch:2);
WriteLn;
WriteLn(', :');
for ch:=#0 to #255 do ifch in resl then Write(ch:2):
WriteLn;
WriteLn(Tace, :');
for ch:=#0 to #255 do ifch in res3 then Write(ch:2):
WriteLn;
WriteLn(', : ');
for ch:=#0 to #255 do ifch in res4 then Write(ch:2);
WriteLn;
End
1. , , ,
. , , ,
, @, #, $, ^, &, _,
*, %, ~. , ,
.
2. , , ,
. , , ,
, .
. ,
.
3. ,
. (: 345 6785 1235 54
657). , ,
.
. (
. 5.)
4. , ,
. .
, :
( ),
.
5. ,
, . , ,
, i, j , , I, m, .
.
135
1.
4.8.
- , , .
, .
, .
Borland Pascal :
(. 4.33).
.
. 4.34.
,
:
, :
Var ZapLZapl: record { , 5 }
F,S:real; { }
, .'integer; { }
C:char;
{ }
end;
Zap3: record {, 3 }
S: string /80/; { 80 }
: array [1..20] of real; { 20
}
Flag:: boolean; { }
end;...
, :
record j I
to,
end
-- "0--
. 4.34.
< >
136
4.
Ztl = record
{ , 5 }
F,S:real;
{ }
AyB:integer;
{ }
C'char;
{ }
end;
Zt2 = record
{ , 3 }
S: string [80]; { 80 }
: array [1..20] /^^/;{
20 }
Flag: boolean; { }
end;
Var ZapU Zap2:Ztl;
{ Ztl}
Zap3:Zt2; ...
{ Zt2 }
,
, , :
Human=record
{ }
Fio: record
{ 3 }
Fam,
{}
Name,
{}
Otch: string;
{ }
end; {Fio}
BirthDay: record
{ 3 }
Day:!.,31;
{}
Month: 1..12;
{}
Year: word;
{ }
end; {Birthday}
end; ...{Humein}
1.
. 4.35.
< >
,
, :
Var Sotr: Human;
Otdel: array [1..20J of Human;
.
, .
,
, :
Const
BirthDay: Data = (Year: 1973; Month:6; Day:30); ...
.
.
.
. 4.35.
, Sotr Human, ,
:
Sotr. BirthDay Day: =-25;
: =SotKBirthDay. Year;...
, ,
with (. 4.36). , Sotr Human
Day
with:
with
^)
4.
)
)
)
r)
with
with
with
with
Sotr do BirthDay.Day:=30;
SotnEirthDay do Day: =24;
Sotn BirthDay do Daay:=31;
Sotr do
with BirthDay do Day:= 7;...
.
. :
OtdelfiJSotr;...
.
4.23. ,
: .
,
.
Program ex;
Type
data=record
( }
year: word; {}
month:LJ2; {}
day:L.31;
{}
end;
zap-record
{ }
fam:stringfl 6J; { }
birthday: data;
{ }
end;
Var fb:array[L.25] of zap; { }
fff:string; { }
ij,m,n:byte;
key.'boolean; { , - true}
Begin
WriteLnC <=25');
ReadLn(n);
:=0;
{ }
repeat
:=-^1;
Write(*Beedume :');
Readln(fb[m].fam);
Write(* : '); Readln(fb[m]Mrthday.year);
WriteC
: ');
ReadLn(fb[m].birthday.month);
WriteC
: *);
ReadLn(fb[m].birthday.day);
until n=m;
WriteLn;
139
/.
{ with}
WnteLn(' '); WriteLn;
for /;=7 to do
withfbfijdo
begin
Write(i:2,fam:17);
with birthday do
WriteLn(year:6, month:4y day:4);
end;
WriteLn;
{ }
WriteLn('Beedume ');
ReadLniffJ):
i:=0;
key:=false; { }
repeat i: =1+1 ;
if/bfij.fam =fffthen key: = true
until key or( i=m);
{ }
if key then { , }
withfb[i]do
begin
WriteLnCae : ');
Write(fam:18/ ');
with birthday do
WriteLn(day:2,': \month:2, V \year:5,' ');
end
else WriteLn(' : \fff:18,' .');
End.
.
, . .
.
(4.37).
,
, ,
. ,
.
:
:
140
4.
case
\<
hGKDH
hi
].
, ,
(, - , ).
Forma = record { }
case { }
boolean of { , }
{ }
True: (Birthplace: string[40]; { }
{ }
False: (Country: stringf20J; {}
EntryPort: string[20]; {}
EntryDate: array[L.3] of word; {}
Count: word) {}
end;.,.
:
Object2 - . Object 1 -
:
Const
,
,
. , ,
,
().
,
. ,
, , . .
,
.
,
. ,
.
.
.
142
4.
,
,
, , .
:
= record { }
case byte of
0: Wo:word;
{ word}
1: Lodongint; { longint}
2: Re:real;
{ real}
end;
Var OPerem;
Begin...
C.Lo:=0; { }
C.Wo:=10; {
10}
WriteLn(C.Lo:10);... {
}
6
.
,
.
1. , , ,
, :
, , , .
.
, .
2. ,
, : ,
.
,
: 5 - (+ 25%), 4 - (+10%),
- , - (-15%),
- 0.
.
.
143
5.
.
., , ,
,
. Borland Pascal
: .
5.1.
,
( ). Borland Pascal
- , .
,
, (
). ,
, .. ,
, , (. 5.1).
.
(
, , ).
begin...end.
-.
,
.
(. 5.2).
>
. 5.1.
< >
144
5.
- ^ procedure V
- ^ function V
I I \1^
,<7>
[!
\^^
. 5.2.
< > {) < > ()
.
.
.
:
- ;
- .
.
,
.
. .
,
, ,
, . ,
, ,
,
.
, . 5.3
, .
,
. z ,
z .
z, .
,
,
, ,
. , , 145
1.
Program ex;
Var xrreal; z:real;
-----t":
Procedui^ A;
Var z: integer;
PrdeodurfesB;
Var irtfitegerK^
Begin i:=z; x:=5;
End;
B^gin
\
-round(x);
End;
Begin
End.
. 5.3.
, ,
.
- .
.
(. 5.4). ,
, ,
.
- ,
, .
(
, . ). ,
var
'-*/ const V
U|OLJ
11 V
L/7V
I [
5.
,
.
Borland Pascal
:
-
,
;
-
,
,
;
var; -
\
( ) -
, ,
,
;
const.
. , ,
-,
. , ,
-
, .
,
.
. ,
, ,
( ,
..), :
<>:=< >(< >).
,
:
< >(< >).
-
: - ,
.
, ,
- return.
147
1.
J
i
Stf(x,y,z) J
.
a,b,c,d,e
'
p:=(x+y+z)/2
I
Strf(.)+Stf(,
{ j
Return
a,b,c,d,e
p:=(x+y+z)/2
Stp
(a,b,e,SI)
s=v:.
stMT..
i
81(,,,5
.
Stp
(c,d,e,S2)
Return
SHS2
f
. 5.5.
{) ()
5.1. ,
.
, .
.
- .
, -
-. -
, , .
, .
. 5.5.
.
:
Program ex;
Var A,B,C,D,E:real;
{ }
{ }
Function Stf(const X, Y,Z:real):real;
Varp:real;
{ }
begin
{ }
p:=(X^Y+Z)/2;
Stf:=sqrt(p^(p^X)^(p-Yr(p^Z)):
end;
148
J.
{ }
Begin
WriteLn ');
ReadLn(A,B,C,D,E);
]1('1 ', Stf(AjB,E)+Stf(CyD,E):7:3);
End.
Program ex;
Var A,B,C,D,E:real; SJ,S2:real; { }
{ }
Procedure Stp(const X, Y,Z:real;var S:real);
Varp.real;
{ }
begin
{ }
p:=(X+Y+Z)/2;
S: =sqrt(p *(p'X) Y;?- Y) *(p-Z));
end;
{ }
Begin
WriteLnC );
ReadLn{A,B,C,D,E);
Stp(A,B,E,Sl); { }
Stp(CyD,E,S2); { }
\S1+S2;7:3);
End
, , ,
( string), , , ,
:
type.
:
mas^arrayfl.JOJ /real;
str80=stringf80J;
procedure (M:mas; fout:str80);...
5.2.
, < 10.
- ,
-. 10
. mas 149
I.
,
-. .
Program ex;
Type mas-arrayll.AO] of integer; { 10 }
Var aimas;
i,n: integer;
Function sum(b:mas; n:integer).'integer;
Var s: integer;
i: integer;
Begin s:=0;
for i:=I to n do s:=s+b[ij;
sum:=s;
End;
Begin
ReadLn(n);
for i:=l to n do Read(a[i]);
ReadLn;
WriteLn(VyMMa= \sum(a,n));
End
5.2. .
, , ,
.
5.3.
, = sin , = cos , = tg , = In , = ^
:
;
;
.
. : ,
, ,
.
(. 5.6, )
.
(. 5.6, ). ,
,
(. 5.6, '). ,
150
5.
:
1 - sin X
2 - cos X
3-Inx
4-'^
5 -
: _
:
1 - ;
2 - ;
3 - ;
4 - .
: _
: _
: _
1 : _
: _
.
1 =...
=...
=
=...
=...
=...
=...
=...
.
.
.
J
: _
: _
=... =...
=... =...
.
. 5.6. :
- ; - ; - -
.
, .
,
, 4 ().
,
.
. 5.7
, ,
() .
151
1.
. 5.7.
. , ..
.
.
. ,
5, ,
. ,
:
:
__.
_.
- _ 5
_, (_)
___.
_.
-.
.
: __ __ (__).
__ :
152
J.
^^:
_^.
.
1 - sin ;.
2 - cos ;.
3 - In ;.
4 - '^;.
5 - ..
.
_ (_)
:
_ ():
^_.
_.
- _ 4
__ :
1: (_);
2: (_);
3: (_);
-.
__. .
_ .
-.
.
___ ___:
^__:
_.
:.
1 - ;.
2 - ;.
3 - ;.
. 4 - ..
: .
.
(_)
:
153
I.
(__):
__.
, .
.
h.
=
- X <
(_, , )
=, , =,
=, ,
-
x=x+h
-.
___.
.
(_) (_) . ,
.
: true , false - .
- :
(_, , ):
=1
:
1: y=sin(x);
2: y=cos(x);
3: >0
=1()
=18
-
4: =()
-
.
, ,
( __ ^^
(^ ).
154
5.
. 5.8.
, (. 5.8).
.
,
(,
begin end). ,
..
1. B(n,m), , m < 20, m > . ,
(,)
m-n .
,
, .
.
2. SIM(n,m), n,m20).
,
,
. SIM , :
. ,
.
155
I.
5.3.
, , , , ,
.
-
, .
: -
, -
.
:
Unit < >;
Interface
< >
Implementation
< >
[Begin
< >7
End,
,
.
.tpu.
. Borland Pascal
, :
Compile - ,
< >.1
, , .tpu
(Options/Directories);
- , .tpu,
.pas, ,
;
Build - .tpu
.
Build,
- Compile.
(
), .
,
, ( 156
5.
, , ).
, .
CeKifUH UHuifuanwaifuu ,
, (
, , ..).
(
) .
.
, ,
:
Uses < !>, < 2>, ...;
uses ,
( )
. ,
.
.
5.4. ,
.
5.2 :
,
.
, .
{ Summa.pas}
Unit Summa;
Interface
{ }
mas=array[L.]OJ of integer;
Function sunt(b:mas;n:integer).'integer;
Implementation .
Function sum; { }
Var
s: integer; i: integer;
begin 8:^=0;
for i:=J to n do s:^s+b[i];
sum:=s;
end;
End.
: mas
Sum.
Program ex;
Uses Summa; { }
Var a:mas; { mas}
i,n: integer;
157
L
Begin
readln(n);
for i:=l to n do re ad(a[i]);
ReadLn;
WriteLn('CyMMa= \sum(a,n));
{ sum}
End
Bee , ,
. ,
,
< >.< >.
, X:
Unit ;
Interface
VarX:real; ...
End
, ,
X:
Program ex;
Uses ;
Var X:integer;
Begin
X:=10;
{ }
A.X:=0.45; ... { A}
Borland Pascal ,
.
Borland Pascal
.
System ~ -
, , ,
, ..
.
Crt - -
, ,
, .
Graph - -
, ,
.
158
5.
Dos -
MS DOS - ,
.
, Printer, Graph3,
Overlay .
. , System, Crt, Dos, Printer
Turbo.tpl, Graph Graph.tpu.
, ,
:
, .
5.4.
Borland Pascal ,
, . ,
,
-, .
- ,
.
-
, :
array of real;
array of integer;
. , ,
, ,
.
. - -
, -- .
^/^('< >) - ,
, -
.
/,(?'('< >) -
, - .
.
5.5. 5.4. -
,
, .
159
I.
, 5.4,
: mas.
,
.
.
Unit Summa2;
Interface
Function sum(b:array of integer; n: integer): integer;
Implementation function sum;
Var s: integer; i: integer;
begin s:=0;
{ ,
-1,
}
for i:=0 to '1 do s:=s+bfij;
sum:=s;
end;
End.
.
Program ex;
Uses Summa2;
Var a:array[l.. 10] of integer;
i,n: integer;
Begin ReadLn (n);
for i:=I to n do Re ad(a[i]);
ReadLn;
WriteLnCCyMMa=\sum(a,n));
End.
5.6.
, , .
.
,
High.
Unit ;
Interface
Function sum(b:array of integer): integer;
160
5.
Implementation
Function sum;
Var s: integer; i: integer;
begin s:=0;
for i:=0 to High(b) do s:-=s+b[i];
sum:=s;
end;
End.
Low High, -5 -3.
Program ex;
Uses SummaS;
Const a:array['5..'3,3,. 7] ofinteger=((], J, /, 7,1),
(2X2X2).
(3X3,3,3));
Var i:integer;
Begin
for i:=Low(a) to Higlt(a) do WriteLn(sum(a[i]));
end.
. ,
, - a[i].
,
- , (. 5.5).
.
Borland Pascal,
-, .
, -
. ,
,
{$+} - openstring.
5.7. , ,
.
,
,
:
Unit Stroka;
Interface
Procedure Add(var s: openstring);
161
L
Implementation
Procedure Add;
begin
s:=^s+chr(succ(Ord(s[length(s)J)));
end;
End
s ,
,
(Error 26: mismatch).
Program ex;
Uses Stroka;
Var S:string[26]; i:integer;
Begin
s:^'A\for i: =2 to 26 do Add(s);
WriteLn(s);
End
.
1. ,
, . . .
2. ,
. .
. .
5.5.
Borland Pascal ,
.
( -),
.
, -
, - .
:
162
5.
;
.
(. 2.5), :
Procedure Proc(Var:a);...
...b:=Integer(a)-^IO;,..
absolute (. 2.3), :
Procedure Proc(Var:a);...
Var r:real absolute a;...
, , , ,
.
5.8. ,
,
.
, .
.
64 /< >.
.
treal, mr, tinteger - mi.
Unit Summa4;
Interface
Type ttype=(treal, tinteger); { }
Function sumfvar x;n:integer;t:ttype).real;
Implementation
Function sum;
Var mr:array[L.maxint*2 div sizeof(real)] of real absolute x;
mi: array[L.maxint^l div sizeof(integer)] of integer absolute x;
s:real;i:integer;
begin s:=0;
if t=treal then
for i:-I to n do s:=s+mr[ij
else for i:=I to n do s:-s+mifij;
sum:=s;
end;
End
163
I.
.
Program ex;
Uses Summa4;
Var a:array[L.10] of integer;
b:array[L.15] of real;
i,n; integer;
Begin
for i;=l to 10 do Read(a[iJ); ReadLn;
WriteLnCCyMMa= \stim(a,10,tintegerJ:8:J);
for i:=l to J 5 do Read(b[i]); ReadLn;
WriteLn('CyMMa= \sum(b, 15jreal):8:l);
end.
.
1 ,
{$R-}.
,
.
,
, ,
, ,
. , (2,3,2)
:
bl,l,l' ^^1,1,2' bi,2,i, b | 2,2^ b] 3,1, b] 3 2, b 2 | j , ^2,\,b ^2,2,1' ^2,2,2^ 21, 2.
5.9.
.
. 5.9 , (,)
, <, , ,
.
, i j
(i-l)*P+j, ..
.
.
, ,
.
. ,
* div 2.
* , ,
.
164
5.
1-
..
. 5.9. (,) {) {)
Unit Matrica;
Interface
Procedure tran(Var x;n,P:integer);
Implementation
Procedure tran;
Var a:array[1..2*maxint div sizeof(real)] of real absolute x;
ij: integer;
t.real;
begin
for i:=2 to n do
forj:=l to i-I do
begin t: =a[(i-l) ''P+jJ;
af(i-l) *P+jJ: =afO'l) *P+i];
a[0'l)''P+i]:=t;
end;
end;
End.
:
Program ex;
Uses Matrica;
Var a:array[L .10J,. 10] of real;
ij.'integer;
Begin
WriteLnC a(5 *5);');
for i:=l to 5 do
begin
for j:=l to 5 do Read(a[i,j]);
ReadLn;
end;
165
I.
tran(a,5,10);
WriteLn(': *);
for i:-l to 5 do
begin
forj:=l to 5 do Write(a[iJ]:6:2);
WriteLn;
end;
End
1. ,
nxm . .
2. ,
nxm . .
.
5.6.
,
.
, , :
proc=procedure (a,b,c:real;Var d:real):
func=function(x: real): real;
:
Var f:func;
/:1;...
,
,
(
{$+} far).
4- (. 7.1)
2- ,
, .
166
5.
: 1.
(. 5.2), ,
.
2. , System,
.
,
, ,
.
5.10. ,
[,] .
. :
UnitSFun;
Interface
Type func-functwn(x:real):real;
Procedure TabFun(f:func;a,b:real;n:integer;
Var Masf:array of real);
Implementation
Procedure TabFun;
Var h.real; i:integer;
Begin
h;=(b-a)/(n'l);
for i:=0 to n-l do Masf[i]f(a+h*i);
End;
End
. sin
.
Program ex;
Uses SFun;
Var masFl: array[L, 10] of real; masF2: array[L. 20] of real;
i: integer;
function Fl(x:real):real; far;
Begin Fl:-sin(x); end;
function F2(x:real):real; far;
Begin F2:-exp(x)+cos(x); end;
Begin
WriteLnC sin x:);
TabFun(FIA2J0,masFI);
167
1.
I 1,
=0;
I Nx(N-l)!,
>0.
.
. .
.
,
.
/76?/cy/?cwe;/(9w ,
.
:
-
;
-
,
.
168
5.
3tofi . ,
, mueaifuu.
:
;
-;
- -
;
( string);
- 12 ,
( )
.
5.11.
, .
1.2. .
: ,
.
:
.
,
.
- R.
(. 5.10, ). ,
, .
1(,) J
1(,))
>
R=A
>
Nod = A
Nod
(.,)
Nod
(A,B-A,R)
Nod =
Nod(A-B,B)
Return
Nod =
Nod(A,B-A)
I
Return
. 5.10. :
- ; -
169
1.
1
[_
<
1
=4
1
<
1
>
|_
<
1
1
V
~4
-8
=4
8
=12
,
-
-
-
-
J
. 5.11.
Program ex;
Var a,b,r:integer;
Procedure nod(a,b:inieger; var rnnteger);
Begin ifa-b then r:-a
{}
else ifa>b then nod(a'b,b,r)
else nod(a,lhayr)
End;
Begin ReadLn(a,b);
nod(a,b,r);
WriteLn(r);
End,
- . , =12
=8
, . 5,11 ( , . . 2
, ).
1^ (. 5.10, ),
, .
:
Program ex;
Var ,b,r:integer;
Function nod(a,b: integer) .integer;
begin ifa=b then nod:'=a {}
170
5.
else
{ }
ifa>b then
nod:=nod(a'b,b)
else
nod:=nod(a,b'a)
end;
Begin
ReadLn(a,b);
r:=nod(a,b);
WriteLn(r);
End
, ,
, ,
. ^
.
.
. ,
16 , 64 .
5.12.
( , -
..).
.
.
- :
, - . .
, ,
.
:
Function reversel (const st: string): string;
Begin iflength(st)=0 then reverserl:= "
else
reverserl: = reversel (copy (st, 2, length(st)'l)) +stflj;
End;
:
V = 4 ( ) + 256 (-) +
+ < > 270 ().
171
I.
5.
Root
(. ,) J
. 5.12.
Procedure root(a,b,eps:real;var r:real);
Varf,x:real;
Begin x:=(a+b)/2;
f:=x*X'l;
ifabs(f)<=eps then r:=x
else
if (a *a'l) y> 0 then root(x, b, eps, r)
else root(a,x,eps,r)
End;
Begin ReadLnfa, b, eps);
root(a,b,eps,x);
WriteLn(' x^ \x:9:7);
End
, ,
,
.
.
: ,
,
Borland Pascal.
forward, : 173
1.
. 5.13.
,
forward;
(
).
,
,
(. 5.13),
:
5.
Function f_char;
Begin
if i>length(st) then f_char:=true
else
if Mi] in ['A \. 'Z\ 'a'.. *z']) then
f_Shar: =f_value(st, /+1)
else
fjohar:=false;
End;
Begin
WriteLnC : *);
Readln(s);
iff_char(s, 1) then
WriteLnCCmpoKa *)
else WriteLnCCmpoKa *);
End
, . 5.14, ,
.
.
, ,
.
f
,
V (-0 J
, . 5.15.
,
,
, (
" "
) ~
, ~ ,
(...)
\
.
.
"
5.15.
"
,
, ,
( Return j
,
-
.
. 5.14.
.
175
J.
" "
" "
. 5.15.
, , , .
.
:
, -
,
.
Program ex;
Type mas =array[I.. JOJ of real;
Var x:mas;
i: integer;
Procedure print(var x:mas;i: integer);
Begin
ifx[i]=Othen WriteLnf'***')
else
begin
ifx[i]>0 then WriteLnfi,': xfij);
print(Xyi+l);
{ }
ifx[i]<0 then WriteLn(i,' ^ xfiJ);
end
End;
Begin
i:=0;
repeat i:=i+l; Read(x[i]) until x[ij=0;
ReadLn;
print(xj);
End.
\16
5,
. , i
,
:
, .
1 2 li
12
13
21 23
23
311 32
,
. 123 132 213 231 312 321
. 5.16.
.
,
=3
.
5.16. ,
. ,
, ABC,
: ABC, , , , CAB, .
,
m .
-1 . -
1-2 ..
Perest
- --
(,,,)
J
. +1-
.
. 5.16
r^^:=l,m-n+lV-|
=3.
,
p[n]:=i
p[m]
n-m+1 ,
rl
1.
Perest
(n+l,m,rl,p)|
. 5.17.
1 1I I 1 1
Program ex;
Type
mas=array[L,5] of char;
Const a:mas= 'ABCDE V
Var pole:mas;
Return
. 5.17.
177
I.
procedure Perest(n,m:integer; Const :mas; Var pole:mas);
Var rl:mas;
kjJ: integer;
Begin
ifn>m then
begin
for i:=l to m do Write (pole fij);
WriteC '):
end
else
for i:-l to m-n+l do
begin
pole[n]:^r[i];
k:=l;
forji^l to m-n^l do
ifjoi then
begin
rl[k]:-r[j];
k:=k+];
end;
Perest(n-^l,m,rl,pole);
end;
End;
Begin
Peres t(l, 5, a.pole);
End
.
:
V, = 2*2 + 4 + 4;
: V2 = m + 3*2;
: V3 12.
V = V, + V2 + = 12 + m + 6 + 12 30 + .
+ 1 .
. ,
, , ,
.
178
5.
1. ,
:
DDDD
FFFFFF . . 26 . .
2.
:
, m>n>0;
C{m,n} = ^ U ^ (=0 >0) (m=n=0);
I C{m-l,n-l} + C{m,n-1} .
3.
( [3, 6]).
. , , ,
, ,
- .
, .
.
. .,
.
( Iog2 ).
4. .
. m .
.
,
.
5.8. . .
,
().
,
, .. .
.
0(!) 0(").
179
I.
:
;
. .
,
, ,
, .
( )
, .
, ,
.
.
-
,
-
-
( , ,
). .
5.17.
: 1111, 1112, 1113, 1121, 1122, 1123, 1131, 1132, 1133, 1211,..., 3333.
1.
. - 4. ,
4 , (. 5.18, ).
m - ,
1111 mmmm.
,
,
.
2.
,
1 . .
1
(. 5.18, ). ,
< 10.
180
5.
(
a=(I,l,l,
1,1,1,1,1,1,1)
i=l,m,l
a[l] = i
J=b"^i
/
a(n)
/
/
a[21=j
k=l,m,l
a[3] = k
n=I,m,I
a[4] = n
a(4)
/
/
. 5.18. :
-
;-- ^
Program ex;
Const
a:array[L, 10] ofbyte^d
Fbr Im^n:integer;
7,7,7,7,7,7,7,7,7;;
181
I.
Begin
ReadLn(ri,m);
while aflj<m+l do { }
begin
for i:=] to n do Write(a[i]); ( }
WriteC ;
a[n]:=afnj+l; { 1 }
for i:=n downto 2 { }
ifa[i]>m then
begin
afij:=l;
a[i'l]:^a[i'l]+l:
end;
end
End
,
.
,
,
.
, ,
,
.
5.18. . ,
m (m>3)
mxm , .
.
, ,
- * . ,
, .
,
- ,
12 3 4
(. 5.19).
*
,
. j
*
(=:0> 1 3 I 1 4 | 2 | i,
*
12 3 4
,
*
.
,
. 5.19.
,
:
182
5.
pole[j] = poIe[i] - ;
I Pol^LJ] " pole[i] I =1 j - i I - .
,
,
.
.
, .
, .
:
.
: true - , false -
. -
pole.
. ,
.
Program ex;
Type p=arrayfl.. 100] of integer;
Var pole.'p;
i,m: integer;
{ }
Function newj-(m:integer;pole:p).boolean;
Var iJ: integer;
Begin
new_r:=false;
for i:=I to m-J do
forj:=i+l to m do
if(pole[i]='polelj]) or(abs(polelj]'pole[i])==j'i) then exit;
new_r:-true;
End;
{ }
Function Variantfm:integer; Var pole:p):boolean;
Var i: integer;
Begin
polefmJ:=pole[mJ+I;
{
}
for i:=m downto 2 do
{ }
if pole [i] > m then
begin pole[i]:=l;
polefi'l]: =^polefi'IJ+1;
end;
183
I.
ifpoIefJJ <= then { }
Variant: =true
else Variant:'='false;
End;
{ }
Begin
WritelnC ');
ReadLn(m);
for i:=l to m dopole[i]:=l;
{ }
repeat
if Newr(m,pole) then
{ }
begin
for i:=l to m do Write(pole[i]:2);
Writein;
end;
until not Variant(m,pole); { ,
}
End
, ,
, 0("^).
, .
,
m .
. 4x4.
,
]..., 2...,3...,4....
. 4
:
11..,
21..,
31..,
41..,
,
: 11.., 12.., 21.., 22.., 23.., 32.., 33.., 34.., 43.., 44..
,
.
184
5,
. 5.20.
, .
.
. 5.20 m = 4
. -
2413.
. 5.21 , 1^
ferz
new_r,
.
Program ex;
Type p=arrayfl.. lOOJ of integer;
Varpole:p;
km: integer;
{ }
Function new_r(n:integer;poIe:p):boolean;
Varj:integer;
Begin
newjr:-false;
for j:-l to n-1 do
if (pole lj]'='pole[n])or(abs(pole[j]-pole[n])=n-j) then exit;
newJ*:-true;
End;
{ }
Procedure ferz(n,m:integer; varpole:p);
Var i: integer;
185
1.
C
(
/
newr "\
(n,pole) J
V(n,m,pole)y
new r=true
LJZJ
ferz
(l,m,poIe)
. 5.21. {),
()
{)
Begin
ifn=m+I then { m , }
begin
for i:=J to m do Write (pole[ij: 2);
WriteLn;
end
else
{ - }
for i:=I to m do {m }
begin
pole[nJ:=i; { - }
if new_r(n,pole)
{ }
thenferz(n'^l,m,pole); {
}
end;
End;
{ }
Begin
WriteLn('Beedume : *);
ReadLn(m);
186
5.
5.1
, ,
4x4
44 = 256
17
5x5
55 = 3125
54
10
6x6
66 = 46656
153
7x7
V = 823543
552
40
8x8
88=16777216
2057
92
:=0;
ferz(hmypole);
End,
new_r
( - ).
ferz . m
( ).
,
, . 5.1.
I. ,
. ,
.
,
.
2. ,
,
, .
187
6. ,
(
), , , : , ,
CD , -.
, , ,
.. Borland Pascal
MS DOS.
6.1. MS DOS
, .
MS DOS :
;
,
;
a-z, A-Z,
, , _
$;
,
, : PRN, CON, NUL, COMI, COM2, AUX, LPT1, LPT2,
LPT3.
Windows
, ,
.
Borland Pascal MS DOS.
, .
.
188
6. .
,
, :
, ~ ( );
PAS, BAS, -
, C++ .
* ?, *
, ? - , :
* - ;
*. - ;
??. PAS - PAS, ,
;
PRG1.* - PRG1;
*.* - .
MS DOS ,
().
.
, ,
.
, (
).
, .
,
.
, , .
, .. (),
. ,
(. 6.1).
. , ,
, .
,
,
. , ,
, .
.
\,
\,
. :
189
. 6.1.
\katl\kat3\
,
. :
c:\katl\ kat3\file5.dat
. ,
.
6.2. Borland Pascal
Borland Pascal
, : , ,
. .
,
. .
, ,
.
.
, ,
. -
. , 190
6. .
, ,
, .
- , -
, ,
.
, ,
.
-, ,
. . , :
CON - : , ;
1 - ;
NUL - ,
.
- ,
,
- .
.
(. 6.2).
Borland Pascal
,
,
(. 6.3).
.
< > =
Jile /< >;...
< > - , .
. 6.2.
191
I.
r&i
~*/^|1text
. 6.3.
< >
,
/
(, ..).
- :
< > = text;...
,
.
:
< >
=/ile;...
.
Borland Pascal,
, :
Var
:
FF =file of integer;
VarFLFF;.,.
. ,
-, :
FF ^file of integer;
Procedure Print (Var F1:FF);...
192
6. ,
:
-
;
-
/;
- -;
(
).
.
( )
.
Assign (Var f; sUstring) -
f, ,
St.
,
.
, :
FI1 = text;
Var flfifi:
FIl;
1.
Var f: file of char;
Begin
Assign(f, *a. dat * ) ; { }
{$ I'} { -}
ReSet (f); { }
{$ /+/ { }
iflOResult then WriteLn (' *);
else WriteLn('0awi *);...
2. ReWrite(VarJ) - ,
f, .
. ,
( ~ ).
.
3. AppEnd(Var fiiext) - ,
f, .
, , , , ,
.
,
:
INPUT - ;
OUTPUT - .
,
-. -
(. 2.6).
.
MS DOS
. - .
.
. ,
MS DOS,
< , -
> .
.
:
A:\>example.exe <a.dat >a.res - a.dat, a.rez.
194
. .
, crt
(. 8.1), - ,
.
.
- .
:
- ;
- ,
;
.
-
(. 6.3 - 6.5).
. , ,
Close(VarJ).
.
,
, , .
.
,
Assign
.
.
MS DOS Borland Pascal
,
.
1. ReName(Varf; name:string) -
, f.
name.
, ,
. -
.
2. Erase(Var J) -
.
, .
3. EOF(Var J):boolean - .
, .
.
TRUE, (
). , , ,
, , .
FALSE, .
195
1.
, EOF -
. ,
. EOF
TRUE, , .
, EOF .
ASCII 26 (#26).
CTRL-Z. ,
, , ,
, .
PI 2 | |
. 6.4.
196
6. .
, -
ASCII #13, #10. 13
, 10 -
. ,
ENTER.
,
(. 6.2). , ,
.
, ,
, ,
.
: , , .
.
,
,
, Borland Pascal.
.
1. EOLn( [Var J]): boolean - TRUE,
;
INPUT,
.
, EOLn, EOF, -
. ,
.
EOLN TRUE, #13.
EOLN TRUE,
#13.
L
STRING
,
,
. ,
, . Read
(. 2.6). , Read
,
, .
Read ,
, .
.
, -.
, ,
.
Read ReadLn
.
,
ENTER 127 ,
.
3. ReadLn( [Var f;] vl,v2, ,..,vn ) -
, . ,
Read,
,
ReadLn Read .
,
.
Read ReadLn
.
INPUT. ReadLn
Read .
Read
, ..
ENTER,
.
4. Write( [Var /] v7,v2, ...,vn ) -
.
- CHAR,
STRING, BOOLEAN, .
.
OUTPUT, .
198
6. .
:
<> [: <1> [: < 2> ]],
<1> <2> ,
2.6.
5. WriteLn( [Var /;] vl,v2, ...,vn ) ~
.
OUTPUT, .
Write,
, #13 #10.
WriteLn ,
(
).
6. SeekEOLn( [Var /] ):boolean -
TRUE .
, INPUT.
7. SeekEOF( [Var /]):boolean - ,
TRUE .
,
INPUT
.
6.1. ,
26 ,
, :
DDDDDDDDDDDDDDDDDDDDD
..
Program formjextjile;
Var
fitext;
{ }
:char; n,i:integer; fname,st:string[30];
Begin
WriteLnC '); ReadLn(fiiame);
Assign(f/name);
{ }
ReWrite(f);
{ }
Randomize;
{ }
199
1.
for :='' to 'Z' do
begin
{ }
n:=Random(30)+l:
for i:=l to n do st:=st+a:
WriteLn(fySt); { }
WriteLn{st);
{ - }
end;
Close(f); { }
End,
,
(, ).
, ,
. ,
, ,
, .
, - ,
, .
6.2. ,
: , , ,
.
, ,
.
Program ex;
VarflJ2:text;
{ }
st.name: string;
Begin
WriteLnC :'); ReadLn(name);
Assign(fl,name); { }
{$!'}
{ }
Reset(fl);
{$
ifIOResult=0 then { }
begin
Assign(f2/temp.dat');
{ }
Rewrite(f2);
{ }
while not EOF(fl) do { }
begin
if SeekEOLn(fl) then ReadLn(flySt) { ,
}
200
6. .
else
begin
ReadLn(fl,st);
{ }
WriteLn(f2,st); { }
end;
end;
Close(fl);
{ }
Close(f2); { }
Erase(fl);
{ }
ReName(f2,name); { }
end
else WnteLn('0au/i .
*);
End
1. , ,
, . ,
,
, , #.
.
2. ,
. .
.
,
.
6.4.
- , ,
(. 6.5).
()
0. ,
,
.
1 2
. 6.5.
201
1.
.
1. Read(Var /; 1, 2, ...,) -
.
, ,
. ,
-.
2. Write(Var f; cly 2 ...) -
.
, , .
3. Seek(Var f; numcomp:word) ~
numcomp.
4. FileSize(Var f):longint -
, .
Seek():
Seek(f, 512);,.,
5. FilePos(Var fi.iongint-
, -
.
, 0.
. ,
. , ,
,
.
.
(
), .
: ,
,
, , ,
, .
.
6.3. , ,
, .
, ,
( ),
.
202
6. .
Program ex;
Varfyflifile of char; { }
chyVchar;
j:longint;
name:strmg[8];
Begin
WriteLnC : *); ReadLn(name);
{ }
Asslgn(f, name-^\dat^); { }
ReWrite(f);
{ ()}
WriteLnC CTRL-Z:');
{ }
while not EOF do { CTRL-Z }
begin
ReadLn(ch); { }
Write(fyCh); { }
end;
WriteLn;
{ }
ReSet(P;
{ }
while not EOF(/) do
{ }
begin
Read(f,ch);
{ }
Write(cK ' ');
{ }
end;
WriteLn;
{ }
ReSet(f);
{ }
while not EOF(f) do
{ }
begin
Read(f,i);
{ }
Write(i,' ');
{ }
i:=chr(ord(i)+10); { }
WriteLn(i);
{ }
Seek(fyFUePos(f)'l); { }
Write(fyi);
{ }
end;
WriteLn;
{ }
ReSet(f);
{ }
/=0;
{ 0}
while not EOF(f) do
{ }
begin
203
I,
Read(fJ); { }
Write(i);
{ }
Seek(fyFileSize(f)-FilePos(f)); {
}
Read(fyi); { }
Wnte(i);
{ }
j:=j+l:
{ }
Seek(fJ); {
}
end;
WriteLn;
WriteLnC : *); ReadLn(ch);
{ :
}
Close(f);
{ }
ReName(fyname-^\bak^); { }
ReSet(f);
{ }
Assign(fl,name+\dat');
{ }
ReWrite(fl);
{ }
{ - }
while not EOF(f) do
begin
Read(fyi);
{ }
ifioch
then Write(fJ,i); { ,
}
end;
Erase(f);
{ ,
, }
{ }
ReSet(fl);
{ }
while not EOF(fl) do
begin
Read(flyCh); { }
Write(ch ' ');
end;
WriteLn;
End
6.4. , ,
.
.
204
6. .
Program ex;
Type fam=record
{ }
ff:string[20]; {}
year:word;
{ }
month:L.12;
{ }
day:L,31
{ }
end;
Varf:file offam; { }
jbifam:
J: integer;
fffistring;
key;boolean;
Begin
Assign(f,'(udat'); { }
ReWrite(J);
{ }
WriteLnC CTRL-Z);
while not EOF do {, CTRL-Z}
begin
ReadLn(/b.ff, fb.year, fb.month, fb.day); { ,
,
Enter}
Write(fjb); { }
end;
Close(f);
{ }
WriteLnC ');
Readln(ffJ);
key;=false;
{ }
ReSet(f);
{ }
while (not EOF(f)) and (not key) do {
}
begin
Read(fjb);
{ }
iffbjf^fffthen
{ , }
begin { }
WriteLnCJlama: \fb.year,fb. month; 3,fb. day;3);
key;=true; { }
end;
end;
if not key then
{ }
WriteLn('Hem ) ; { }
Close(f); { }
end,
205
I.
,
CHAR.
,
#13
#10.
6.5. ,
CHAR .
Program charjextjile;
Type ff=file of char; { - }
Var
/
{ }
a:char;
n,i: integer;
Jhame,st:string[30];
Begin
WriteLn('Beedume ');
ReadLn(fname);
Assign(ffname);
{ }
ReSet(f); { }
while not EOF(f) do { }
begin
St-'';
Read(f^a);
{ }
while (#13) and not EOF(f) do {
}
begin
st:='st+a; { }
Read(f,a);
{ }
end;
if not EOF(f) then Read(f,a); { #10}
WriteLn(st);
{ }
end;
Closeif);
End
1. , ,
: ,
, , .
, (
), .
, .
206
6, .
2. ,
-50 +120,
( 1 100),
.
.
3. .
, .
, .
.
6.5.
,
.
.
, /
.
, ,
.
,
ReSet Re Write.
recsize
. , 128 :
ReSet (Var f; [recsize:word\);
ReWrite(Var f; [recsize:word ] /
recsize - , 65535
.
, (512 ),
: 1024,2048.
,
, Read Write.
BlockRead BlockWrite.
1. BlockRead(Var f:file;Var buf; CounCword [;res:word] ) .
buf ,
. Count
ReSet .
207
L
res
. - , ..
, res ,
2, BlockWrite(Var fifile; Var buf; Count:word [;res:word\) buf .
6.6, .
, ,
.
1, 2048 .
.
Program copir;
Const recs=1024; { }
Var y7,yi7.y/fe;{ }
buf: array [L.2*recs] of byte;
{ 2048 }
i:word;
namein,nameout: string;
Begin
WriteLnC - :');
ReadLn(namein);
{ }
Assign(fiynamein);
{$
ReSet(fiyl); { }
{$!+}
iflOResulto
then
begin
WriteLn(#7,' \namein);
Halt
end;
WriteLn - ');
ReadLn(nameout);
Assign(fo,nameout);
ReWrite(fOyl); { }
while not EOF(fi) do
begin
BlockRead(ft,buf,sizeof(buf),i);{ }
BlockWrite(fo,bufi);{ }
end;
Close(fi);
Close(fo)
End
208
6. .
6.6. DOS
Borland Pascal
MS DOS,
.
Dos Uses Dos,
, .
Dos
.
1. DiskFree((lrive:byte):LongInt-
drive . drive
: - , 1 - , 2 - ..
2. DiskSize(drive:byte):LongInt -
. drive ,
.
3. GetFTime(Var f; Var time:LongInt) -
f.
, .
4. UnPackTime (time:LongInt; Var DT:DateTime) -
time,
, DateTime, Dos
:
DateTime = record
year:
word; {}
month: word; {: 1..12}
day:
word;
{: 1..31}
hair:
word; {: 0..23}
min:
word;
{: 0..59}
sec:
word;
{: 0..59}
end;
5. PackTime(DT:DateTime;Var time:LongInt) -
DT DateTime time.
6. SetFTime(Varf; time:LongInt) -
; time -
.
7. GetFAttr (Varf; Var Attnword) -
, .
( , , ..)
.
. Attr.
209
1.
Dos
1 :
Const
Readonly
Hidden
Sysfile
VolumelD
Directory
Archive
Anyfile
= $01:
= $02;
= $04;
= $08;
= $10;
= $20;
= $3F;
{ }
{ }
{ }
{ }
{ }
{ }
{ }
, ,
, :
GetFAttr(fMrF);
if Lo(AttrF) && Readonly oO then
WriteLn('0am '' '**);
8. SetFAttr(Var f; Attr:word) -
.
9. FSearch(path:PathStr; DirList:s(rlng):PathStr -
, path,
;
;. , .
\0. FSpllt(patlt:PathStr; Var DinDlrStr; Var name:NameStr;
Var Ext:ExtStr) - , path,
. . dir, name
ext.
.
11. FExpand(path:PathSrt):PathStr -
. ,
.
6.7. ,
Dos :
;
;
.
Program fundos; { dos}
Uses dos,crt;
Var fiJo:text;
{ }
, i:word;
tinte,size:longint;
date:DateTime;
patltf:DirStr;
namef:NameStr;
extfiExtStr;
atribyte; { }
name:string;
210
6. .
Begin
ClrScr;
WriteLnf' :');
ReadLn(name);
Assign(fhname);
{$!-} ReSet(ft);{$!+} { name}
iflOResulto
Othen
begin
WriteLn(#7, * \namej;
Halt;
end;
GeiFTime(fiyiime);
{ }
UnPackTifne(time,date); { }
WriteLn(^ama = \date.year:5,date.month:3, date,day:3);
WriteLnC = \dateMour:3,date,min:3ydate.sec:3);
with date do
begin year:=200J; month: =3; day: =8
end;
PackTime(date,tinte); { }
SetFTime(fi,time); { }
WriteLn(*oce : ');
WriteLn('dama = \date,year:5,date,month:3,date.day:3);
WriteLn(*pe =\date.hour:3,date,min:3,date,sec:3);
FSplit(nameypathf,namef,extJ); { }
WriteLn(*ooe =\pathf:25,namef:J2,extf:8);
GetFAttr(ft,k);
{ }
atr:=lo(k);
WriteLnC \atr);
size: =DiskFree(l);
WriteLn(*Ceo6odHoe \size:10, * ');
Close(fi);
End
:
:
c:\iva\primer.pas\file\primer.txt
= 2001 3 7
= 10 47 22
= 2001 3 8
= 10 47 22
= c:\iva\primer.pas\file\
32
9104
primer .txt
211
?
,
. ,
,
. ,
, ,
, . ,
.
, , .
,
. Borland Pascal
, ,
, .
,
, .
MS DOS.
7.1.
,
Intel ,
. ,
.
, .
, .
2 , ~ 4 , - 16 .
+
(. 7.1).
5 ( ) +
AQ^ (),
212
7.
Intel
( i8086)
, 16. 0 1 2 3 4 5
,
,
.
. 7.1.
,
+
64
, 16 (0,16,32, ), .
.
.
16 ().
,
(. 7.2), 20 2^^
1 .
2^^-1, 64 .
, 64
, .
.
, Pascal,
Windows, + .
,
. : ,
. .
.
:
,
, -, -
- .. (.
5.6).
:
16
CS - ;
DS - ;
SS - .
0000
20
. 7.2.
213
1.
(. 7.3).
Borland Pascal
-
.
word
. 7.3.
.
: .
,
.
, ,
.
. 7.4.
:
tpi=4nteget;
Varpi.tpi;
{ }
{ }
:
Varpi: ^integer; { }
,
.
pointer. :
Var:pointer;...
- ,
.
:
= ^;
{ person !}
= record
{ person}
: string:
next: ;
end;...
-<
. 7.4.
<
>
214
,
,
nil. nil
.
.
,
7.
,
- nil. :
Constp:^real=nil;...
.
.
,
nil.
.
:
Var
1, 2: ^integer;
: ^real;
: pointer;
{ }
pJ:=p2; :=; 1:=; pl:=nil; :=;
( }
:=2; pJ:=p3;,..
. ,
- @ ( ) -
. - pointer,
.
:
Var i.integer;
pi: ^integer;...
pi:=@i; { pi i}
( ).
, '^.
, .
.
:
j:=pi^; {] ,
pi}
pi^:=pi^-^2; { , pi,
2}
. 7.1 , .
215
1.
1
pi
Const i:integer=];
Var pi: ^integer;
1
1
?
1 ^ 1
i
pi
pi
\1
pi:=@i;
N'1
pi^:^pi^j^2;
pi
i
1 1
pi
\1
\ .
,
pi, 2
1 3 1
pi:-nil;
pi
0 1
\|
pi
I ^1
.
(=) (< >).
.
:
sign:=pl=p2; { sign
true false }
ifplonil
then ... { }
,
. , ppi
:
216
7.
Const i:integer^ 1;
Var pi: integer;
ppi: ""pi;
ppi
\
\
pi
pi:=@i;
ppi:=@pi; ...
\
\
i
1
. 7.5.
TO ,
. 7.5.
i
. ppi^^
integer 1.
, .
,
.
1. ADDR(x): pointer - ,
, , .
, @.
2. SEG(x): word -
.
3. OFS(x): word- .
4. CSEG: word-
CS - .
5. DSEG: word-
DS - .
6. PTR(seg,ofs:word):pointer -
seg ofs.
. ,
, .
,
.
.
,
,
.
:
Var L:longint;
{ }
1:^[1..4] of byte; { 4 }
k:byte;
217
J.
Begin
1:423456789;
P1:=@L; { @ }
:^1^[1]: { L,
,
}
,
, ,
.
7.2.
.
~ .
,
. ,
200 ... 300 , . 7.6.
(GooTBeTCTBeHHO, ,
.)
Borland Pascal,
:
HeapOrg - ;
HeapEnd - ;
HeapPtr - !0^
.
, .
1. New (Var < >) -
-.
.
. 7.6.
218
7.
:
Varpi: ^integer; ...
New(pi); { pi ,
}
2. New (<^ >^;/7<?/^~
.
.
:
tpi: ^integer;
Varpi:tpi; ...
pi:- New(tpi); {pi ,
}
New, New.
3. Dispose ('< >^ -
, .
:
Dispose(pi);...
,
nil, , .
New Dispose
-
.
:
, -
.
.
4. / (Varp:pointer)- HeapPtr
, .
5. UpoiXQjxypa. Release (Var p:pointer) -
, , Mark.
:
new(pl);
new(p2);
mark(p);
new(p3);
219
J.
new(p4);
release(p);.,.
. Dispose Release ,
Release ,
Dispose.
,
.
6. GetMem (Var p:pointer; size:word) -
, size (
64),
pointer . ,
,
, .
7. SizeOf(x): word-
.
8. FreeMem (p:pointer; size:word) -
, GetMem.
,
, ,
.
.
.
.
9. Maxavail: longint ~
.
10. Memavail: longint -
- .
.
,
, ,
Heapfunc:=l, :
Function HeapFuncfsize: word) : integer; far;
begin HeapFunc: =7; end;
, HeapFunc:
HeapError:=@HeapFunc; ...
,
New GetMem ,
220
7.
nil, .
,
.
7.1.
( < 10000, m < 10000, nxm ^ 50000).
nxm (real)
= 300000 , 64 , ,
.
nxm,
4xnxm = 200000 , 64 .
ptrstr ( ),
-
(. 7.7).
64000/4 =
= 16000 . ^
, 64000/6 = 10677
real, .. , .
, ,
(1^).
.
1, j .
, - Seg(ptrstr[i]), ,
,
- Ofs(ptrstr[i]), j-1
- (j-l)xSizeOf(real).
-,
^eal.
I I
I I
JiL
I IZI
I I ZE
hid
>!
. 7.7.
221
1.
Program exjargejnas;
Const =76000; { }
Var iJ,n,m:word; s.real;
ptrstr: array[L.nn] of pointer; {
}
tpreal=^real;
{ }
Function AddrR(iJ :word) :tpreal:
begin
AddrR: =Ptr(Seg(ptrstr[i]''), OfsfptrstrfiJ'^)+(/-1) *SizeOf(real))
end;
{ }
function heapfunc(size:word):integer; far;
begin heapfunc:^!; end;
{ }
begin
Randomize;
heaperror:=@heapfunc; {
}
WriteLnC ,');
ReadLn(n,m);
for i;=] to do
begin
GetMem(ptrstrfiJ,m*sizeof(real));{
}
ifptrstr[ij=nil then
{ ,}
begin
{ }
WriteLnC ^,');
forj:'==l to i'l do
FreeMem(ptrstr[j]ym*sizeof(real)); {
}
Halt(2);
end;
forj:=l to m do AddrR(iJ)\'=Random; { ,
}
end;
s;=0;
for i;==I to n do forj:=l to m do s:=s + AddrR(ij)^;
WriteLn('3Ha4eHue =\s;15:10);
WriteLn(VpedHee =\s/(n*m):]5:J0);
for i:=] to n do FreeMem(ptrstr[iJ,m*SizeOf(real)); {
}
End
222
7.
7.3.
,
,
.
,
.
. :
,
(. 7.8, );
, ,
- (. 7.8, );
,
, (. 7.8, ).
()
(. 7.8, ).
(. 7.8, ).
, , , ,
. -
"l
J^
"
^1 ^ ^ 3
^4
. 7.8. :
- ; - ; - ; - ; -
223
I.
, (
) .
,
. : ,
, ,
.
:
-
, ,
nil (. 7.9, )\
-
,
(. 7.9, );
" ^
^^^^
I3HIIB*C
. 7.9. :
- ; 5- ;
- ; - ; - -
224
7.
-
, ^
, -
nil (. 7.9, );
-
,
,
- (. 7.9, );
' -
, nil (. 7.9, ).
, ,
:
= ^element;
{ }
element = record
name: string[16]; { 1}
telefon:string[7]; { 2}
: ;
{ }
end;
,
:
= ^element;
{ }
element = record
name: stringfldj; { 1}
telefon:string[7]; { 2}
prev: ;
{ }
next: ;
{ }
end;
-
.
,
,
)^ nil, .
, , ,
, ..
, :
Varfirst, last, q: ;...
, .
225
1.
.
7.4.
, ,
:
,
;
,
.
,
,
.
.
,
.
.
:
tpel=^element; { }
element^record
num:mteger; {}
p:tpel;
{ }
end;
-
-,
:
Varfirst,
{ - }
n,f,q:tpel; { }
:
first :^ml;
.
.
.
:
226
7.
,
;
;
( )
;
.
,
nil:
new(first);
first ^.:=5;
first \:^;
{ }
{ }
{ nil }
. 7.10
.
.
,
(. 7.11):
new(q);
{ }
q^.num:=4; { }
q\p:=first; {
}
first: =q; ... { }
( ).
,
,
first
first
first:-nil:
first
I
I I
\ new(first):
= ^
first
\ S \ I
%
^ =5;
first :
I 5 101
"%
first ; =//;
. 7.10.
:
- ; - ;
- ; - nil
227
I.
first
1=^
first
to
new(q);
q\ : =4;
first
first
q\p:=^first;
. 7.11.
:
- ; - ; - ;
, -
(. 7.12). f- ,
- , :
new(q):
{ }
q\num:=3; { }
q\p:='n;
{
}
f".p:^q;
... {
}
,
-
f^.p:
new(q);
q\num:=3;
q\p:=f\p;
f^.p:=q;
228
{ }
{ }
{
}
... {
}
7.
first
first
JL
8~rg1
q
Dn34ZI34 8T0I
first
1XEEW3IEHX1S)
q^.num:=3;
I 3 I
.=;
T O
first
f^-p-q:
. 7.12. ( ):
- ; - ;
- ; , -
.
, (. 7.13):
new(q):
q\num:=7;
q\p:=nil;
f^.p:=q;...
{ }
{ }
{ nil}
{
}
229
1.
first
first
'
801
new(q);
first
I I
q mwi: = 7;
L~i-JI
//?; =^;
first
ixr34zi3bzz
^;?; ==//;
. 7.13. :
- ; ~ ;
- ; .-
, ,
nil:
new(q);
{ }
q^Mum:=7; { }
q^.p:=f^.p; {
nil}
f^.p:=q; ... {
}
230
7.
,
.
7.2, ,
, . ,
. - CTRL-Z (
).
:
,
:
ReadLn(a);
new(first);
{ }
first \:=;
{ }
first \:=;
{ nil , }
while not EOF do
begin
ReadLn(a);
new(q);
{ }
q\num:-a;
{ }
q^.p:-first; {
}
first:=q; { }
end; ...
7.3. ,
, .
, . - CTRL-Z (
).
,
, , nil
:
ReadLn(a);
new(first);
first \:=;
f:=first;
{ }
{ }
{f - ,
}
1.
f\p:=q;
f:-f\p;
end;
q\p:=nil;
{
}
{ }
(
nil}
, ,
:
ReadLn(a);
new(first);
first ^.:=;
f:-first;
{ }
{ }
{f- ,
}
7.
begin
{ }
q\p:=first;
firsU-q;
end
else
( }
begin
n:-first;
{ }
f:-first;
{ }
flag:^false;
{" "}
{ }
while (n\ponil)
and (not flag) do
begin
n:=n\p; { }
if q^,num<n\num then { }
begin
{ }
q\p:^f\p;
f''>p:^q;
y7ag;=/rwe; {" "}
end
elsef:-n;
{ }
end;
if not flag then { , }
begin
{ }
q\p:-nil;
f\p:^q;
end;
end;
end;
.
:
f:-=first;
while fonil do
begin
< f>
end;
...
:
233
I.
f:=first;
while fonil do
begin
WriteLn(f\num, * *);
end; ...
.
, , ,
, ,
, :
fi^flrst;
flag:--false;
while (fonil) and (not flag) do
begin
iff \num=k then flag:^notflag
elsef:^f\p;
end;
if flag then < >
else < >; ...
.
:
;
( ) ;
, ;
.
.
,
,
, nil first (. 7.14):
first
^
234
first
'
'
first
[1]
Dispose(first);
first:^nil; ...
*
( Disposefflrst); first: ^; ) .
"^
. 7.14.
f, :
- ; -
; - nil
(. 7.15):
7.
first
rJL
f:^firsi\p;
first
iiiM
- ,1
first
TT0l
Dispose(first):
e
0
first: =/
. 7.15. ( )
:
- ; -
; - ; -
f:='first\p;
( }
Dispose(first); { }
first:"=/; ...
(
}
:
qfirst;
first :=first\p;
Dispose(q);...
, ( ).
, ,
,
(. 7.16).
n:=f^,p;
f^,p:=n\p;
( }
(
}
Dispose(n); ... ( }
235
L
first
first
.
,
nil:
n:=f^p;
f\p:=nil;
Dispose(); ...
n-.^f'^.p;
,
first
f
n
,
nil.
9";?80]
,
f\p:=n\p;
.
7.5.
first
f
,
7TT]
"801 .
Dispose(n);
, ,
. 7.16. ,
,
( ):
:
- ; -
; -
; -
-
;
-
.
, true, ,
- false.
n.-'^Jirst;
nft:=true;
{ }
repeat
ifn^.num<kthen
begin
236
7.
ifnft then { }
begin { }
q:^firsi;
first:=first^.p;
Dispose(q);
n:-first; { }
end
else
{}
begin
{ }
q:^n;
:-\; { }
188(;
f\p:^n;
end
end
else { }
begin
f:-n;
{ }
:-\;
{ }
nft:='not nft { }
end;
until n-nil;...
{ }
1. ,
#, ,
.
.
2. ,
#, :
XI + ^; 2 + Xj,.,; + .2; ... ^ + ,.
, .
3. ,
. . . ,
, . . .
.
, .
237
L
7.5.
()
, ,
,
.
,
.
, - . ,
, ,
, - . ,
, (. 7.17).
-
. ,
.
.
, .
:
, .
.
, :
, ,
-
.
.
. 7.17.
238
7.
.
:
topjptr-^top;
{ }
top=recorci
value:integer; {}
left,
{ }
right:top_ptr; { }
end;
, :
Var root,
{ - }
pass, next, q:topjptr; { }
- :
root:=nil;
.
. , {5, 2, 8, 7, 2, 9,
1, 5}. 5 (. 7.18, ).
2 , ,
(. 7.18, ). 8
, (. 7.18, ).
7 , , ,
, .
7 - 8.
, -
5
i2)
. 7.18. :
( - ) ()
239
I.
(. 7.18, ).
. 7.18, .
, ,
: , ,
, , , ,
:
{ }
new(q); { }
with q^ do { }
begin value:=;
left:=nil;
right:=nil;
end;
{ }
pass:=root;
{ }
while passonil do { }
begin next:=pass; { -}
if q\value<pass^.value then pass: =pass\left
{}
elsepass:^pass^,right; {}
end;
{ }
if q\value<next\value then
{ }
next\left:=q
{ }
else next^.right:=q;
{ }
^ ,
.
.
Procedure Add(Var r:top_ptr; pass:top_ptr);
begin
ifr=nil then r:=pass { , }
else { }
if (pass\ value<r\value) then Add(r\ left,pass)
else Add(r^.right,pass);
end;...
.
:
.
, ,
. - .
, . , 240
7.
7
(. 7.19).
,
,
.
( )
:
^ ^.^
'^"'-li'l "P""!L!!f'^ "
pass:^root;
flag:=false;
while (passonil)
{ }
{ }
and not flag do {
}
ifn=pass^.value thenflag:^'true { }
else
ifn<pass\value then pass:-pass\left
{}
else pass:-pass\right; {}
(/[;7ag rAew < >
else < > ...
, .
,
true, , false ~ .
pass:
Function Find(r:topj>tr; Varpass:topj)tr; n:integer):boolean;
Begin
ifr^nil then Find:=fiilse { }
else
ifn=r^.value then
begin
Find:-true; { }
pass:=r;
{ }
end
else
ifn<r^.value then
Find:^Find(r^Jefl,n) {}
else Find: =Find(r^.right,n); {}
End;
, :
241
1.
. 7.20. :
- ; -
. 7.21. :
-> ; -
242
7.
. 7.22. :
- - ;
- ;
-
L
if k<r\value
then
{ , }
Delete(r\lefUk)
else
ifk>r^.value then
{ , }
Delete(r\right,k)
else
begin { , }
{ }
ifr\right=nil then { }
begin
r:=r\left;
188(;
end
else
ifr\left=nil
begin
then { }
r:=r\ right;
188(;
end
else { }
del(r^Jeft,r);
end
End;...
.
,
.
, , .
:
, ,
.. (. 7.23).
7.6.
.
,
. 7.23.
.
244
7.
,
.
, ,
.
.
,
.
.
Program Sort4;
Type topjptr^^top; { " "}
top=record
{ )
value:integer;
{ }
left, right:top_ptr; { }
end;
Var next number: integer;
n pass:topj)tr;
{ }
{ }
Procedure AddfVar r:top_ptr; pass: top_ptr);
begin
ifr=nil then r:=pass { , }
else { }
if (pass\value<r\value) then Add(r^.left,pass)
else Add(r\right,pass);
end;
{ - }
procedure Tree(r:top_ptr);
begin
ifronilthen
begin { }
Tree(r\left);
{ }
Write (revalue: 4); { }
Tree(r\right);
{ }
end;
end;
{ }
begin
{ }
WriteLnC ');
:=;
Read(nextjiumber);
while not EOF do
245
L
begin
new (pass); { }
withpass^do { }
begin
value: -nextjiumber;
left: =nil;
right: ==nil;
end;
Add(r, pass); { }
Readfnextjiumber)
end;
ReadLn;
WnteLnCCopmupoeaHuan :);
Tree(r);
End
.
.
.
.
,
(. 7.24, , ),
(+1)/2 , , , ,
{\),
(. 7.24, ). (Iog2 4-1)/2 ,
. . Ocp(Iog2 ).
.
, ,
, ,
. : -1 , 1 - (
. 7.24. :
, - ; -
246
7.
). [(-1)+1]/2 ;
-1 , (-1)/2 , OyivP-),
.
(log2 (-1 )+1)/2;
, (-1), 0^p(nlog2 ).
. ,
, .. 2. ,
0().
0^,( Iog2 ).
1. ,
: ,
, , , , , .
,
(. 4.6),
10, 100, 1000 .
2.
, 300 .
, .
7.6. .
,
, ,
, ,
, (
, ..).
,
.
, . ,
,
(+1,5)(-10)(+5)/(.)
, . 7.25
( ^).
247
I.
\^ v^ v^ ^ \^
@000
. 7.25.
:
) , ,
,
( ,
);
) , :
,
;
)
..
,
,
.
: ,
, , .
:
- ,
,
- ,
, - ,
.
,
, ,
sin X In X. ,
,
.
. 7.26.
(x+l,5)*cos(2*x+5), ,
,
,
.
7.26.
248
7.
7.7.
, . (
,
.)
,
:
, - ,
:
- -- .
Constr_Tree
:
.
: ,
.
: ,
.
, Set_Of st.
Count.
. ,
, ,
.., ; Count
Key=false.
Program ex;
Type setChar=set of char; { }
str80=strmg[80]; { 80 }
='^;
{ }
Top=record
{ }
operator:string[5];
{ }
value:single;
{ }
lefUrighUpTop; { }
end;
Var st:str80;
{ - }
Root:pTop;
{ }
:1; { }
x,xn,xe,dx,y:single; {,
, }
n,i:word;
{ }
{
st}
Procedure Constr_Tree(r:pTop;st:str80);
Var next.'pTop; SetOp:setChar; po,code:integer;
stlstri:str80; :single;
249
1.
{ st:
SetOp - ;
0}
Function PosOp(st:str80;SetOp:setChar):byte;
Var ij,k,p:byte;
begin
j:=0;k:=0;p:=0;i:=l;
while (7<= length(st)) and (p'=0) do
begin
ifst[ij= Y* ^hen inc(j) {
}
else ifst[i]'=')' then inc(k) {
}
else ifQ'^k) and (st[i] in SetOp) thenp:=i;
inc(i):
end;
PosOp:=p;
end;
{ }
Begin
po:='PosOp(st,[*+ \'- 7' { + -}
ifpo=0 thenpo;=PosOp(st,f'*\ /']); {
* /}
ifpo=0 thenpo:=PosOp(st,f'^*J);{ '^}
ifpooO then
{ }
begin
\operator: =st[]; { }
stl:=copy(st,l,po-l);
{ }
if(stlf]J= ) and (PosOpfstlJ'"' \ V\ \'.; '^ 7>= then
stl:=copy(stl,2,length(stl)-2);
{ }
stri:=copy(st,po-^lJength(st)'poJ;
{
}
if(stri[l]= ' and (PosOpfstriJ'* \ 7\ \'-', '^'])^0) then
stri:=copy(stri,2Jength(stri)'2); { }
new(r^.left);
{ }
Constrjrree(r\left,stl);
{ }
new(r^.right);
{ }
Constr_Tree(r^,right,stri); { }
end
else
ifst[lj= '' then {}
begin
r^.operator: = 'x\'
250
7.
r4eft:=nil;
r^.right:=ml;
end
else
begin
val(st,c,code); { }
if code=0 then {}
begin
\:^';
r\left:=nil;
r\right:^nil;
r^. Value :=";
end
else
{}
begin
po:=Pos('(\st);
r^.operator:-copyfst, 1 ,pO'J); { }
r^.right:^nil;
stl:=copy(st,po+l,length(st)^pO'l);
{
}
new(r^Jeft);
Constr_Tree(r\left,sd); { }
end;
end;
end;
{ :
Key=false, }
Function Count(r:pTop;x:single;Var key:boolean):single;
Var s,sl: single;
begin
if not key then
{ }
begin
Count:=0;
exit;
end;
ifr\operator='o'
then
Count:^rWalue {}
else
if r^.operator^ 'x' then
Count: =x
{ x}
else
case r\ operator[1] of
*+ V Count:=Count(r^Jeft,x,key)'^Count(r^.right,x,key);
251
I.
'-V Count:=Count(r^Jeft,x,key) - Count(r^.nght,x,key);
'* V Count: ^Count(r^.left.x,key) *Count(r^.nght,x,key);
V begin
s: =Count(r^, rightyX, key);
ifabs(s)<le'10
then { }
begin
Count: "=0; key:=false;
end
else Count: =Count(r^Jeft,x,key)/s;
end;
'^\' begin
s: =Count(r\ left.x, key);
si: =Count(r^,nght,x,key);
ifsoO then
Count: =exp(sl *ln(abs(s)))
else
if s 1=0 then Count:=1
else Count: =0;
end;
's': Count: =sin(Count(r\left,x,key));
*cV Count: =cos(Count(r\left,x,key));
else
{ }
begin
Count:=0;
Key:=false;
end
end
end;
{ }
Begin
WriteLnC :);
ReadLn(st);
Write (' xn, xe, n: ) ;
ReadLn(xn,xe,n);
new (Root);
Constr_ Tree(RootySt);
dx:=(')/(' 1);
WritelnC X V
y);
x:=xn;
for i:=l to n do
begin
key:=true;
y: =Count(Root,x, key);
252
7.
if key then
WnteLn(x:6:3,y:20:3)
else
WriteLn(x:6:3/ ');
x:=X'^dx;
end;
End
1. ,
,
: cos, tg, ctg, ^ . .
2.
.
3. ,
.
8.
MS DOS
MS DOS .
- , .
: , ,
-,
, , -. .
-
, BIOS ( -)
MS DOS.
Borland Pascal MS DOS
, Crt,
Graph Dos.
8.1.
,
,
,
. ,
,
, .
.
.
.
, .
. Borland Pascal
, MS DOS, .. ,
25 80 .
254
8, MS DOS
[)
'
T j [
:
0
V
I
. 8.1.
,
, 2 ,
:
ASCII,
;
,
(. 8.1).
},
. i ^
1, .
. ,
, .
:
(ci ,
1) - (. 8.1).
255
1.
8.1
,
1^
0
0
0
0
0
0
()
g
()
b
()
0
0
1
1
0
1
0
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
1
0
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-
-
-
-
crt .
crt .
- .
25x80 .
, .
Write WriteLn .
:
#7 - ;
#8 - ;
#10 - (
, );
#13 - .
256
8, MS DOS
yi
25
. 8.2.
, .
(. 8.2).
crt
.
1. Window(xl, 1, 2, y2:word) - .
(1, 1) (2, 2) .
crt :
WindMiUy WindMax:
word.
, 1
hi, :
xl-Lo(WmdMin) ] =Hi(WindMin) x2-Lo(WindMax) y2==Hi(WindMax) -
;
;
;
.
.
2. TextColor(color:byte) -
.
3. TextBackGround(color:byte) -
.
TextColor TexfflackGromid ,
crt:
257
1.
Black = 0;
Blue = 1;
Green-2;
Cyan = 3;
Red-4;
Magenta = 5;
Brown = 6;
LightGrey =7;
Blink -128;
{}
{}
{}
{}
{}
{}
{}
{-}
{}
DarkGrey = 8;
{-}
LightBlue = 9;
{-}
LightGreen = 10; {-}
LightCyan = / / ;
{-}
LightRed-12;
{}
LightMagenta = 13; {}
Yellow = 14;
{}
White = 75;
{}
TextAttr:word,
8. MS DOS
:5
1 '*
'
25
!.
57
-48
34
69
- . ^:
' ^^ - :
,. s-s^^ir.
=27.2
,. ,
',<**''
. 8.3.
.
.
.
Program ex;
Uses Crt;
Var a:array[L JO] of integer;
XyClx,nJ:integer; s:real;
Begin
ClrScr;
{ }
Window(20,3,50,5); { }
TexiAitr:=16+7; { - }
ClrScr;
{ }
GotoXY(2,2);
{ }
Write(*Beedume : *); { }
ReadLn(n);
{ }
dx:^(80'(n^l)*3)divn;
:=0;
s:=0;
TextAttr:=2*I6-^14; { }
for i:=I tondo
begin :-+3;
Window(x,7^+dx,9); { }
ClrScr;
{ }
259
I.
GotoXY(2,2); { }
ReadLn(a[i]); { }
s:=s+afij;
x:=x-^dx;
end;
TextAttr:=4*16+14; { }
Window(18ylly53J3); { }
ClrScr;
{ }
GotoXY(3,2); { }
Write('CpedHee = \s/n:5:2);
ReadLn;
{ Enter}
Wmdow(l, 1,80,25); { }
TextAttr:=7;
{ }
ClrScr;
{ }
End.
8.2.
- ,
- .
/,
- ,
.
-,
.
- , ,
. .
- (<-, , ->, i .
Home, End, Tab, Page up. Page down), (Del, Backspace),
(Ins, Caps lock, Num lock, Scroollock),
(Esc, Break, Fl, F2, F3, ..., FI2) ..
.
- Shift, Ctrl Alt.
. ,
, Shift-a
.
400 ,
.
/ BIOS (
-) BIOS .
260
8. MS DOS
,
256, , ,
1 (. 2),
, .
,
ASCII, , :
, - scan- (. 3).
-
Read ReadLn, ASCII
BIOS .
.
Read ReadLn ,
, ,
, ( #13, #10).
crt ,
.
1. KeyPressed: boolean - true,
, false - BIOS ;
, ;
2. ReadKey:char - BIOS
, ,
.
ReadKey
: , - scan-:
chl:=ReadKey; { }
ifchl=#0 then ch2:=ReadKey; { =0, }
8.2.
. Esc.
Program ex;
Uses crt;
Var cl,c2:char;
Begin
repeat cl:=ReadKey;
{ }
ifcl=W then
{ }
begin
c2:=ReadKey;
{ scan-}
WriteLn(ord(cl):5, ord(c2):5) { }
end
else WriteLn(ord(cl):5)
{ ASCII}
until c7 =#27;{ Esc}
End.
261
1.
. ReadKey
BIOS
/
,
1 -
scan-, ,
1 - Caps Lock
~"2 ~
,
1 - Num Lock
.
1 - Scroll Lock
1 - Alt
BIOS
1 - Ctrl
1 - Shift |
(. 8.2),
1 - Shift | $0:$417.
Mem:array of byte, :
Mem[$0:$4J7],
;
8.2
8.3.
crt ,
.
\. Sound (f:word) - .
, :
- 330 , - 349 , 370 , 392 , 415 , 440 ,
466 , 494 , 523 , 554 , 588 , 622 , ,
- 660 . .
2. NoSound - .
3. Delay (Uword) -
, .
, Delay ,
.
, .
4. GetTime (VarHour, Minute, Second, SeclOO:word) -
. Dos.
8.3. .
.
262
8. MS DOS
Program ex;
Uses Crt;
Const f: array[L.13] of word = (330, 349, 370, 392, 415, 440,
466, 494, 523, 554, 588, 622, 660);
Var i:byte;
Begin for i:=l to 13 do
begin
Sound(f[i]);
forf^l
to 5000 do Delay(lOOO); { ?!}
NoSound;
end;
End.
,
,
GetTime:
Program ex;
Uses Crt, Dos;
Procedure NewDelay(dTime:word);
Var key:boolean;
Hour, Min, Sec, SeclOO, MyHour, MyMin, MySec, MySeclOO: Word;
Begin
GetTime(Hour, Min, Sec, Sec100); { }
{ }
MySeclOO:^SeclOO+dTime; MySec:=Sec+MySecl00 div 100;
MySeclOOc^MySeclOO mod 100;
MyMin:=Min-^MySec div 60;
MySec:=MySec mod 60;
MyHour:-Hour-^MyMin div 60; MyMin:=MyMin mod 60;
key:=false;
while not key do { }
begin
GetTime(Hour, Min, Sec, Seel00); { }
{, }
if (>) or ((=) and ((Min>MyMin) or
((Min-MyMin) and ((Sec>MySec) or
((Sec^MySec) and ((SeclOO>^MySeclOO)))))))
then key:=true;
end
End;
Const f array[L.13] of word = (330, 349, 370, 392, 415, 440,
466, 494, 523, 554, 588, 622, 660);
Var iibyte; j:integer;
263
8. - MS DOS
{ }
Const menu:array[L,4] ofwin=
((xl:5:yl:4;x2:15;y2:4;text: 'new '),
(xl:5;yl:5;x2:15;y2:5;text: 'open'),
(xl:5;yl:6;x2:15;y2:6;text: save'),
(xl:5;yl: 7;x2:15;y2:7;text: 'exit'));
{ }
Procedure DrawWin(w:win;attr:byte);
Begin
with w do
begin
TextAttr:=attr;
{ }
Window(xl,1 ,2,2); { }
Clrscr;
{ }
GotoXY(2,l);
{ }
Write(text);
{ }
end;
End;
{ npos}
Procedure DrawMenu(npos: integer);
Begin
Clrscr;
for i:=l to 4 do
ifi=npos then DrawWin(menu[i],94) { }
else Draw Win (menufij, 30);
{ }
End;
{ }
Begin
npos:=I; { }
DrawMenu(npos); { }
repeat
chl: =ReadKey; ifchl =#0 then ch2: =ReadKey;
case chl of
W: case ch2 of
#72: begin
{ }
ifnpos>l then { }
bemi
DrawWin(menu[npos],30); {
}
npos:=npos-l; { }
DrawWm(menu[npos]y94); { }
end;
end;
265
L
Begin for i:=l to 13 do
begin
Sound(f[i]):
NewDelay(50);
NoSound;
end;
End
8.4. .
,
,
.
1 (>1<, ,
-^, <-\ .
Enter.
.
Esc.
8.4. : new,
open, save, exit. ,
.
(. 8.4). exit
Esc.
:
;
.
.
25x80 MS
DOS.
Program ex;
1
5
15
8(
Uses crt;
1
Var nposJ: integer;
--!..,
4
; :'-i'f;;'; '
chlyCh2:char;
Type
open
'-^^:;: , \
win=record {
save
exit
}
7
xI,yJ,x2,y2:word; {
-;
}
'' V:-'-^^'''''25
text:string[8]; {
}
. 8.4.
end;
.W.,,,...;
264
1.
#80: begin
ifnpos<4 then { }
begin
DrawWin(menu[npos],30); {
}
npos:=npos-^l;
{ }
DrawWin(menu[npos]y94); { }
end;
end;
end; {case }
#13: begin
Window(U,80y25);
TextAttr:=7;
ClrScr; { }
case npos of
1: begin
Write (' \ menu[npos].text);
ReadLn;
end;
2: begin
Write(*BbinonHeH \ menu[npos].text);
ReadLn;
end;
3: begin
WriteC \ menu[npos],text);
ReadLn;
end;
end; {case}
DrawMenu(npos); { }
end;
end; {case}
until (ch]=#27) or ((chl=#13) and (npos=4));
Window(l.180,26);
TextAttr:=7;
ClrScr; { }
End
1. ,
(. 5.2).
,
.
.
266
8. MS DOS
2.
. 6 ,
, .
, ,
. . ,
.
.
8.5.
() .
.
.
.
,
. .
1. 1 - 1 - :
, 1,
, 0.
2. 1 - 2 - :
:
01-;
10 - ;
11 - .
!:
01--;
10 - ;
11 - .
00, .
3. 1 - 4 - , 16- .
, , (. 8.5).
6 RGBrgb,
2/3 , - 1/3
. ,
:
R
1
j G
1
!
i
I
i
, : , 1/3, 2/3,
I, 4^ = 64 . 267
1.
. 8.5, 16-
16 ,
16 .
. , , ,
:
, , , .
.
4. 1 - 8 - , 256 .
,
, , 256
, 18 . 18
6 ,
64 .
:
268
8. MS DOS
1 1
Red
1 1
^^^^^
Green
0
;
Blue
!
; I
, 256
64^ = 262144 .
,
. ,
256
Borland Pascal 7.0.
,
, ,
(
- ) .
,
, Borland Pascal 7.0
- ,
,
, .
VGA,
. EGAVGA.BGI Graph
VGA = 9.
Borland Pascal . 8.3.
,
, Graph.
. Graph ,
.
1. InitGraplt(Var driver, mode:integer; patlt:string) -
.
,
, .
8.3
i ^
\ i
^
!
^
: VGALo =0
|
16
; ,^
,
'
!
^
640x200
i
!
i
^^ .
,.^^,.^^
I
1
4
VGAMed =1
16
640x350
'
VGAHi =2
16
640x480
\
269
L
: ,
, detect = 0.
path ,
, (
BGI Borland Pascal).
,
- ".
2. GrapliResult:integer - ,
.
3. GraphErrorMSG(ErrNum:integer):string -
.
:
Var dnver,mode,erwr: integer;
Begin
driver: =detect; { driver: =0;}
InitGraph (driver, mode, 'd: \BP \BGI');
error: =GraphResult;
iferroroO then { }
begin
WriteLn(' ',
GraphErrorMSG(error));
Hah(l); { }
end;
{ }...
4. CloseGraph - :
.
, , MS
DOS , MS DOS .
. Borland Pascal,
.
5. RestoreCrtMode -
.
6. SetGraphMode(mode:integer) -
,
RestoreCrtMode.
7. GetGraphMode:integer -
.
,
:
270
8. MS DOS
RestoreCrtMode; { }
... { }
SetGraphMode(GetGraphMode); { }
. Graph
.
1. GetPalette(Var Palette:PaletteTy) -
.
PaletteType, Graph:
PaletteType = record
size:byte; { }
Colors:array[O..MaxColorsJ of short in t; { }
end;
63.
2. SetAllPalette(Palette: PaletteType) -
.
PaletteType,
:
EGABlack = 0;
EGABlue = 1;
EGAGreen- 2;
EGACyan = 3;
EGARed = 4;
EGAMagenta=5;
EGABrown-20;
EGALiglitGrey=7;
{}
{}
{}
{}
{}
{}
{}
{-}
EGADarkGrey=56;
{-}
EGALightBlue= 57; {-}
EGALightGreen = 58; {-}
EGALightCyan = 59; {-}
EGALightRed = 60; {}
EGALightMagenta = 61; {}
EGAYellow = 62;
{}
EGAWhite = 63;
{}
3. SetPalette(ColorNum,Color:word) -
ColorNum Color.
4. SetBkColor(Color:word) - .
(
). ,
, . SetBkCoIor
, Color.
SetPalette(0,Color).
5. SetColor(ColorNum:word) -
ColorNum .
6. GetDefaultPalette(var Palette: PaletteType) -
.
271
1.
,
,
, :
SetPalette(5,18); { 5-
010010 - -}
SetColor(5); { - 5- }
SetBkColor(5); { 0-
000101 - : }
GetPalette(p); { PaletteType}
for i:=0 to p.size do Write(p.colors[i]:5); {
}
,
. Graph ,
, .
1. SetLineStyle(styley patterity thickness: word) -
style pattern thickness.
:
SolidLn=0; {}
DottedLn=l; {}
CenterLn=2; {}
DashedLn=3; {}
UserBitLn=4; { }
0..3, .
4, .
- 16 48 , ,
, : 1010
1010 1010 1010, $,
. 48
.
,
:
NormWidth=l; { }
ThickWidth=3; { }
:
SetLmeStyle(UserBitLn,$AAAA,NormWidth); {
: , }
272
8. MS DOS
2. SetFUlStyle(fillstyle, color: word) -
fillstyle color .
:
EmptyFill-O;
SolidFill-l;
LineFill-2;
LtSlashFill-3;
SlashFiU=4;
BkSlashFill-5;
LtBkSlashFill=6;
HatchFill-J;
XHatchFill=8;
InterLeaveFill=9;
WideDotFill=10;
CloseDotFill=ll;
UserFill=12;
{ - }
{ }
{
}
{ - }
{ - }
{WW ~ }
{WW - }
{-f+++ - }
{ - }
{+ + + - }
{. . . . - }
{
- }
{, }
10 10 10 10
0 10 10 10 1
10 10 10 10
0 10 10 10 1
10 10 10 10
0 10 10 10 1
10 10 10 10
0 10 10 10 1
.
4. FloodFill(x, , color: word) -
, SetFiIlStyle, ,
273
1.
color,
(,). , .
. Graph
,
( ,
).
1. PutPixelfx, , color: word) - ,
color,
(X, ).
2. GetPixel(x,y:word):word -
, .
3. MoveTo(x,y:word):word- ,
.
4. MoveRel(dx,dy:word) -
.
5. GetX:word G^/K*>v^rrf-
X .
6. GetMaxX:word GetMaxY:word -
.
7. Line(xlyyl,x2,y2:word) - (1,1)
(2,2).
8. LineTo(x,y:word) -
(,).
9. LineRel(dXydy:word) -
, dx,dy.
10. Rectangle(xl,yl,x2,y2:word) -
.
11. Bar(xlyyl,x2,y2:word) -
.
12. Bar3D(xl,yl,x2,y2,depth:word; top: boolean) -
, :
1, 1, 2, 2; depth 25% ,
top , (, true, ,
false). ,
, .
.
13. DrawPoly(numPoints:word; var PolyPolnts) -
. ,
-
PointType:
274
8. MS DOS
Type PointType = record
x,y:word;
end;...
:
Var MP:array[5] of PointType; { }
DrawPoly(5,MP);
{ }
1.
20. Sector (, , stangle, endangle, radiusX, radiusY: word) .
21. FillEllipse (, , radiusX, radiusY: word) -
.
.
^ Write WriteLn,
.
Graph
.
1. SetTextStyle(font,direction,charsize:word) -
font, direction
charsize.
:
DefaultFont=^0;
TriplexFont=l;
SmallFont=2;
SanserifFont=3;
GothicFont=4;
{}
{ }
{ }
{ }
{}
,
:
HorizDir-0;
VertDir=l;
{ }
{ }
,
(8x8 ). ,
.
2. SetTextJustify(horiz, vert :word) -
goriz vert
.
:
LeftText=0;
CenterText=l;
{ }
{
}
RightText=2;
{ }
BottomText=0; { }
CenterText=l; {
}
TopText=2;
{ }
3. TextHeight(st:string):word - st
.
276
8. MS DOS
4. TextWidth(st:string):word - st
.
5. OutText (sUstring) - ,
.
6. OutTextXY(x,y:word; sUstring) - st,
(, ).
, .
, Graph
.
1. ClearDevice - .
2. SetVlewPort (1, 1, 2, y2:word; clip:boolean) -
. xl, 1, 2, 2 ,
clip - , .
3. GetViewSettings(Var mn:ViewPortType) -
- win ViewPortType:
ViewPortType^ record
xl,yl,x2,y2:word; {}
Clip:boolean; {}
end;...
4. ClearViewPort - ,
.
5. SetActivePage(pageNumber:word) -
- pageNumber.
,
. ,
.
6. SetVisualPage(pageNumber:word) -
.
:
SetVisualPage(O): { }
SetActivePage(l); { 1 }
Rectangle(10, 60, 30, 80); { }
Readln;
{, }
SetVisiialPage(l); { 1 }
.
Graph
.
277
L
1. GetImage(xl,ylyx2yy2:word;varp:pointer) -
. 1,1,2,2
. ,
.
ImageSize.
2. ImageSize(xl,yl,x2,y2:word):word
, .
3. PutImage(x,y:word; var p:pointer; bitblt:word) -
(, ). .
bitbit :
NormalPut=0;
XorPut=l;
OrPut=2;
AndPut=3;
NotPut=4';
{ }
{ }
{ }
{ }
{ }
, (12 = 1IOO2)
(12 = 1IOO2),
NormalPut - 1100 - ;
XorPut - 0000 - ( );
OrPut - 1100 - ;
AndPut - 1100 - ;
NotPut - 0011 - .
.
:
Size:= ImageSize(0A99,99);
GetMem(p,Size); {
}
:=0;
:=0;
Pieslice(50,50,0J60J7); { }
Getlmage(0,0,99,99,p^); { }
repeat
PutImage(x,y,p^yO); { ,
}
delay (] 00);
{}
:=+3;
:=+1;
278
8, MS D
until x>getmaxx'50; { }
FreeMemfp, Size);
{ }
8.6. *
.
. ,
.
,
.
, ,
..
.
.
,
(. 8.6).
:
-
niy -
^ " ^1
-
"
, , kxj^, kyj^ - ;
i
max
/"^
min
\i
. 8.6. :
- ; -
279
1 ~
; ], Xj^ - ,
.
:
kxj = 1 (Xj - |) X ^^ + ,
^\ = 1 ( - yj) X + ^,,
1 - .
,
.
.
.
8.5. ,
y=cos(x+2)/2
,
.
.
.
Program Gr;
Uses Crt, Graph;
Const
n=5;
{ }
=2; { }
=100;
{ }
=^5; =5;
{ }
=60; =;
=45; ^'; { }
= array[1. .100 ] of real;
ari = array[L. 100] of integer;
Var
gd,gmj:integer; { }
X, y:arr;
{ }
, ky:ari;
{ }
ymin, ymax:real; { }
dx,dy:real;
{ }
dkx,dky:integer; { }
mx,my:real;
{ }
st:string[5];
{ }
h , : real;
{, }
280
8. MS DOS
Begin
ClrScr;
Write :');
ReadLn(xn,xk);
h:=(xk-xn)/(k-l);
{ }
[1]: =;
ymin:=le30;
ymax:=-lelO;
for i:=] to do { }
begin
yfiJ:=cos(x[iJ+2)/2;
if y[i]>ymax then ymax:=y[ij;
if y[i]<ymin then ymin:=y[ij;
if iolOO
thenx[i+]J:=x[iJ+h;
end;
mx:=(kxk-kxn)/(xfkj'xf]j);
{ }
my:=(kyk-kyn)/(ymax-yminj; { }
for i:=J to do
{ }
begin
kxfij: =round{(xfiJ'X[lJ) *) +;
kyfij: =round((ymax-y[iJ) *) +;
end;
gd: =detect;
InitGraph(gd,gm, "); { }
SetColor(4);
{ - }
OutTextXY( 180,20, T=cos(x-^2J/2'); { }
SetColor(17);
{ - }
SetBKColor(7);
{ }
Rectangle(,,);
{
}
SetColor(4);
{ ~ }
for i:=l to -1 do
{ }
Line (kx[i],ky[i],kx[i+l],ky[i^l]);
dkx:='round((kxk'kxn)/nx);
{ }
dky:=round((kyk'kyn)/ny);
{ }
SetColorf] 7);
{ - -}
for i:=J to do
{ , }
Line(kxn+dkx*r,kyn,kxn-^dkx*i,kyk);
for i:=] to ny do
{ , }
Line(kxn,kyk-dky*i,kxk,kyk'dky*i);
dx:=(x[kJ'X[]JJ/nx;
{ }
dy:=(ymax-ymin)/ny; { }
SetTextJustify(1,2);
{ }
281
1.
Y = cos(x+2)/2
0.50
0.31
0.12
-0.07
-0.26
-0.46
2.00
3.00
4.00
5.00
6.00
7.00
. 8.7.
for i:=J to +1 do
{ }
begin
Str((xflJ+dx*(i-])):n:m,st);{ }
OutTextXY(kxn+dkx*(i'l), kyk+6,st); {
}
end;
SetTextJustijy(2J);
{ }
for i:=l to ny+I do
{ }
begin
Str((ymin+dy*(i'l)):n:m,stJ;{ }
OutTextXY(kxn-6,kyk'dky*(i'l),st); { }
end;
ReadLn; { ENTER}
Closegraph;
End.
, . 8.7.
.
.
8.6.
12,
.
. 282
<^. MS DOS
.
.
.
Program difgramma;
Uses Graph;
Const
kmax=12; { }
r=J50;
{ }
=5;
{ }
=2;
{ }
mas=array[J..kmax+JJ of integer;
masl=array[L.kmax] of real;
Var
fmasl;
{ }
alfa:mas;
{ }
driver,err,
{ }
{ }
bet, { ,
}
,,
{ , }
1,1,
{ }
,,
{ }
i: integer;
st:string[5]; { }
s:real;
{ }
begin
WriteLnC ( 1 \:3,') ');
ReadLn(k);
{ }
for i:=l to do
begin
WriteLnCBeedume\i:3, '-e ');
ReadLn(f[i]);
while f[i]<0 do
begin
WriteLnC , ');
WriteLnCBeedume\i:3, '-e );
ReadLn(f[i]);
end;
283
1.
s:-s+f[i]:
end;
if s=0 then
begin
WriteLn('Bce .');
ReadLn;
halt(l);
{ no }
end;
{ }
driver: =detect;
InitGraph(driver,err, ");
SetBkColor(15); { }
SetPalette(lO);
SetColor(l); { }
{ }
: =GetMaxX div 2;
: =GetMaxY div 2;'
{ }
alfa[l]:=0;
for i:= 2 to k+1 do
begin
ifi<>k+l then
alfa[ij:=alfa[i'lj+round(ffi']]/s*360)
else alfa[k+l]:^360;
SetFillStyle(i mod 10, i); { }
Pieslice(xn,yn,alfafi'lJ,alfafiJ,r); { }
{ }
bet:=(alfa[i'lj+alfa[ij) div 2;
x:==xn+round(r*cos(bet*pi/I80));
: =yn'round(r*sin(bet*pi/I80));
if ((bet> =0)and(bet< ^90))or((bet> =2 70)and(bet< -=360))
thenxl:=x-^10
elsexJ:=X'8*n']0;
if((bet>=0)and(bet<=J80))
thenyly-lS
else
yli^y^l;
Sir(f[i'l]:n:m,st);
{ }
OutTextXY(xl,yl,st);
{ }
end;
ReadLn;
CloseGraph;
End
, . 8.8.
284
8. MS DOS
56.00
79.00
35.00
24.00
23.00
44.00
66.00
38.00
79.00
. 8.8.
8.7. .
:
, .
()
(),
: .
, ,
,
.
,
,
.
.
: ,
.
.
285
1.
(,,,)
(,)
( , ) ^ .
C(x,,yJ
(''''')
(,,
. 8.9. :
- ; - ; -
(. 8.9, )
| = X + dx,
y i = y + dy,
X, - ; xj, | -
; dx, dy - .
(^, ^>) (. 8.9, ):
] =(-) + ,
1 =(-) + ,
Mj^, My - ; ^., ^. - ,
.
(^,, ^,) (. 8.9, ):
| = ( - ^) cosa + ( - ^,) sin + ^,,
1 = ( - ) cosa - ( - x j sin + ^ ,
- .
8.7. ,
:
, .
.
:
( ).
.
-
.
.
.
286
8. MS DOS
. 8.10.
.
- .
( ).
.
-
.
! .
, , ,
.
Square.
(. 8.10):
,
, -
.
,
. :
Program ex;
Uses Crt,Graph;
Const
r=]00;
Type
mas =array[I.. 4] of integer;
Var
X, y, xl, yl:mas;
gd,gm,xn,yn,xc,yc, ij, kl: integer;
t,k:reaJ;
287
L
{ }
Procedure Square(,:mas);
Begin
Line(x[lly[llx[2],y[2]);
Line(x[2],y[2],x[3],y[3]);
Line(x[3],y[3lx[4].y[4]);
Line(x[4M4Ml].y[l]):
End:
{ }
Procedure Pow(xc,yc,x,y:integer;t:real;var xl,yl:integer);
Begin
xl: =xc+round((X'Xc) ^cos(t)) -^rounddy-yc) '^sin(t));
yl: =yc+round((y'yc) *cos(t))'round((X'Xc) *sin(t));
End;
{ }
Procedure Massch(xc,yc,x,y: integer; k: real;var xJ,y J .'integer);
Begin
xJ :=round(x*k-^(]-k) *xc);
yl: =round(y*k+(l'k) *yc);
End;
{ }
Begin
gd: =detect;
InitGraph(gd,gm, 'd:\bp\bgi);
SetColor(2);
xn: =GetMaxX div 4;
yn: =GetMaxY div 3 *2;
xc: =GetMaxX'Xn;
yc:=GetMaxY'yn;
{ }
xflj: =xn-r; yflj: =';
x[2]: =xn+r; [2]: =yn-r;
x[3]: =xn+r; y[3]: =yn-^r;
x[4]: =xn-r; [4J: =yn+r;
k:=0.99;
t:=0;
{ }
while (t<l) and not KeyPressed do
begin
SetColor(2); { }
Square(x,y); { }
t:=t-^0.001; { }
288
8. MS DOS
{}
forj:=I to 4 do { }
Massch(xc,yc,xljJ,y/jJ,kx] [flyJ /jj):
Massch(xc,yc,xn,yn,kxn,yn); { }
{}
forj:=l to 4 do { }
Pow(xn,yn,x]/jJ.yW7rt,x]/jlylOJ)>'
forj:=I to 1500 do Delay(lOOO); { NewDelay . 8.3}
SetColor(O); { - }
Square(x,y);
{ }
x:=xJ;
{ }
y:=yJ;
end;
CloseGraph;
End
,
.
.
:
1)
,
;
2) , -
,
.
, .
2.
,
A4dxl,dyl)
,
(dx,dy)
(. 8.).
Square 1
. ,
,
~
. . 8.11.
.
289
I.
Program ex;
Uses Crt,Graph;
Const r:real=100; { }
Var
X, , dx, dy, dxl, dyJ, xn, yn, xc, yc, xnl, ynl.real;
gd,gmJJ: integer;
tyk:real; { }
{ }
Procedure Squarel(x,ydx,dy:integer);
Begin
Line(x+dx,y-^dy,X'dy,y+dx);
Line(X'dy,y+dx,X'dx,y'dyJ;
Line(x-dx,y'dy,x+dy,y'dx);
Line(x+dyy-dx,x+dx,y+dyJ;
End;
{ }
Begin
gd:=detect;
InitGraph(gd,gm, *d:\bp\bgi');
{ }
: =GetMaxX div 4;
yn:--GetMaxYdiv3*2;
xc: ^'GetMaxX-xn;
yc:=GetMaxY'yn;
{ }
dy:=0;
: =0,95;
t:=0;
{ }
while (t<100) and not KeyPressed do
begin
SetColor(2); { }
Squarel(round(xn) round(yn), round(dx), round(dy));
{}
xnl: = xn *k+(]'k) *xc;
yn 1: =yn *k+ (J -k) *>'c;
r:= k'^r;
{}
t:=t+l;
{ }
dxl:=r'^cos(t);
dyl:= r*sin(t);
forj:=J to 5000 do Delay(lOOO); {}
290
8, MS DOS
SetColor(O); { }
Squarel(round(xn), round(yn), round(dx), round(dy));
dx:=dxl; { }
dy: =dyl
xn:=xnJ
yn:=ynl
end;
CloseGraph;
end.
.
:
- .
MS DOS
.
8.4,
.
VGA, Borland Pascal, 4
,
(
).
VGA ( 19: 200*320 256 262 144
), (8 ) .
,
.
8.8. ,
. - -.
Graph,
,
, 200*320,
.
( ).
, Borland Pascal
, , Dos, .
Program ex;
Uses Graph, CrU Dos;
Type
ScreenType=array [0,.199,0..319J of byte; {
- }
ImageType=array[0..999]ofbyte; { }
ScrTypePtr=^ScreenType; { }
ImageTypePtr=^^ImageType; { }
291
L
{ mode}
Procedure SetBIOSMode(mode:byte);
Var r:registers;
Begin
r.AL:=mode;
{ AL}
:=0;
{ }
intr($10,r);
{ 0- 10- }
End;
{ }
Var
Driver, Mode .'Integer;
s:string;
ij, n, m, l,y, dy: integer;
Active_Ptr:ScrTypePtr; { " "}
Image:ImageTypePtr; { }
Begin
{ }
Driver: =Detect; InitGraph(Driver,Mode, ");
s:='ABCDEF\SetColor(4); SetTextStylefGothicFont, HorizDir, 3);
OutTextXY(2,2,s);
n:=TextHeight(s)+3;
m:^TextWidth(s)+3;
GetMem(Image,(n+l)*(m+])); {
}
1:=0;
for i:=0 to ndo
for J: =0 to mdo
begin
image^[l]:=Lo(GetPixel(j,i)); { }
1:4+1;
end;
CloseGraph;
{ }
SetBIOSMode($13); { 19- }
Active_Ptr:=Ptr($AOOO,0); { }
:-0;
dy~l;
{ }
repeat
{ }
1:=0;
for i:=0 to do
292
8. MS DOS
forj:=Oto do
begin
Active_Ptr''[y+i+]0j+20J:=image^flJ;
1:4+1;
end;
for i:=J to 1000 do Delay(3000); {}
Inc(y,dy); { }
if(y>120) or (y<0) then dy:='dy; {
}
until KeyPressed;
SetBIOSMode(3);
{ }
End.
8.8.
- ,
.
- ,
, .
, Borland Pascal,
, BIOS.
15 = 51 (int 33h ~
).
:
( );
;
( );
.
, Borland Pascal
,
, Dos.
Intr(numlnt:byte; Var Regs:Register) -
numlnt. Regs Registers
( ) :
Registers = record case Integer of
0: (AX,BXCXDXBP^DI,DS,ES,
Flags: word);
J: (AL,AH,BL,BH,CL,CH,DL,DH:byte);
end;...
, . , 293
I.
,
, DX.
, ,
.
Unit Mouse;
Interface
Uses Dos;
Function ResetMouse:Boolean; { }
Procedure ShowMouseCursor; { }
Procedure HideMouseCursor; { }
{ }
Procedure ReadMouseStatefVar , :integer;{ }
Var LeftButton,
{ }
MiddleButton,
{ }
RightButton:boolean); { }
Procedure MoveMouseCursor(x,y:integer); {
}
Implementation
{ }
Function ReSetMouse.Boolean;
Var :Registers;
Begin
r.AX:^0;
intr($33,r);
ReSetMouse: =r.AX=$FFFF;
End;
{ }
Procedure ShowMouseCursor;
Var r: Registers;
Begin
KAX:=I;
intr($33,r);
End;
{ }
Procedure HideMouseCursor;
Var r: Registers;
Begin
KAX:^2;
intr($33,r);
End;
294
8. MS DOS
{ }
Procedure ReadMouseStatefVar ,:integer;{ }
Var LeftButton,
{ }
MiddleButton,
{ }
RightButton:boolean); { }
Var :Registers;
Begin
r.AX:=3;
intr($33,r);
:=;
y:==r.DX;
LeftButton-fr.BXAND 1)<>0;
RightButton:=(r.BXAND 2)<>0;
MiddleButton:^(KBXAND 4)<>0;
End;
{ }
Procedure MoveMouseCursor(x,y: integer);
Var r: Registers;
Begin
KAX:=4;
r.CX:=x;
KDX:=y;
intr($33,r);
End;
End
, , .
,
, (
) ,
. , , ,
.
. 8.12 ,
( , ,
Left true, - , false).
,
,
.
.
,
,
8x8 .
295
[
^
Left = tme
Left = false
I
Left = false
. 8.12. {
8.9. ,
.
.
,
(. 8.13).
. ,
(), i^pcop .
, .
, , ,
, , .
,
.
::||||?|^||
iiiii^iiasSs
|||||||||,
-?ciif:f|ii
. 8.13.
296
8. MS DOS
Program ex;
Uses CrtMouse;
Var x,y,xt,yt: integer;
l,m,r:boolean;
exit_m: boolean;
Begin Clrscr;
if not ReSetMouse then { }
begin
WriteLn('Mbitub ');
Halt(l);
end
else WriteLn('Mbiiub , *);
ShowMouseCursor; { :
}
MoveMouseCursor(0,0); {
}
Window(70,1,80,3); { - }
Textattr:=^]6*J+14;
Clrscr;
Gotoxy(2,2);
WriteCKoe');
Windowd 1M25);
Gotoxy(],3);
Textattr:=5*]6-^9;
repeat
{ }
ReadMouseState(x,y, /, , );
if I then { }
begin
{ }
xt:=x div 8+1;
yt:=y div 8+1;
exitjn:=(xt>=70) and (xt< =80) and (yt> =1) and (yt< =3);
if not exitjn then
begin
Gotoxy(xt,yt);
HideMouseCursor; { ,
}
Write('x= \ xt:4, ' = \ yt:4);
ShowMouseCursor; {
}
end;
repeat ReadMouseState(x,y,l,m,r) until not I; {
}
end;
until exitjn; { }
Textattr:=7;
Clrscr;
End
297
1.
MJ.
. 8.14.
*
.
8.10.
: ,
. (
): ~ Exit
Esc (. 8.14).
Program ex;
Uses Mouse,Crt,Graph;
Var
x,y:mteger;
l,m,r: boolean;
exitjn: boolean;
driver,mode: integer;
ch:char;
{ }
Procedure Button(xI,yI,x2,y2:integer;s:string);
Begin
SetColor(O);
SetFillStyle(l8);
Bar(xl,yl,x2,y2);
{ }
SetFillStyleOJ);
(1-^2,1+2,2'3,2); { }
SetFillStyle(ll5);
Bar(x],ylxl+ly2);
298
8. MS DOS
Bar(xl+2,]+Ixl+2,y2-J);
Bar(x],yJ,x2,yI+J);
Bar(xl+lyl+1x2'lyl
+2);
SetColor(4);
SetTextStyle(lA3);
OutTextXY(xl^20,yl+3,s);
End;
{ }
Begin
Clrscr;
if not ReSetMouse then { }
begin
WriteLnCMouse not found, *);
halt(l);
end;
driver: ^'detect;
InitGraph(driver,mode,' ');
SetColor(4);
OuttextXY(10,]0, 'Drawing with mouse:');
ShowMouseCursor;
{ }
SetBkColor(3);
Button (500J0,600,50, 'Exit');
repeat { }
if keypressed then ch:-readkey {
, }
else { , }
begin
ReadMouseState(x,y,l,m,r); { }
Exitjn: ==(> =500)and(x< =600)and(y>=10)and(y< =50);
if not Exitjn and I then { Exit
}
begin { }
HideMouseCursor;
PutPixel(x,y4);
ShowMouseCursor;
end;
end
until (exitjn and I) or (ch=#27);
repeat ReadMouseState(x,y,l,m,r) until not I; {
}
CloseGraph;
End
299
I.
1 8.4 ,
: .
8.9. .
MS DOS ()
.
MS DOS.
- ,
, DOS.
:
COMSPEC=C:\COMMAND.COM
{
MS DOS}
PATH=C:\QEMM;C:\DOS;C:\NC
{
}
PROMPT=$p$q
{ MS DOS}
,
SET.
DOS .
1. EnvCount: integer -
, MS DOS.
2. EnvStr(Index:integer):strmg -
MS DOS .
3. GetEnv(EnvVar:string):string -
MS DOS .
, , ,
, MS DOS
work:
flag:--false;
while (i<EnvCount) and not flag do
begin
ifpos('work^\EnvStrli])^l then
begin
path: =copy(EnvStr[i], 6, length(EnvStr[i])-5);
flag:'=true;
end
else inc(i);
300
8. MS DOS
end;
if flag then < >
else < > ...
MS DOS - ,
MS DOS (
).
, :
A:\>C:\My\copyflle A.dat B.dat 80
DOS ,
.
1. unt:integer - B03Bpaui?ieT .
2. ParamStr(Index:integer):string -
, ,
:
ParamCount
ParamStrfOJ
ParamStrflJ
ParamStr[2]
ParamStr[3]
=3
= C:\My\copyfile
= 'A.dat'
= 'B.dat'
= W
- ,
. . .
, ,
,
, ,
.
DOS.
1. Exec < >,
< \\>:string) -
.
2. DosExitCode:word -
.
:
0123-
;
Ctrl - ;
;
.
301
1.
(
Halt).
3. SwapVeciors - (,
) Borland Pascal
, :
DOS->Pascal -> 005( ) ^
Pascal->DOS
SwapVectors
SwapVectors
, ~
, , Borland Pascal.
,
:
{$ < >, < >,
< >}
- 1024 65520 ; -
655360 ; -
655360 .
8.11. ,
..
.
{$ $4000,0,0} { 16, }
Program ex;
Uses Dos;
begin
WriteLnC ,./);
SwapVectors;
Exec('c: \utils\bitmap.exe \ *r24.pcx');
SwapVectors;
WriteLn(\., ');
ifDosError then {
}
WriteLn(Vuiu6Ka DOS #', DosError)
else
WriteLn(* . = *,
DosExitCode); { }
End.
302
2. -
9.
, ,
100 . . ,
, .
,
- ().
Windows,
Delphi, Visual C++, C++ Builder.
,
^ {),
[2].
, ,
, ,
.
9.1.
{
),
().
,
.
,
2i - .
303
2. -
.
, ,
, ,
, ,
, , .
,
. ,
.
, 5.2.
9.1.
, y=sin , y=cos , y=tg , =1 , =^
:
;
;
.
(. . 5.6 - 5.7). , , . . .
, , .
: . .
, . .
, .
(. 9.1).
,
.
,
.
,
.
,
: , .
: ,
, ,
,
, - .
304
p.
(fV
i ^
()
()
. 9.1.
,
, .
2
8.4.
9.2. -
- .
- ,
, , .
,
, ,
. ,
,
.
305
2. -
. 9.2. ,
-
. ,
. ,
, ..
,
, ,
.
.
,
- . . 9.2
, -.
-
:
- ;
- ;
1. - , ,
.
-
,
, ,
.
9.3.
,
. ,
,
: , ,
.
,
306
9. /
. ,
, , ,
, - , ,
.
,
, .
. Borland Pascal ,
.
, .
, , C++.
.
, ,
.
, .
,
.
^,
- (. 9.3, , ).
(. 9.3, ).
,
.
10-12.
,
.
'
{>
()2
. 9.3. :
flf - ; - ; -
307
2. -
2..4
. 9.4. , :
;
,
. .
, ,
(. 9.4, ).
.
(. 9.4, ).
^
, ,
,
.
. ,
(1 -
) ,
,
( ) .
,
(. 9.5),
.
, , 0..* 1 ..*, *,
.
0..*
-
-<
,
. 9.5.
.
,
,
, .
308
9.
-
.
.
()
.
.
:
~
; , ,
LISP SMALLTALK;
{ ) -
-
; ,
( , , ..);
, ', , --
, Borland Pascal
;
-
- -; ,
;
, -
( C++),
.
.
,
, , ,
, , , :
.
{ ).
,
, :
, ,
, ,
.
{ ),
.
, 11.5.
,
.
309
2. -
,
,
, .
.
1. ,
/ ~
, .
,
,
.
2.
-
- .
3.
-
(
) .
.
9.2. ,
:
( );
;
;
;
;
;
.
,
,
. TWord
. TText
, .
TWord.
, , (. 9.6, ).
.
310
p.
TWord
font, size
SetFont()
SetSize()
TWord
font, size, next
SetFont()
SetSize()
L.nmax
0..*
TText
n, nmax, MasW(nmax)
Length (), Add (), Del(),
SetAttrO, Chang 1{),
Chang2()
TText
pFirst;^TWord
<>\ Length (), Add (), Del(),
SetAttrO, Chang 1(),
Chang2()
. 9.6. :
- ; 6-Q
TText
TWord (. 9.6, ). ,
, ,
,
.
.
9.3. ,
9.1.
,
. .
.
, ,
[, ], , ,
.
TMetod. Run
( ) ,
.
Task, Run.
TMetod ( ).
TMetod, Task (. 9.7).
, TMetod Task
. ,
abstruct.
311
2. -
TMetod
, b.real
Run
TMainMenu
Task 0
h:real
Task ( )
TMaxMin
eps.real
TaskO
TRoot
eps:real
Task ( )
. 9.7.
. 9.8.
,
,
, .
.
, .
, ,
(. 9.8).
.
10 - 11.
9.4. -
- ,
: , ,
. , ,
. ,
, .
.
. -
.
.
, ,
.
.
:
,
.
(, 312
p.
, ).
,
.
, ,
/ (,
, ),
..
,
. .
. -
.
, .
.
, , , ,
, .
,
, .
. , ,
.
, ,
.
, ,
.
. -
.
, ,
,
, .
,
,
.
,
, , ,
. ,
, .
, -
.
313
. .
, (
) , .
.
, ,
, .
:
< > = object
< >
< >
end;...
.
,
, :
Procedure < >.< >;
< >
Begin
< >
End;...
314
TRoom
length, width
Square()
. 10.1. {) ()
Function < >. < >;
<; >
Begin
< >
End;...
10.1. ,
(. 10.1, ).
:
, ,
(. 10.1, ). ,
, - ,
, -,
.
TRoom = object
length, width:real;{: }
function Square .real; { }
end;
Function TRoom.Square; { }
Begin
Square:= length"^ width;
End;...
,
.
. - .
,
. , ,
Self ,
.
.
:
315
2. -
Function TRoom.Square; { }
Begin
Square: = Self, length * Self, width;
End;...
Self , @Self , (,
, ,
).
10.2. .
,
, ,
.
:
Var A.'TRoom;
{ TRoom}
B:array[1..5] of TRoom; { TRoom}
Type pTRoom=^TRoom; { TRoom}
Var : pTRoom;
{ TRoom}
,
, --
.
New New.
:
New(pC);
pC:=New(pTRoom);...
Dispose. :
Dispose();...
,
, ,
11.7.
.
, :
:
< >.< > < >.< >;
with:
316
2. -
Function TRoom.Square; { }
Begin
Square:^ length"^ width;
End;
Const
A:TRoom = (length:3.5; width:5.1); { }
Begin
WriteLn(' \A.Square);
End
-
,
Init:
Program ex;
Type TRoom = object
length, width.real;{: }
function Square:real;{MQTOJX }
procedure //i//(7,H';/'^aO;{ }
end;
{ }
Function TRoom.Square;
Begin
Square: = length* width;
End;
{ }
Procedure TRoontlnit;
Begin
length:=l; width:-w;
End;
Var A:TRoom; { -}
{ }
Begin
AJnit(3.5y5.1); { }
WriteLn(' \A.Square);
End,
.
.
:
Const A:TRoom=(length:3.7;:5,2);
Var B:TRoom;..,
:=; { B.length=3.7, B.width=5.2}
318
2. -
WriteLnC = \A.Square);
End.
Borland Pascal
. :
public-,
;
private - ,
.
, ,
, ,
:
Unit < >;
Interface
< >= object
< >
private
< >
public
< >
private
< >
end;...
, , TRoom
,
private,
:
Unit RoomHiden;
Interface
Type TRoom = object
private { }
length, width:real; {: }
public
{ }
function Square.real;{ }
procedure Init(l,w:real);{ }
end;
Implementation
Function TRoom.Square; { }
Begin
Square:= length"^ width;
End;
320
Fmin Fmax
, , , . 10.2.
321
2, -
TWin_gr
1,1,2,2, F, xn, xk, n,
dx, Fmin, Fmax, mx , my,
xm, ym, xs, ys, s
Init, Run, Fminmax, Rx, Ry
dx,
XS, ys (
,
) . .
. - ,
, ,
.
. , Fmin, Fmax, xs ys Run, Rx, Ry,
.
Run, ,
, .
. 10.3. TWin gr
.
. Init
() Run ().
,
public. , Init
Fminmax,
. Run
Rx - , Ry - .
, Run,
.
TWin_gr . 10.3.
, TWin_gr.
Unit WinGr;
Interface
Uses crt.Graph;
Type
Fn =Function(X:real) :real;
arr=array[L. 200] ofpointtype;
TWin_gr=object
public
procedure Inlt(axn,axk:real;an:Integer; aF:Fn;
axl,ayl,ax2,ay2:Integer); { }
procedure Run;
{ }
private
xl,yl, x2, 2:Integer; { }
F:Fn;
{ }
n:Integer;
{ }
xn, xk,
{ }
322
2. -
Fmin:=y;
Fmax:-y;
for i:=2 ton do
begin
x:=x+dx;
y:=F(x);
if y>Fmax then Fmax:=y;
if y<Fmin then Fmin:=y;
end;
end;
{ }
Procedure JWinjgKRun;
Var x:real;
i: integer;
dinjirr:^arr; { }
Begin
SetViewPort(xl,1 ,x2,y2,true); { }
ClearViewPort;
{ }
SetColor(2);
{ }
Rectangle(0,0,x2'xJ,y2'yl);
{ }
SetColor(14);
{ }
SetLineStyle(0,0,3);
{ : 3}
:=;
GetMem(dinjarr,2*n); { }
for i:=J to do
begin
dinjarr^fij,x: =round((X'Xn) *mx+xs);
dinjarr^fij.y; =round((Fmin'f(x)) ^my+ys);
x:'=x+dx;
end;
DrawPoly(n,dinjarr^);
{ }
FreeMemfdinjarrJ'^n); { }
SetLineStyle(0,OJ); { : 1}
Rx;
{ , }
Ry;
{ , }
ReadKey; { }
end;
{ , }
Procedure TWin^gr.Rx;
Var jc, dxl:real;
Begin
x;=xn;
dxl:=(xk'Xn)/5;
324
2. -
{ }
Begin
dr:=detect;
InitGraphfdnmode, ");
WLInit('0.9,0.9,I00fA0,300,400);
Wl.Run;
W2.Init(l,3,200/,320J00,600,400);
W2.Run;
End
1.
. .
2.
.
: .
.
.
.
-
. ,
,
. ,
: ( ),
.
11.1.
.
-
() -,
.
- -
, -, :
< -> = ]((<\\ ->)
< >
end;...
11.1.
,
(. 11.1).
10.3
TRoom Room, -
?
?
^
__ __ J
. 11.1.
327
2. -
TRoom
length, width
Square(), Init'()
,
.
TRoom,
TVRoom
V,
height
Square (. 11.2).
V(), NewInitO
TRoom
. 11.2.
TVRoom height.
Room,
TRoom:
Program ex;
Uses Room;
Type TVRoom = object(TRoom)
heighUreal;
{ }
function V:real;
{ }
procedure Newlnit(lw,h:real); { }
end;
Procedure TVRoom.NewInit;
Begin
Init(lyW); { }
height:=h; { }
End;
Function TVRoom. V;
Begin
V:=^Square*height;{ }
End;
VarA:TVRoom;
Begin
A.NewInit(3.4.5.l2.8);
WriteLn(*nnoutadb = \
A.Square:6:2);
WriteLn(V6beM = ', A. V:6:2);
End
. 11.3.
TVRoom
328
TVRoom, ,
: length, width height (. 11.3)
: Square, Init, Newlnit V.
,
" .
IL
, -,
,
.
. Borland Pascal ,
.
,
1, , .
. ,
, .
. Borland
Pascal -
-. ,
-
.
:
VarA:TRoom;
B:TVRoom;...
:-;
{}
:-;... {: !}
. Borland Pascal -.
, (. 11.4).
:
-
-
"**
?
-
. 11.4.
-
329
2. -
VarpC: ^TRoom;
E.TVRoom;...
{ }
{ }
:- @;
{
}
^.height: =2.7; {, -
height
TVRoom}
,
(. 2.5):
pTVRoom^'^TVRoom;
VarpC: ^TRoom; { }
:TVRoom;... { }
:= @;
{
}
pTVRoom(pC)^.height:=2.7; { }
1. , ,
,
. , ,
.
.
.
2. ,
, , ,
.
.
11.2.
,
.
?
- .
11.2.
?
,
. 11.5. (. 11.5).
330
//.
TRoom
length, width
Square(), Init ()
15
TFlat
n, roomsrTRoom
^
FlatSquare(), Init ()
. 11.6.
.
TRoom,
.
,
,
15 . TFlat 15
TRoom (. 11.6).
. FlatSquare,
Square - TRoom.
.
,
rooms,
.
.
Program ex;
Uses Room;
{ Room 10.3}
TFlat=object { }
n:byte;
{ }
rooms:array[L.15] of TRoom; { TRoom}
function FlatSquare:real;{MQTOJX }
procedure Init(an:byte;Var arooms);{MQTOJX }
end;
Procedure TFlatJnit; { }
Var a:array[L,15] of TRoom absolute arooms; {
- . 5.5}
Ubyte;
Begin
:=';
{ }
for i:=l to do { ,
TRoom
}
rooms[i].Inlt(a[i].length, [i],width);
End;
331
2, -
Function TFlaLFlatSquare; { }
Var S:real;
i: integer;
Begin
S:=0;
for i:=l to n do { }
S: =S+rooms[iJ, Square;
FlatSquare:=S;
End;
Const mas:array[L.3]of TRoom- ((length:!.5; width:3.75),
(length:2.85; width:4.1),
(length:2.3; width:2.8));
Var F:TFlat; { -}
Begin
FInit(3,mas);
{ }
WriteLn(* = \FFlatSquare);{ }
End
1. , . 9.6, .
.
2. , ,
, ,
, - (. 8.4).
.
11.3.
,
:
( )
.
11.3.
,
(. 11.7).
?
. ,
. 11.7. . ,
332
//.
TRoom
TRoom (. 11.8).
,
.
0..1
TRoom
length, width
Square(), Init ( )
TBRoom
pB:^TRoom
BSquare(), InitAII ( )
Program ex;
Uses Room;
Type
TBRoom =object(TRoom)
. 11.8.
pB: ^TRoom;
TBRoom
function BSquare:real;
procedure InitAll(lw:real; lb,wb:real);
end;
Procedure TBRoom. InitAII;
Begin
Init(l,w);
if (Ib^O) or (wb-=OJ then
pBnil
else
begin
New(pB);
pB''Jnit(lb,wb);
end;
End;
Function TBRoom, BSquare;
Begin
ifpB=nil then BSquare: = Square;
else BSquare: = Square ^pB\ Square;
End;
Var B:TBRoom; { -}
Begin
, InitAll(3J,5J,L8A8); ( }
WriteLn(' = \B.BSquare);
End
.
, 7.2.
,
.
11.7.
333
2. -
1. , . 9.6, .
.
2.
, , , ,
, - (.
8.4). .
.
.
11.4.
9.3,
.
11.4.
2,
(. 11.9).
, ,
TRoom.
. Square,
.
, Square
(. 11.10).
Square TVRoom2
Init,
height.
Borland Pascal
-.
inherited -
:
inherited Square
TRoom. Square
:
?
. 11.9.
2
334
TRoom
length, width
Square(), Init()
TVRoom2
height
Square(), Init()
. 11.10.
TV Room
//.
Program ex;
Uses Room;
Type TVRoom2 = object(TRoom)
height;real;
{ }
function Square:real; { }
procedure InU(l, w,h:real); {
}
end;
Procedure TVRoom2,Init;
Begin
{ }
inherited InitQyW); { TRooniInit(l,w) }
height:-h; { }
End;
Function TVRoom2.Square;
Begin
Square: ^inherited Square-^2'^height*(length'^width); {
}
End;
VarA:TVRoom2;
Begin
AJnit(3A5.l2.8);
WriteLnCrinouiadb = \A.Square);
End
,
.
: -, , ,
, (
).
,
.
. , Init TRoom
, Init TVRoom2 - .
.
,
,
:
< >(< >).< >.
335
2. -
:
VarA: TVRoom2;,.,
TRoom(A),Square;..
{ }
^^
^ ,
(. 11.4).
,
,
.
11.5. .
,
, , ,
.
.
11.5, ,
,
, ,
, (. 11.11).
TRoom2 TRoom,
Print. TVRoomP TRoomP,
(. 11.11).
.
?
TRoomP
length, width
Square(), Init(), Print()
TVRoomP
height
Square(), Init()
7
?
_ .^
. 11.11. :
{)
()
336
. 11.12.
TVRoomP
//.
1 - !
Program ex;
Type TRoomP=object
length, width:real;{: }
/unction Square:real; { }
procedure Print;{ }
procedure /'.^;{ }
end;
Function TRoomPSquare; { }
Begin
Square: = length * width;
End;
Procedure TRoomPPrint; { }
Begin
WriteLnCIInouiadb =', Square:6:2); { }
End;
Procedure TRoomPJnit; { }
Begin
length: ="1;
width: ^^w;
End;
Type TVRoomP = object(TRoomP)
height:real;
{ }
function Square:real; { }
procedure Init(l,w,h:real); {
}
end;
Procedure TVRoomPInit;
Begin
////7(7,wj;{ }
height: =h;
{ }
End;
Function TVRoomPSquare;
Begin { }
Square :=inherited Square + 2*height*(length + width);
End;
Var A:TRoomP; B:TVRoomP; { -}
Begin
A.Init(3.5,5,1);
{ A}
A.Print;
{ = 17.85}
B.Init(3,5,5,1,2.7); { }
B.Print;
{ = 17.85 - !!!}
End
337
2. -
TRoomP
TVRoomP
^1
Square
-*
Square
1 1
, 11.13.
- , Print,
TVRoomP, Square. Square
, Print -
Square TRoomP (. .
11.13).
, , ,
,
( ).
,
~ .
:
1) virtual;
2)
- - ,
procedure constructor;
3) ,
.
, ,
. ,
,
(),
.
.
,
2 (. 11.14).
,
.
338
IL
. 11.14.
,
, .
, .
11.5. .
, Square
Init .
2-
Program easel;
Type TRoomP-object
length, width.real;{: }
junction Square:real; virtual; { }
procedure Print;
{ }
constructor Init(lyW:real); {}
end;
Function TRoomPSquare; { }
Begin
Square: = length * width;
End;
Procedure TRoomPPrint; { }
Begin
WriteLnf' =', Square:6:2); {
}
End;
Constructor TRoomPInit;
{ }
Begin
length: "="1;
width: =w;
End;
339
2. -
TVRoomP = object(TRoomP)
height:real;
{ }
function Square:real; virtual; { }
constructor Init(lyWyh:real); {}
end;
Constructor TVRoomP.Init;
Begin
/(^///(7,M^^;{ }
height: =h; { }
End:
Function TVRoomP Square;
Begin
Square:=inherited Square+2'^height*(length+ width);
End;
Var A:TRoomP; B:TVRoomP; { -}
Begin
A.Init(3,5,5J); { A}
A.Print; { = 17.85}
B.Init(3.5,5.],2,7); { }
B.Print; { = 94.64 - !!!}
End,
,
:
1) ,
-
;
2)
, ;
3)
, -,
(
).
. - - .
, .. . ,
.
, :
,
, .
, ,
,
340
11.
, ?
.
11.6.
:
,
?
(.
11.15).
.
. 11.15.
, ,
{)
.
()
. 11.16.
Square ,
.
, .
Square
,
.
,
,
11.6.
. ,
,
.
TRoomD
Unit RoomMod;
Interface
Type
TRoomD=object
lengthwidth:real;{non:
}
function Square:real; virtual; {
}
constructor Init(lyW:real); {}
end;
length, width
Square(), Init()
z^
TVRoomD
height
Square(), Init()
. 11.16.
341
2. -
TVRoomD = object(TRoomD)
height:real;
{ }
function Square:real;virtual; { }
constructor Init(lyWyh:real); {}
end;
Implementation
Function TRoomD.Square;{ }
Begin
Square;= length"^ width;
End;
Constructor TRoomD.Init;
{ }
Begin
length: ;
width: ==w;
End;
Constructor TVRoomDJnit;
Begin
inherited Init(l,w); { }
height: =h; { }
End;
Function TVRoomD, Square;
Begin
Square: ^inherited Square+2 '^height*(length+ width);
End;
End.
.
Program case2;
Uses RoomMod;
VarpA: ^TRoomD; { }
:TVRoomD; { }
Begin
B.Init(3.5,5J,2,7); { }
WriteLn(*nnoujadb^ \ B.Square:6:2);
{ 11= 94.64}
:=@;
{
}
WriteLn(FInouiadb= \ ^.Square:6:2); { = 94.64}
End,
11.7. ,
,
, . 342
//.
,
-.
Square
, Print -
, -
Square .
Program case3;
Uses RoomMod;
Procedure Print(Var R:TRoomD); { }
Begin
}1('='\ R.Square:6:2);
End;
Var A.'TRoomD; B:TVRoomD; { -}
Begin
A.Init(3,5,5J);
{ A}
B.Init(3.5,5.1,2.7); { }
Print(A);
{ = 17.85)
Print(B);
{ = 94.64}
End
,
:
/(< &^>):pointer -
. ,
. :
ifTypeOf(SelJ) = /(<\\ >;
then < >
else < >
(
) , ,
, :
1) ,
;
2) ,
;
3)
, - ;
4)
.
343
2. -
.
,
, , , ..
.
, :
, .
.
1. , . 9.7.
.
2. ,
9.1.
, 1, ,
9.1.
11.6. .
~
.
, .
.
11.8. ,
: ,
, .
. 11.17.
. 11.17.
344
//.
0,0
0,0
0,0
\
Y|
Y> '
:(
Y^
" "
'
. 11.18. :
- ;- ;
-
,
(. 11.18).
, , ,
.
,
, , ,
.
, Rel,
(. 11.19, ).
(
TVLChar - ..), .
,
, , TLineChar
ch, X, ,
Move(), Rel(), Init()
TChar
ch, X,
Move(), Rel(), Inlt()
TVLChar
yn
Rel(),lnit()
A
TCirChar
xc, yc, r, to
Rel(),Init()
TLineChar
xn
Rel(), Init()
TVLChar
yn
Rel(), Init()
TCirChar
xc, yc, r, to
Rel(),Init()
. 11.19. :
- ; -
345
2. -
(. 11.19, ).
, ,
Rel Move, ,
Rel {). , ,
,
. .
Program ex;
Uses crt,Graph;
{ }
TChar=object
ch:char; {}
,:integer; { }
constructor Imt(ach:char;ax, ay: integer);
procedure Move(t:integer);
procedure Rel(t:integer); virtual;
End;
Constructor TChar.Init;
Begin
ch:='ach;
x:=ax;
y:=ay;
End;
Procedure TChar.Rel;
Begin End;
Procedure TChar.Move;
Begin
SetColor(GetBkColor);
OuttextXY(x,ych);
Rel(t); { }
SetColor(ord(ch) mod 16);
OutTextXY(x,ych);
End;
{ , }
TLineChar=object(TChar)
xn:integer; { }
constructor Init(ach:char;aXy ay: integer);
procedure Rel(t:integer); virtual;
End;
Constructor TLineChar.Init;
Begin
inherited Initfach, ax, ay); xn: =ax;
End;
346
//.
Procedure TLineChanRel;
Begin
x:=(xn+t) mod GetMaxX;
End;
{ , }
TVLineChar=object(TChar)
yn:integer; { }
constructor Init(ach:char;ax, ay: integer);
procedure Rel(t:integer); virtual;
End;
Constructor TVLineCharlnit;
Begin
inherited Initfach, ax, ay);
yn:=ay;
End;
Procedure TVLineChanRel;
Begin
y:=(yn+t) mod GetMaxY;
End;
{ , }
TCirChar=object(TChar)
,,:integer; { }
tO:real;
{ - }
constructor Init(ach:char;axc,ayc,ar:integer;atO:real);
procedure Rel(t:integer); virtual;
End;
Constructor TCirChar.Init;
Begin
inheritedInit(ach,axc+round(ar*sin(atO)), ayc+round(ar*cos(atO)));
xc:=axc;
yc:=ayc;
r:=ar;
tO:=atO;
End;
Procedure TCirCharRel;
Begin
x:=xc+Round(r*sin(tO-^t*0.05));
y: =yc-bRound(r *cos(tO-^t *0.05));
End;
{ }
Var A:TLineChar;
B:TVLineChar;
C:TCirChar;
347
2. -
t: integer;
i: integer;
dn md: integer;
{ }
Begin
dr:=detect;
InitGraph(dnmd, :\\);
AJnitCa'A25);
B.InitCb\ 100,0);
CJnit('c \GetMaxXdiv 2,GetMaxY div 2,80,0);
t:=0;
{ }
while not Keypressed and (t< 1000) do
begin
A.Move(t); { }
B,Move(t);
C.Move(t);
t:=t+l; { }
for i;=l to 1000 do delay(lOOO); { }
end;
CloseGraph;
End.
1. ,
: , .
.
2. ,
, , .
.
3. ,
. .
11.7. .
Borland Pascal ,
, .
.
New, 348
//.
.
New(<T\m >[, < >]) -
, , .
, .
, .
- . ,
, procedure
destructor. ,
,
.
Done.
Dispose.
/)/5/;(?5^<>[, < >] ) -
, , .
1L9.
2, ,
2,
.
(2'
).
11.7 , .
,
.
Program ex;
Type
pTRoomD2=''TRoomD2;
TRoomD2 ^object
length, width:real;{: }
function Square .real; virtual; { }
constructor Init(lyW:real); {}
destructor Done;
{}
end;
Function TRoomD2.Square; { }
Begin
Square:= length"^ width;
End;
349
2. -
Constructor TRoomD2.Imt;
{ }
Begin
length: =1;
width: ^w;
End;
Destructor TRoomD2.Done;
Begin
End;
Type pTVRoomD2^'' TVRoomD2;
TVRoomD2 = object(TRoomD2)
height:real;
{ }
function Square:real; virtual; {
}
constructor Init(l, Wyh:real); {}
end;
Constructor TVRoomD2,Init;
Begin
/?///(7,w^; { }
height:^h;
{ }
End;
Function TVRoomD2.Square;
Begin
Square: ^inherited Square+2*height*(length+ width);
End;
Var pA: pTRoomD2; pB:pTVRoomD2; { }
Begin
{ ~ }
pA:=New(pTRoomD2Jnit(3.5,5.1));
{ }
1('= \ pA\Square:6:2); { = 17.85}
Dispose(,Done);
{ }
{ - }
pB:=New(pTVRoomD2Jnit(3,5,5.I,2.7^^; { }
WriteLn('nnouiadb=', pB\Square:6:2); { = 94.64}
Dispose(pB,Done);
{ }
{ :
- }
pA:=New(pTVRoomD2Jnit(3,5,5.1,2.7)^;{ }
WriteLnCIInoujadb'^ \ pA^,Square:6:2); { = 94.64}
Dispose(pA,Done);
{ }
End.
. 350
//.
(
TRoomDS
0..1
),
length, width
,
Square(), Init (), Done()
- .
,
TBRoomD
.
-o! pBi^TRoom
Square(), Init(), Done()
, . 11.20.
7.2.
,
,
, ,
. , .
Borland Pascal fail,
.
, , nil,
, , ,
, false.
11.10.
,
. /
, -
- .
(. 11.20). TRoomD3,
TRoomD2, .
, ,
TBRoomD,
, .
Program ex;
Type pTRoomD3=^TRoomD3;
TRoomDS =object
length, width:real;
{: }
function Square:real; virtual; { }
constructor Init(l,w:real);
{}
destructor Done; virtual;
{}
end;
351
2. -
Function TRoomDS,Square; { }
Begin
Square:= length"^ width;
End;
Constructor TRoomDS.Init; {}
Begin
length: ="1;
width: =w;
End;
Destructor TRoomD3.Done;
Begin
End;
Type pTBRoomD=^TBRoomD;
TBRoomD=object(TRoomD3)
pB:pTRoomD3;
function Square:real; virtual;
function BSquare:real; { }
constructor Init(l,w:real; lb,wb:real);
destructor Done;- virtual;
end;
Constructor TBRoomD.Init;
Begin
inherited Init(l, w);
if(lb^O)or(wb=OJ thenpB:=nil
else
begin
New(pB);
ifpB=nil then
begin
WriteLnCHe *);
Done; { ; ,
}
fail; { }
end
else pB\Init(lb,wb);
end;
End;
Function TBRoomD.BSquare;
Begin
ifpBonil then BSquare:=pB\Square
else BSquare:^0;
End;
352
//.
Function TBRoomD, Square;
Begin
Square: = inherited Square+BSquare;
End;
Destructor TBRoomD. Done;
Begin { , }
ifpBonil then Dispose();
End;
Function HeapFuncfsize:Word):integer; far;
Begin HeapFunc:=I; end;
Var A: TBRoomD; pBLpTBRoomD; pB2:pTRoomD3;
Begin { }
: =@HeapFunc;
{ }
if A.Init(3,2,5.1,2.5J) then { true false}
begin
WriteLn(A.Square:6:2,A.BSquare:6:2); { }
A.Done; { }
end
else WriieLn('He , *);
{ -
-}
pBl:'=New(pTBRoomD,Init(3.2,5J,2.5,l));{nQw nil}
ifpBlonil
then
begin
WriteLn(pBl\Square:6:2,pBl^.BSquare:6:2); { }
Dispose(pBl,Done);
{ }
end
else writelnf'He . *);
{ -
-}
pB2:='new(pTBRoomDJnit(3.2,5.1,2.5J));{nQv^ nil}
ifpB2<>nilthen
begin
WriteLn(pB2^.Square:6:2, { 2}
pTBRoomD(pB2)^.BSquare:6:2); {
, -
- "" (. 11.1)}
Dispose(2,Done); { - 2}
end
else WriteLn(*He . ) ;
End
353
2. -
11.8. .
,
(). - ,
. ,
(, ),
. ,
, .
Borland Pascal
,
.
, .
.
,
(),
.
() (. 11.5),
.
,
. ,
,
.
.
11.11. ,
: , .
: -,
(. 11.21).
,
.
,
, ^, . ,
11.6, ,
.
-, -.
,
(. 11.22), Move.
354
11,
. 11.21.
.
Program ex;
Uses crtyGraph;
Type pChar^'^TChar;
{ }
TChar^object
ch:char;
x,y:mteger;
constructor Init(ach:char;aXy ay: integer);
procedure
Move(t:mteger);
procedure Rel(t:integer); virtual;
destructor Done;virtual; { ,
}
End;
TChar
ch, X,
Move(), Rel(), Init(), Done()
TLineChar
|1
TVLChar
yn
xn
Rel(),Init(),
Done()
ReI(),Init(),
1
1 Done()
0..10
TString
<^
Move(), Init(), Done()
TCirChar
xc, yc, , to
Rel(), Init(),
DoneO
. 11.22.
355
2. -
Constructor TCharlnit;
Begin
ch:=ach;
x:'=ax;
ay:
End;
Procedure TCharRel;
Begin End;
Procedure TCharMove;
Begin
SetColor(GetBkColor);
OuttextXY(x,ych);
Rel(t); { }
SetColor(ord(ch) mod 16);
OutTextXY(x,ych);
End;
Destructor TChar.Done;
Begin End;
{ ,
}
pLChar=^TLineChar;
{ , }
TLineChar=object(TChar)
xn.'integer;
constructor Init(ach: char; .: integer);
procedure Rel(t:integer); virtual;
End;
Constructor TLineCharlnit;
Begin
inherited Init(ackax,ay);
xn:=ax;
End;
Procedure TLineChanRel;
Begin
x:=(xn-^t) mod GetMaxX;
End;
Type p VChar=^TVLineChar;
{ , }
TVLineChar=obJect(TChar)
yn:integer;
constructor Init(ach:char;ax,ay :integer);
procedure Relft:integer); virtual;
End;
356
//.
Constructor TVLineCharlnit;
Begin
inherited Init(ach,ax,ay);
yn:=ay;
End;
Procedure TVLineCharRel;
Begin
y:=(yn+t) mod GetMaxY;
End;
Type pCChar=^TCirChar;
{ , }
TCirChar=object(TChar)
,,:integer; tO:real;
constructor Init(ach: char; axc,ayc,ar: integer;atO:real);
procedure Rel(t:integer); virtual;
End;
Constructor TCirChar.Init;
Begin
inherited Init(ach,axc+round(ar*sin(atO)),ayc-^ round(ar* cos(atO)));
xc:=axc;
yc:=ayc;
r:=ar;
tO:=atO;
End;
Procedure TCirChanRel;
Begin
x: =xc+Round(r*sin(tO+t*0.05));
y: =yc+Round(r*cos(tO-^t*0.05));
End;
Type TString=object
mas:array[l.JO] ofpChar; { }
n:integer;
{ }
procedure Init(as:string; tmove:byte); { }
procedure Moveft:integer);
{ }
procedure Done;
{ }
End;
Procedure TStringlnit;
Var i: integer;
Begin
n:=length(as);
357
2, -
for 1:=^] to do
begin
case tmove of
l:masfiJ:=new(pLCharJnit(asfiJ, 9*i, GetMaxYdiv 2));
2:mas[i]:=new(pVCharJnit(as[i], GetMaxXdiv 2'n*5-^J04 0));
3:masfiJ:=new(pCCharJnit(asfiJ, GetMaxXdiv 2, GetMaxYdiv 2,
100, 2*pi^(H)/n));
end;
end;
End;
Procedure TStringMove;
Var i: integer;
Begin
for i:==n downto J do masfiJ\Move(t);
End;
Procedure TString.Done;
Var i: integer;
Begin
for i:=] to n do dispose(masfiJ,Done);
End;
Var s:string; M:array[L.3] ofTString; ij,dr,md:integer;
Begin
Write(* 10 :');
ReadLn(s);
InitGraph(dr,md, 'd:\bp\bgi');
for i:=l to 3 do MfiJJnitfsJ);
t:-0;
while not KeyPressed and (t< =1000) do
begin
for i:=l to 3 do M[i].Move(t); { }
/;=/+7;
for i:=l to 1000 do delay(lOOO);
end;
for i:=l to 3 do MfiJ.Done;
CloseGraph;
End
-
, , , ,
.
358
//.
1. ,
: , .
, ,
,
.
2.
, .
.
12.
-
, .
, ,
.
,
.
.
12.1.
, ,
.
12.1. ,
: (), (
, ), / .
.
.
(. 12.1).
, - Enter.
,
Esc.
,
, . 12.2.
360
/2.
. 12.1.
. 12.2. :
1 - 4 - , ,
; 5 -
, ,
.
,
.
(. 12.3),
, ,
. ,
iliiiilll^
,
.
,
1| ^
|jij
.
. 12.3,
(. 12.4),
[;-;:;f \*if i ^ r l
361
2. -
.
1 1 . ,
;|':-:-,1:^^
.
, ,
,
1 1
, Enter:
. 12.4.
.
.
(. 12.5, \ , ,
.
/ .
. ,
(. 12.5, ).
,
(. 12.6).
, .
. ,
.
-
^:||::,,';;-^^^
;;:;:J;;^';;:;;;rt::t;r
[':::: ;:';;,::^'';^^^
||';;^^a<^n^
f-:'';:'^;^f^l|||iJ:^^
11111111111111
11 II
i': ?.
''yy.y:^!\i'jfi^^^^
. 12.5. {)
()
362
12.
^
W
1 [ \! 2 [ ]
i
^
1
[1
2 [ ]
'
"
-^5'
. 12.6.
:
1 - ; 2 - ;
3 - ; 4 -
-
. 12.7.
,
.
.
, :
) (. 12.8, ) - ,
( Enter);
v,^^^
'
^'"'^^v,^^
"
'
]
. 12.7. -
363
2. -
-:
1 1
home.dat
| |
1 1
1 1
1 11 !
1 ]
I [
Bii^^eM
1111111
1 1
. 12.8.
) (. 12.8, ) - ,
- ;
) (. 12.8, ) - ,
;
) , (. 12.8, , ) -
,
- .
,
- (. 12.9).
364
12,
|3<?|^^^
t^':,'
:-::'^/^:^:<:?^^:-...
<>
''?&^*^^::''$
|:f::;;';.-i;'?!*^
|||:
<>
-:,:
^'-->
| ^^^^^^^^^
<>
<>
,,,.^*.,, , , , , , . , , , , . . , * . . , ,
<> 1
.:.,-:,-...;::!:
1^; "'::: ]
* -.
^^^^^^
;/ \^__
\ ,11,,,.,,,,,,,,,,,
. 12.9.
(
)
,
.
12.2.
, . 12.9 .
,
, .
,
,
..;
.
365
2. -
TWin
1, 1, 2, 2, attr, xt, yt, text
Draw(), SetAttr(), Init()
TInput
inp:TWin
Draw(), Init(), Input(),
Enov{ \ Clear()
TMessage
ok:TWin
Draw(), Init(),
RunQ
TMenu
nalt, npos,
masalt:array[1..10] of TWin
Run(), Draw(), EnterQ, InitQ
TForm
ninput, masinp:an-ay[1..5] ofTInput
Draw(), EnterO, Input(), CIear(), Init()
. 12.10.
.
TWin, ,
, ,
, .
attr - . 8.1.
Draw, SetAttr. Init (. 12.10).
TInput TWin
inp TWin,
( . 12.10 ,
).
Init Draw,
.
Input,
Error, Clear,
.
TMessage TWin.
.
Draw, Init
Run, .
TMenu TWin,
TMessage,
. , ,
TWin, masalt. ~ .
nalt. 366
12.
. Run .
Draw,
. Run
Enter, .
TMenu Init.
TForm TMenu,
. -
, masinp,
ninput. Run
, Draw Enter - .
, TMenu, TForm Draw Enter
(1-
).
TForm -.
, Input Clear.
,
, (
). ,
.
12.3.
.
,
.
T W i n Win: -
, - .
Unit Win;
Interface
Uses crt;
Type str80=stnngf80J;
TWin-=Object
xly yly x2, 2:integer; { }
attr: integer;
{}
xt, yt:integer;
{ }
text:str80;
{ }
procedure Init (ax 1, ay I, ax2, 2, aattr, axt, ayt: integer;atext:str80);
procedure SetAttr(aattr:integer); { }
procedure Draw;
{ }
End;
367
2, -
Implementation
Procedure TWinJnit; { }
Begin
1:'=^1;
1:-^1;
2:='2;
2:^2;
attr:-aattr;
xt:=axt;
yt:=ayt;
text:==atext;
End;
Procedure TWin.Draw; { }
Begin
TextBackGround(attr div 16);
TextColorfattr mod 16);
Window(xl,yl,x2,y2);
Clrscr; { }
Gotoxy(xt,yt);
Write (text);
{ }
end;
Procedure TWin.Setattr; { }
Begin
attr: =aattr; { }
Draw;
{ }
end;
End
T I n p u t Input. Error
,
, ,
, (1-
).
Unit Input;
Interface
Uses crt, Win;
Type TInput=-Object(TWin)
inp:TWin; { }
Constructor Init(axl,ayl,ax2,ay2,aattr,axt,ayt:integer;atext:str80;
bxlybylybx2yby2ybattrybxtybyt:integer;btext:str80);
procedure Draw; { }
procedure Clear; { }
368
12.
procedure Input;
( }
function Error:boolean; virtual; { }
end;
Implementation
Constructor TInputJnit;
Begin
inherited Init(axl, ay I, ax2, ay2, aattr, axt, ayt, atext);
Inp.Init(bxI, by J, bx2, by2, battr, bxt, byU ');
end;
Procedure TInput.Draw;
Begin
inherited Draw;
inp.Draw;
End;
Procedure TInput. Clear;
Begin
inp.text:-**;
inp.Draw;
End;
Procedure TInput.Input;
Begin
Window (inp.xl, inp.yl, inp.x2, inp.y2);
TextBackGround(inpMttr div 16);
TextColorfinp.attr mod 16);
repeat
Gotoxy(inp.xt, inp.yt);
Clear;
ReadLnfinp, text);
Gotoxyfinp.xt, inp.yt);
Write(inp.text);
until not Error;
end;
Function TInput.Error; { }
begin
Error: "^false;
end;
End
T M e s s a g e Message.
Unit Message;
Interface
Uses crty Win;
369
2. -
TMessage='Object(TWin)
ok:TWm;
{ }
procedure Init(axl, ayj, 2, 2, aattr, cat, ayt: integer;atext:str80;
bxl, by], bx2, by2, battn bxt, byt:integer;btext:str80);
procedure Run;
{ }
procedure Draw; { }
end;
Implementation
Procedure TMessage.Init;
Begin
inherited Initfaxl, ayl, ax2, ay2, aattr, cat, ayt, atext);
ok. Initfbxl, by], bx2, by2, battr, bxt, byt, btext);
end;
Procedure TMessage.Draw;
Begin
inherited Draw; { }
okDraw; { }
End;
Procedure TMessage.Run;
Begin
Draw;
{ }
ReadKey; { }.
End;
End.
T M e n u Menu.
-
. ,
, , , ,
.
Unit Menu;
Interface
Uses crt, Win;
Type TMenu'=^Object(TWin)
nalt:integer;
{ }
masalt:array[L.10] ofTWin; { }
npos'.integer;
{ }
constructor Initfaxl,ayl ,2,2,aattr,
axt, ayt: integer; atext:str80;n: integer;
const w:array ofTWin); { TWin}
procedure Run;
{ }
procedure Draw; virtual; { }
370
12.
procedure Enter; virtual; { Enter ...}
end;
Implementation
Constructor TMenu.Init;
Var i: integer;
Begin
inherited Init(axl, ay I, ax2, 2, aattr, axt, ayt, atext);
nalt:=n; { }
for i:=I to nalt do
masalt[i]Jnit(w[i-l],xly wfi-IJ.yl, wfi'lj.x2, w[i-lj.y2,
wfi'ljMttr, wfi'JJ.xt, wfi'IJ.yt, wfi-lj.text);
End;
Procedure TMenu.Draw;
Var i:integer;
Begin { }
TextBackGround(O);
TextColor(l);
Windowd 1M25);
Clrscr;
inherited Draw;
{ }
for i;=l to nalt do masaltfiJ.Draw; { }
End;
Procedure TMenu.Run;
Var chl,ch2;char;
temp: integer;
Begin
Draw;
npos:=nalt;
masalt[npos].Setattr(71);
repeat
chl:=Readkey; { }
ifchl =#0 then ch2: =Readkey;
case chl of
#0: case ch2 of
#75:begin
{ }
temp:'=npoS'l;
iftemp^O then temp:=nalt;
{}
masaltfnposJ.SetattrfJJ3);
{ }
masaltftempfSetattr(71);
{ }
npos:=temp;
end;
#77:begin
{ }
temp:=npos+I;
iftemp=nalt+J then temp:=l; {}
371
2. -
masalt[npos].Setattr(113); { }
masalt[temp].Setattr(71); { }
npos:=temp;
end;
end;
#13: begin
masalt[npos].Setattr(113); { }
Enter; { Enter - }
Draw; { }
masalt[npos].Setattr(71); { }
end;
end
until((npos=nalt)and(chl=#13))or(chl=#27);{jxo }
End;
Procedure TMenu.Enter; { }
Begin end;
End.
T F o r m Form.
-
.
Unit Form;
Interface
Uses crt, WinJnputMenu;
Type TForm=Object(TMenu)
ninput:integer; { }
masinp:array[1..5] ofTInput; { }
constructor Initfaxl, ayl, ax2, ay2, aattr, axt, ayt: integer;atext:str80;
n:integer; const wl:array of TWin;k:integer;
const w2:array of TInput);
procedure Draw; virtual; { }
procedure Clear; { }
procedure Input; { }
end;
Implementation
Constructor TForm. Init;
Var i: integer;
Begin
inherited Init (ax 1, ayl,ax2, ay2, aattr, axt, ayt, atext, n, wl);
ninput: =k; { }
372
12.
for i:-l to ninput do
masmpfiJJnit(w2fi'JJ.xJ, w2fi'IJ.yI,
w2fi'lj,x2, w2[i'l].y2, w2[i'l],attr,
w2[i-l],xt, w2[i],yt,w2[i'l]Jext,
w2[i'l]Anp.xl, w2[i'l]Anp.yl,
w2[i-l].inp.x2, w2fi'JJJnp.y2,
w2[i-l],inp.attn w2[i'l]Anp.xU w2[hl].inp.yt,
w2fhlj, inp, text);
End;
Procedure TForm.Draw;
Var i: integer;
Begin
inherited Draw;
{ }
for i:=l to nalt do masalt[i].Draw; { }
for i:=l to ninput do masinpfiJ.Draw; { }
End;
Procedure TForm. Clear;
Var i:integer;
Begin
for i:=I to ninput do masinpfi],Clear; { }
End;
Procedure TForm.Input;
Var i: integer;
Begin
Clear;
for i:=I to ninput do mas inp[iJ, Input; { }
End;
End
12.4.
12.1
(. 12.7).
: ,
. ,
. : /,
. . 12.11
.
.
XBase (. 12.12).
373
2. -
.--^
^""^^-^^^^^
^--.^^^
/^
/ ^^^-.^.^^
^
1
. 12.11.
f,
.
: p_family ~ - , kl, 2,
,
family, name, telefon. ,
Open,
Add, Find
FindNext.
,
. ,
, , . 2"* = 16
. (. 12.1), ..
.
:
ff = (kl 2 4) v (1 2 ) v ( i l 2 4),
TBase
f, family, name, telefon, p_family, p_name, kl, k2
Init(), Open(), Add(), Find(), FindNext(),
Closefi:)
. 12.12. TBase
374
-
, V -
.
.
12.
12.1
kl
1
!
fr
Base, .
Unit Base;
Interface
Type str30=string[30];
rec=record
rfamily rname, rtelefon:str30;
end;
Type TBase=Object
ffile ofrec;
family name, telefon:str30; { }
pjdmilypjiame:str30;
{ }
kly k2:boolean;
{ }
procedure Open(fname:str30);
{/ }
procedure Add(afamilyaname,atelefon:str30); { }
function Find(afamilyaname:str30):boolean; { }
375
2. -
function FindNext:boolean;
{ }
procedure Closef;
{ }
End:
Implementation
Procedure TBase.Open;
Begin
Assign(f,fname); { }
{$
Reset:
{$1-^} { }
iflOResultoO then ReWrite(f): { }
End;
Procedure TBase.Add;
Var r:rec;
Begin
Seek(f,FileSize(f)); {ycTSLueiBnnBeiQM
}
r.rfamily:^afamily; { }
.'^;
rtelefon: =atelefon;
Write(f,rJ;
{ }
End;
Function XBase. Find;
Begin
Close(f);
{ }
ReSet;
{ }
pjdmily:=afamily;
{ }
_:=;
kJ:=p_family<> "; { }
2:=_<> 'V
Find:=FindNext;
{ }
End;
Function TBase.FindNext;
Var r:rec;
, k4, ff:boolean; { }
Begin
ff:^false; { }
while not Eof(f) and notjfdo
begin
Reader);
k3:=pjamily=r,rfamily;
{ }
4: =_ = ;
376
12.
if(kl and 2 and and 4) { }
or (not kl and k2 and k4) or (kl and not k2 and ) then
begin
ffi'^true;
{ }
family:^r.rfamily; { }
:= ;
telefon: = rtelefon;
end
end;
FindNext:=ff; { }
end;
Procedure TBase.Closef;
begin
18; { }
end;
End,
.
, , ,
, .
,
.
.
. 12.13 ,
TBase.
TIName
. Error TInput,
.
TMain .
Enter,
.
nalt. may
.
TAdd TFind
. ,
Enter - TMenu. TFind
,
, ,
Show ( ,
, ) .
377
2, -
"
IL
TIName
TMain
TForm
Error()
TAdd
Enter()
may
Enter(), Init()
2_
TFind
Enter(), Input(), Show()
XBase
. 12.13.
, TMessage.
-,
.
.
Program Memory;
Uses crt,WmJnput,Message,Menu,Form,Base;
{ - }
TMain-Object () { }
:1;
{ }
Procedure Enter; virtual;
end;
Type TIName=Object(TInput)
{ }
Function Error:boolean; virtual; { }
end;
Type TAdd=Object(TForm)
{ }
Procedure Enter; virtual; { }
end;
378
12,
TFind=ObJect(TForm)
{ }
Procedure Input; virtual; { }
Procedure Enter; virtual; { }
Procedure Show;
{ }
end;
{ -}
Var M:TMain;
{ }
N:TIName;
{ }
A:TAdd;
{ }
F:TFind;
{ }
ND:TMessage;
{ }
B:TBase;
{ }
{ }
Procedure TMain.Enter; { }
Begin
case of
l:begin
N.Draw;
{ }
NJnput;
{ , }
B,Open(N.inpJext); { , ,
- }
may:=true; { }
end;
2:if may then { }
A.Run;
{ }
/ then
{ }
FRun;
{ }
end;
End;
Function TIName.Error; { }
Var L'integer;
Begin l:=Pos(\ \ inp.Text);
if 1=0 then l:=length(inp.Text);
if(l>0) and e<==8) then Error:=fahe
else Error:=true;
End;
Procedure TAdd.Enter; { }
Begin
casenpos of
l:begin
Input; { , }
B,Add(masinpf]J. inp. text, masinp[2]. inp, text,
masinp[3J.inp.text); { }
379
2. -
end;
end; {case}
End;
Procedure TFindEnter; { }
Begin case npos of
]:begin
Input; { }
ifB,Find(masinp[l]AnpJexUmasinp[2]Anp.text) then Show
else ND.Run; { }
end;
2:begin
ifB.FindNext then Show
else ND.Run; { }
end;
end;
End;
Procedure TFindJnput; { }
Begin
Clear;
{ }
masinp[l].Input; { }
masinp[2],Input; ( }
End;
Procedure TFind.Show; { }
Begin
Clear;
masinpfJJ,inpJext:=B,family; masinpflJ.Draw; { }
masinpf2], inp. text: = name; masinp[2J, Draw; { }
masinpf3JjnpJext:=BJelefon; masinp[3J,Draw; { }
End;
{ -}
Const menul:array[l.J]
ofTWin=
((xl:I0;yl:14;x2:23;y2:18;attr:113;xt:3;yt:2;
text:' /
*),
(xl:26;yl:14;x2:39;y2:18;attr:113;xt:4;yt:2;
text: '
'),
(xl:42;yl:14;x2:55;y2:18;attr:113;xt:5;yt:2;
text: '
'),
(xl:58;yl:14;x2:71;y2:18;attr:113;xt:4;yt:2;
text: '
'));
menu2:array[L.2] ofTWin^
((xl:28;yl:18;x2:38;y2:21;attr:113;xt:2;yt:2;text: ''),
(xl:42;yl:18;x2:52;y2:2I;attr:113;xt:2;yt:2;text: ''));
380
12.
: array[1.. 3] of TWin=
((xl:23:yl:18;x2:33;y2:21;attr:113;xt:2;yt:2:text: ''),
(xl:35:yl:18;x2:45;y2:21;attr:113;xt:2;yt:2:text: ''),
(xl:47;yl:18;x2:57:y2:21:attr:113;xt:2:yt:2;textrBbixod')):
inpp:arrayfJ..3J ofTInput=
((xl:22;yl:8:x2:32;y2:8;attr:94;xt:l;yt:l;text:
'';
Inp:(xl:34;yl:8;x2:54;y2:8;attr:112;xt:l;yt:l;textr')),
(xl:22;yl:10;x2:32;y2:10;attr:94;xt:l;yt:l;text:
' ';
Inp:(xl:34:yl:10;x2:54:y2:10;attr:112;xt:l;yt:l;text:")),
(xl:22;yl:12;x2:32;y2:12;attr:94;xt:l;yt:l;text:
'';
Inp:(xl:34;yl:12;x2:54;y2:12;attr:112;xt:l;yt:l;text:")));
{ }
Begin
{ }
M.Imt(5,5,76,20,30,5,3, ' :',4,1);
A.Init(20,2,60,22,94,5,3, ' ',2,menu2,3,inpp);
N.Init(30,8,50,19,94,3,3, ' :',
35,12,45,12,112,1,1,' ');
FJnit(20,2,60,22,94,5,3, ' ',3, , 3, inpp);
NDJnit(30,6,50,14,30,6,2, ' ',
34,11,46,12,71,2,1, '');
{ }
.:'=false; { }
M,Run;
{ }
if may then B.Closef;
{ }
{ }
TextBackGround(O);
TextColor(l);
Window(l,1,80,25);
Clrscr;
End.
-
:
;
;
(
);
.
.
,
. ,
381
2. -
,
,
, ..
.
. ,
. ,
, ,
.
. , ,
, .
, ,
,
.
- .
,
. -
,
.
~
, . . ,
,
.
, Delphi Pascal,
.
1. ,
. : ,
, , .
:
1) ,
;
2)
;
3) , ,
.
382
12.
.
2. ,
. :
, , , ,
.
1
:
1) ;
2) ;
3) , .
.
3.
1 2.
1.
abs(x:integer):integer
abs(x:real):real
arctan(x:real):real
chr(i:integer):char
cos(x:real):real
dec(var i [; didongint])
exp(x:real):real
fiac(x:real):rea[
^^(^911 [; dUongint])
int(x:re^J)jreal_
( )
i- >1
i di
i di
_^ yejiyjo ^ apr^^
Jo(w:wqrd):byte
In ()
ord(x):longint
^ ^_
pi:real
|
, !
pred(x):< >
< < 1
J
random:real
__ __ J
random(i:mteger):mteger < < i
^^^^
1
randomise
^|
round(x:real):mteger
sin
|
sin(x:real):real
sqr(x:real):real
^
sqr(i:inteRer):mteger
sqrt(x: real): real
, ^yjouiee
trunc(x:real):integer
,
384
. M S D O S ( 8 6 6 )
x\yi
. 1 i 2 I 3
T
I
i 0 I
4
V
16 I ^ ^
32
h48
1 I 2
80 1 P
T
I
Q i R ; S
b i
112;
I
f
8 I 9 ; 10; 11
12
-^ I _|D ! |
$ ' U U |<-
&
"""1
64 \ @
'
96!
6 ! 7
-
71
V I W X
I w
! 3
I 1441 P
; I
: 160
e I
m !
L _}
I ~
I
I
J i
P I
_L
i 1
II
208
.-
192!
240!
^ !H ^ '=^ II
' 176
:224|
L j M ; N
\ i ] '
g ' h
' !
8
I i J
-L
F ! G i
: 128: A
; (
.- -4
1--
13 [ 1 4 I 15
:
1. = + .
2. 32. 255 .
3. 8 .
4. 10 .
5. 13 .
385
. scan-
scan-
Cntl + 2
Shift +
Alt + Q..Alt + ( )
::::::::::^::i::"T""i
15
I
1.71 Z7^^^-^^^^^
Alt + A..Alt + L ( )
30..38
Alt + Z..Alt + ( )
44..50
F1..F10
59..68
i
!
__,
._
;;; ;;;;;;7;;;7"7i
;
i
Page up
73
'^ 75 "^"" ^
->
End
_._.
zii. I'jii
' ' ^""11
79
"
80
Page down
81
Ins
82
83
Del
..,
84..93
1
j
94.. 103
Alt + Fl..Alt+F10
Ctrl + Print screen
Ctrl + <rCtrl + ->
Ctrl + End
~[04|13
114
_...^
-1
Ctrl + Home
_.._|
_._J
Alt+l..Alt + = ( )
Ctrl + Page up
"
';
;
115
386
-'~"~""]
,_//" ^^irzii^
< -
^"'" ' i
i
"
116
117_
118
119
120..131
132
2. . ,
String. :
ShortString = String Borland Pascal;
AnsiString - ,
AnsiChar 2147483547 , (#0),
1;
WideString - ,
WideChar 2147483547 , (#0),
1;
PChar - , array[0..] of
Char, (#0),
0;
String ShortString {$-} AnsiString {$+}.
.
PChar PChar
: PChar(<cpooa >).
3. .
,
: Assign -> AssignFile, Close -> CloseFile.
4. .
{$J+} ,
Borland Pascal, {$J-} - :
f^r <>:<>=<>; ...
5. . ,
. Result,
.
.
, ,
.
6. . :
Unit <>;
Interface < >;
Implementation < >;
Initialization < >;
Finalization < >
end.
, ,
, , -
.
388
4. Delphi Pascal Borland Pascal 7.0
Delphi Object Pascal Borland Pascal 7.0. Object Pascal
:
.
Delphi Pascal.
1. . Delphi Pascal
. .
:
Shortint
Byte
Smallint
Word
Longint
Integer
Cardinal
-128... 127
0...255
-32768...32767
0...65535
-2147483648...2147483647
0...2147483547
,
1
1
2
2
4
4
4
Boolean
ByteBool
WordBool
LongBool
,
1
1
2
4
ord(false)=0, ord(true)=l
ord(false)=0, ord(true)?tO
To
AN^I
Unicode
AnsiChar = Char
WideChar
1
2
Currency 922337203685477.5808
387
Delphi Pascal.
,
-.
, - .
Create Destroy TObject,
Delphi. ,
.
,
:
Constructor < >,Create;
begin
inherited Create;
end;
Destructor < >,Destroy;
begin
inherited Destroy;
end;
, , ,
:
Borland Pascal 7.0:
Delphi Pascal:
Type
TNum = class
public n; integer;
constructor Create (an:integer);
end;
Constructor TNum.Create;
begin
inherited Create;
n:=an;
end;
Var p.pTNum;
Begin
New(p, Init(5));
WriteLn(p\n);
Dispose(p);
End.
Var A:TNum;
Begin
A:=TNum. Create (5);
WriteLn(A.n);
A. Destroy;
End;...
389
, Delphi Pascal :
< > = class (< >)
private
< >
protected
< >
public
< >
published
< >
automated <, ->
end;
protected ,
. published
, (.
6).
:
virtual, ,
, override.
, override,
TObject .
Delphi
abstruct, :
TNumber=class(TObject)
public
Procedure Print; virtual; abstruct;
end;
TIntNumber=class(TNumber)
private i: integer;
public
Constructor Createfai: integer);
Procedure Print;override;
end;
Delphi Pascal
:
;
(, , );
;
;
..
[5].
390
5. Windows
Delphi
Delphi (. 5.1)
32- Windows.
, MS DOS, Windows
,
- , ,
, , ..
,
, .
[11111
Foiml
|Form1: TForml
\\
! = cXas(T: )
. 5.1. Delphi
391
Delphi
,
, .
, Delphi.
(
, .)
. Properties
, ,
, Events - ,
.
.
,
, ,
.
Delphi ,
, .
, ,^
.dpr. , Delphi,
.
-,
.dfm Delphi Pascal .pas.
,
.
, , , ,
.
: ,
, .dcu
.res.
Delphi .
5. - Windows,
.
.
1. .
File\Save Project As...
MyProject.
392
(Forml), (Unitl). ,
File\Save As..., , ,
Calc.
2. .
. ,
, Propeties
Caption ()
.
3. / -
. Standart
Edit,
(. 5.2 , )
.
Properties Text
.
Delphi
TForml, TForm
(. 5.2, ).
4. .
Standart
Button. ,
Shift. ,
, .
Standart . ,
^^^^^^^^!
Cub
, '
<i^ ^ ">
\\_ jt3^e
^ B S E i
'}^-'
iliii
iilliS
^1
TForrril = cXassfTForin)
E d i t l : TEdit;
B u t t o n l : TButton;
Button2: TButton;
Buttons: TButton;
Button4: TButton;
Buttons: TButton;
1^^1 .<;|
a
. 5.2. {) ()
393
, . ,
, (
Caption Properties ) ,
=, +, -, *, / Quit.
.
5. .
Events .
,
. Button 1 ,
, OnClick ( ).
:
Procedure TForml.ButtonlClick(Sender: TObject);
begin
EditLClear;
{ Editl}
operation:='@*; { }
EditLsetfocus; { Editl}
end;
,
.
:
Button2Click - =:
Procedure TForml.Button2Click(Sender: TObject);
Var s:string;
begin
operate;
{ }
operation:-'-^'
{ =}
Str(sum:6:3,s);
{ }
EditLtext:=s;
{ Editl}
ButtonLsetfocus; { Button 1}
end;
Button3Click - +:
procedure TForml.Button3Click(Sender: TObject);
begin
operate;
{ }
operation:-*-\-^; { +}
EditLsetfocus;
{ Editl}
end;
394
Button4Click - -:
procedure TForml.Button4Click(Sender: TObject);
begin
operate;
{ }
operation:^*''; { -}
EditLsetfocus; { Editl}
end;
ButtonSClick - *:
procedure TForml.Button5Click(Sender: TObject);
begin
operate;
{ }
operation:='*^; { *}
EditLsetfocus; { Editl}
end;
Button6Click - /:
procedure TForml.Button6Click(Sender: TObject);
begin
operate;
{ }
operation:-V*; { /}
EditLsetfocus;
{ Editl}
end;
Button7Click - Quit:
procedure TForml.Button7Click(Sender; TObject);
begin
Close;
{ }
end;
. .
Operate.
, :
Procedure Operate;
Var s:string; code:integer; n:double;
Begin
s:-FormLEditLtext;
{ Editl.text}
FormLEditLclear;
{ Editl}
395
Val(s,n,code);
case operation of
'@'; sum:-n;
'+'; sum:=sum'^n;
'-': sum:=sum'n;
=sum*n;
: sum:=sum/n;
end;
{ }
{ }
end;
7. . ,
, ,
( implementation):
Var Sunudouble;
operation: 1=';
8. .
FiIe\SaveAll.
9. .
Ctrl-F9 Project\Compile.
, .
10. .
F9 Run/Run Run
.
. ,
,
,
.
5.2. Windows
.
.
.
. - ,
(. 5.3).
1 ^
^ , J
^^^ . I
"^^^
,
'V
. 5.3.
396
:
, -
OK
Enter
[
]
Enter
[
]
]
. 5.4.
(. 5.4).
,
- .
.
, Delphi (. 5.5),
, .
(.
5.6):
.
, (
Delphi, , ,
, ,
) :
1^^^||^^
TButton
TLabel
TEdit
TBevel
. 5.5.
397
^^!
!^
3]^^^'-;>;:.-:/"
*:-1
^ iiiii>w>it>'^>ijiiii>^;^i
./Ir^>.l...>..-l;l.'>:'.S'.J:..^...^....'^I;I-''
5^;<[ij 625
^'^:|
!:|
!
;B^fte-4MCif10^
. 5.6. :
- ( ); - ;
-
Forml - :
Name: MainForm ~ -;
Caption: ' ' - ;
Labell ~ :
Name: InputLabel - -;
Caption: ' ' ~ ;
Label2 - :
Name: OutPutLabel - -;
Caption: ' :' - ;
Editl - :
Name: InputEdit ~ -;
Edit2 - :
Name: OutPutEdit - -;
398
Enable: false - ;
Readonly: true - ;
Button 1 - :
Name: NextButton ~ -;
Caption: '' - ;
Button2 - :
Name: ExitButton - -;
Caption: '' - .
.
,
, TNumber
Num ,
.
TObject.
. 5.7 ( Delphi). TMainForm
TNumber ,
.
. TNumber
:
Unit UnitNumber;
Interface
Type
TNumber=class(TObject)
private Num:single;
public Constructor Create(aNum:single);
Function SqrNumber:single;
end;
-;-'.-^'.';j
V 'Sp0^- 1
TMainForm
^^:;,
-
^:
MainFormActivate
InputEditKeyPressed
NextButtonClick
ExitButtonClick
TNumber 1
Num
Create()
Sqr( )
Destroy()
1111
. 5. ?1
399
Var N: TNumber;
Implementation
Constructor TNumber. Create(aNum:single);
begin
inherited Create;
Num:=aNum;
end;
Function TNumber.SqrNumber:single;
begin Result: ^Sqr(Num);
end;
end.
MainForm
UnitNumber.
. ,
, ,
,
(. 5.1).
5.1
MainForm: On Activate (. 5.6, )
TEdit
,
Enter I
InputEdit: OnKeyPressed
(.
j - 5.6,
),
1
,
, (.
5.6, )
j
I
1
NextButton: OnClick
: -
I
(. 5.6, )
I
ExitButton: OnClick
i
400
,
Events
.
,
. MainForm,
(, ,
).
Unit MainForm;
Interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls; { Delphi}
Type
TMainForm= class(TForm){oimcdLUHQ - }
InputLabel: TLabel; OutputLabel: TLabel; {}
Input Edit: TEdit;
Output Edit: TEdit;
{}
NextButton: TButton; ExitButton: TButton; {}
Bevell: TBevel;
{}
procedure FormActivatefSender: TObject);
procedure InputEditKey Press (Sender: TObject; var Key: Char);
procedure NextButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
end;
Var MainForm: TMainForm; {- }
Implementation
uses UnitNumber; { TNumber}
{$R \DFM}
Procedure TMainForm.FormActivate(Sender: TObject);
begin
OutputEdit Visible:=false; { }
OutputLabeLVisible:=false; { }
NextButton.Enabled:=false; {
}
InputEdit. Clear;
{ }
InputEdit.ReadOnfy:=false; { }
InputEditSetFocus;
{ }
end;
Procedure TMainForm.InputEditKeyPress(Sender: TObject; var Key: Char);
Var k:single; Codennteger;
begin
ifKey-=#13 then
begin
Key:=#0; { }
401
Val(InputEdit. Text,k,Code);
if Code-0 then
begin
N:-TNumber.Create(strtofloat(InputEdit.Text)); { }
OutPutEditText:'=floattostr(N.SqrNumber); { }
KDestroy; { - TObject}
OutPutEditVisible:-true; { }
OutputLabel,Visible:=true; { }
InputEdit.ReadOnly:-true; { }
NextButton.Enabled:=true; {
}
NextButtonSetFocus; {
}
end
else { }
MessageDlgCCmpoKu codep:>/um ',
mtErrorJmbOkJyO)
end;
end;
Procedure TMainForm.NextButtonClick(Sender: TObject);
begin
FormActivate(NextButton); end; { }
Procedure TMainForm,ExitButtonClick(Sender: TObject);
begin Close; end; { }
End,
- Delphi
:
Program ProectXQ;
Uses
Forms,
MainFormUnit in 'MainFormUnit.pas', {Mainform}
UnitNumber in 'UnitNumber.pas';
{$R *.RES}
Begin
Application.Initialize; { }
Application.CreateFormfTMainForm, MamForw);{ }
Application,Run;
{ }
End.
,
, Delphi
(. 12.1).
402
:^:%|||||^^
IBBI&yfl
^^
;:;11*#:1
.111
':'1^^\
||1-:.1^
,;p.;.j|;;,,-^
::|1||;;|
1':|^|!5^^ ;
^'^':*1
^^-.^
' ^^^^^^^^^^^^^^^^^
]
. 5.8. :
- ; - / ;
- ; -
5.3. .
. 5.8 .
.
. OS.9 .
, . 12.13, ,
Delphi, XBase
TObject. ,
, Delphi
MessageDlg,
.
TBase
Borland Pascal 7.0. :
Assign Close AssignFile CloseFile
Base TBase ,
.
403
TFonn
-
TMainFomi
TlnputFomi
TAddFomi
TFindFomi
XBase
TObject
. 5.9.
Unit BaseUnit;
interface
Type str30=-string[30J;
rec=record
rfamily, rname, rtelefon:str30;
end;
Type TBase=Object
public
ffileofrec;
family, name telefon:str30; { }
pjamilyp_name:str30;
{ }
kl, k2:boQlean;
{ }
procedure Open(friame:str30); {/ }
procedure Add(afamily,aname,atelefon:str30);{ }
function Find(afamilyaname:str30).boolean; { }
function FindNext:boolean;
{ }
procedure Closef;
{ }
End;
Var
Base:TBase;
implementation
Procedure TBase.Open;
Begin
AssignFile(fJhame);
404
{ }
{$!-}
; { }
iflOResultoO then ReWrite(f); { }
End;
Procedure TBase.Add;
Var r.rec;
Begin
Seek(f,FileSize(f)); { }
r.rfamily:=afamily; { }
: =;
rtelefon: =atelefon;
Write(f,r);
{ }
End;
Function XBase. Find;
Begin
CloseFile(f);
{ }
ReSet(f);
{ }
pjamily:=afamily;
{ }
:=;
kl:=p_family<>";
{ }
2:=_<>";
Find:=FindNext;
{ }
End;
Function TBase.FindNext;
Var r:rec; , k4,ff:boolean; { }
Begin
ff:=false; { " "}
while not Eof(f) and notffdo
begin
Read(f,r);
k3:=pj'amily=r.rfamily; { }
4: = = ;
if(kl and 2 and and 4) { }
or (not kl and k2 and k4)
or (kl and not k2 and ) then
begin
ff:=true;
{ " "}
jfdmily:=r.rfamily; { }
:=;
telefon: =^ rtelefon;
end
end;
405
FindNext:=ff; { }
end;
Procedure TBase.Closef;
begin
CloseFile(f); { }
end;
end.
MainForm TMainForm ,
,
. . InputForm,
/ .
, MainForm AddButton
FindButton Enable
false. .
InputForm
: true .
Unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMainForm = classfTForm)
OpenButton; TButton;
AddButton: TButton;
FindButton: TButton;
ExitButton: TButton;
procedure OpenButtonClick(Sender: TObject);
procedure AddButtonClickfSender: TObject);
procedure FindButtonClick(Sender: TObject);
procedure ExitButtonClickfSender: TObject);
end;
var MainForm: TMainForm;
implementation
uses AddUnit, FindUnit, InputUnit;
{$R *.DFM}
procedure TMainForm. OpenButtonClickfSender: TObject);
begin
if InputForm.ShowModal=mrOk then { InputForm}
begin
{ , }
AddButton.Enabled: =true;
{ }
406
:
FindButton.Enabled:=true; { }
end;
end;
procedure TMainForm.AddButtonClick(Sender: TObject);
begin
AddForm.ShowModal;
{ AddForm}
end;
procedure TMainForm.FindButtonClick(Sender: TObject);
begin
FindForm,ShowModal;
{ FindForm}
end;
procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
Close; { }
end;
end.
InputForm
. .
Enter.
Unit InputUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TInputForm = class(TForm)
InputEdit: TEdit;
procedure InputEditKeyPress(Sender: TObject; var Key: Char);
procedure FormActivate(Sender: TObject);
end;
var InputForm: TInputForm;
implementation
uses Base Unit;
{$R *.DFM}
procedure TInputForm.FormActivate(Sender: TObject);
begin
InputEdit. SetFocus;
end;
procedure TInputForm.InputEditKeyPress(Sender: TObject; var Key: Char);
begin
ifKey=#13 then
407
:
begin
:=#0;
Base. Open (InputEdit. Text);
ModalResult:= mrOK;
{ }
end;
end;
end.
AddForm . . 5.10
AddForm,
.
, ,
Enter,
, .
:
.
UnitAddUnit;
interface
uses
Windows Messages SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Enter/
'
Enter
J
1
Enter
J
. 5.10.
AddForm
408
type
TAddForm = class(TForm)
FamLabel: TLabel;
NameLabel: TLabel;
FonLabel: TLabel;
AddButton: TButton;
ExitButton: TButton;
FamEdit: TEdit;
NameEdit: TEdit;
FonEdit: TEdit;
procedure FamEditKeyPress(Sender: TObject; var Key: Char);
procedure NameEditKeyPress (Sender: TObject; var Key: Char);
procedure FonEditKeyPress(Sender: TObject; var Key: Char);
procedure FormActivate(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
end;
var
AddForm: TAddForm;
implementation
uses Base Unit;
{$R *.DFM}
procedure TAddForm.FormActivate(Sender: TObject);
begin
ExitButton, SetFocus;
end;
procedure TAddForm.AddButtonClick(Sender: TObject);
begin
FamEdit.SetFocus;
end;
procedure TAddForm.FamEditKeyPress(Sender: TObject; var Key: Char);
begin
ifKey=#]3 then
begin
Key:=#0;
NameEdit. SetFocus;
end; ^
end;
procedure TAddForm.NameEditKeyPress(Sender: TObject; var Key: Char);
begin
ifKey=#13 then
begin
Key:=#0;
409
FonEdit.SetFocus;
end;
end;
procedure TAddForm.FonEditKeyPress(Sender: TObject; var Key: Char);
begin
ifKey^#13 then
begin
Key:=#0;
Base,Add(FamEdit. Text,NameEdit. Text,FonEdit. Text);
ExitButton. Set Focus;
end;
end;
procedure TAddForm.ExitButtonClick(Sender: TObject);
begin
ModalResult:= mrOK;
{ }
end;
end.
FindForm .
Enter.
unit FindUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TFindForm = class(TForm)
FamLabel: TLabel;
NameLabel: TLabel;
FonLabel: TLabel;
FindButton: TButton;
ExitButton: TButton;
NextButton: TButton;
FamEdit: TEdit;
NameEdit: TEdit;
FonEdit: TEdit;
procedure FamEditKeyPress(Sender: TObject; var Key: Char);
procedure NameEditKeyPressfSender: TObject; var Key: Char);
procedure FormActivate(Sender: TObject);
procedure FindButtonClick(Sender: TObject);
procedure NextButtonClick(Sender: TObject);
procedure ExitButtonClickfSender: TObject);
410
private
Procedure Show;
end;
var
FindForm: TFindForm;
implementation
uses Base Unit;
{$R *.DFM}
Procedure TFindForm. Show;
begin
FamEdit, Text: =Base/amily;
Name Edit. Text: =Base. name;
FonEdit. Text: =Base. telefon;
end;
procedure TFindForm.FormActivatefSender: TObject);
begin
ExitButton. SetFocus;
end;
procedure TFindForm.FindButtonClickfSender: TObject);
begin
FamEdit. SetFocus;
end;
procedure TFindForm.FamEditKeyPressfSender: TObject; var Key: Char);
begin
ifKey=#}3 then
begin
Key:=#0;
NameEdit. SetFocus;
end;
end;
procedure TFindForm.NameEditKeyPress(Sender: TObject; var Key: Char);
begin
ifKey=#13 then
begin
Key:=#0;
if Base.Find(FamEdit. Text,NameEdit. Text) then
begin
Show;
NextButton. SetFocus;
end
else
begin
MessageDlg( 'Hem daHHbix\mtInformation,[mbOk],0);
411
[JpiuioDtceHue
ExitButton, SetFocus;
end
end;
end;
procedure TFindForm.NextButtonClick(Sender: TObject);
begin
if BascFindNext then
begin
Show;
Next Button, SetFocus;
end
else
begin
MessageDlg( 'Hem daHHbix\mtInformationJmbOkJ,0);
ExitButton. SetFocus;
end
end;
procedure TFindForm.ExitButtonClickfSender: TObject);
begin
ModalResult:= mrOK;
{ };
end;
end.
Delphi
.
program BookProject;
uses Forms,
MainUnit in 'MainUnit.pas' {MainFormj,
InputUnit in 'InputUnit.pas' {InputForm},
AddUnit in 'AddUnit.pas' {AddForm},
FindUnit in FindUnit.pas' fFindForm},
Base Unit in 'BaseUnit.pas';
{$R *.RES}
begin
Application. Initialize;
Application. CreateForm(TMainForm, MainForm);
Application. CreateForm(TInputForm, InputForm);
Application. CreateFormfTAddForm, AddForm);
Application. CreateFormfTFindForm, FindForm);
Application. Run;
end.
412
1. . - . .:
, 1997.
2. . -
C++. .: ; .: , 1998.
3. . . .: , 1989.
4. ., ., . . .: , 1975.
5. .., .., .. -
. .: - . .. , 2001.
6. ., ., . : . .:
, 2000.
7. . . .: , 1982.
8. .. -. - . .: -
, 1992.
9. ., . . .:
, 1980.
212
- 213
- 212
15
- 18, 19,20
- 60, 69
- 15, 16, 17
- 61,71
- 17
38
11, 303, 309
- 10, 150, 155
238
- 246
- 238
- 247
218
- 220
- 218, 220
- 218, 220
- 219
136
- 140
- 138, 139
, 305, 315
- 307, 327
- 354
- 306
414
308, 330
77
- 79, 80
- 84, 85
150
93
- 96, 97
- 125
- 59, 83
-
, 89
-
94
- 81
- 24, 172 .
- 24, 104, 150
- 63, 64
- 13
- 99
- 179
- 97
- 102
- 110
- 244
- 65, 68
- 90, 91
- 65
156
127
- 128
- 129
..
.. , ..
.. , .
..
16.05.2002. 70x100/16. .
. . . . 33,8. .-. . 33,25. 5000 .
1433
. ..
105005, , 2- , 5
-
. 432980, . , . , 14
308, 332
306, 327
- 308, 336, 344
& 303
- 316, 348
- 340
56
- - 42
- 69
- 33, 37
- 35
- 58
- 40
- 50
146
- 147
- 147
- 162
- 159, 370
- 157
- 147
- 340
- 166
- 146
179, 183
- 180, 184
13, 33
- 145
- 36
- 145
- 37
- 87
144, 145
- 161
12
177, 180
- 85
- 99
- 120
10, 17
- - 11
14, 312, 365
- 20, 312
144, 145
168
- 177
- 175
- 168, 173
28
28
- - 28
- 28, 29
224, 226
113
52
33
- 33, 34
- 39, 217, 331
- 41, 163, 330, 335
- 41
35, 45
214
188, 190
- 207
- 192, 196
- 191,201
415