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

.., .., ..

Free Pascal Lazarus

2009

004.43
ISBN 978-966-8248-26-9
:

47

.. , ,
.
.. -
,

.

.., .., ..
Free Pascal Lazarus. - .:
, , 2009. - 503 .


, 7
30 2009 .
: ,
, ..
.
Free Pascal Lazarus. Free Pascal Lazarus .
.
, .
. -
Lazarus. 25
.
, , ,
, Free Pascal Lazarus.
, ,
GNU FDL.
ISBN 978-966-8248-26-9

.., .., .., 2009

.., .., .. Free Pascal Lazarus

......................................................................................................7
.................................................................................10
1 Free Pascal........................11
1.1 ...................................................11
1.2 Free Pascal..........................................13
1.2.1 Free Pascal.............................17
1.2.2 Free Pascal .......................................................................................................18
1.3 Geany............................................................19
1.4 Lazarus..........................20
1.4.1 Lazarus Linux................................................22
1.4.2 Lazarus Windows...............25
1.4.3 Lazarus...........................................................................28
1.4.4 Lazarus.............................................................30
1.4.5 .............................................................................34
1.4.6 Lazarus..........................................................34
1.4.7 ................................................................43
1.4.8 ................................................................43
1.4.9 Lazarus...................................................44
1.4.10 ..............................................................53
1.4.11 Lazarus..............................59
1.4.12 - ......................................61
2 Free Pascal.................64
2.1 Lazarus............................................................64
2.2 ............................................65
2.3 .............................................................................67
2.4 Free Pascal...........................................................68
2.4.1 ........................................................69
2.4.2 ...................................................69
2.4.3 ....................................................70
2.4.4 -.........................................................................70
2.4.5 ..........................................................71
2.4.6 ..............................................71
2.4.7 ....................................................71
2.4.8 ...................................................................72

.., .., .. Free Pascal Lazarus

2.4.9 .......................................................72
2.4.10 ................................................................................75
2.5 .................................................................76
2.5.1 ....................................................78
2.5.2 ..............................................................80
2.5.3 ..............................................................80
2.5.4 .....................................................81
2.6 ...................................................................81
2.7 ........................................94
3 ........................................................................96
3.1 ...............................................96
3.2 .................................................................97
3.3 .......................................................................98
3.4 ......................................................................98
3.4.1 ifthenelse.........................................98
3.4.2 case ........................................................117
3.5 . Lazarus...........121
3.6 ..........................................................................125
3.6.1 while .. do........................126
3.6.2 repeat until..................127
3.6.3 for do......................................................129
3.7 ...............................................132
3.8 ..................................132
3.9 Lazarus...................147
3.10 ....................................156
3.10.1 ..................................................156
3.10.2 .........................................................161
4 ....................................................................................164
4.1 .
..........................................................................................164
4.2 .
......................................................................................165
4.3 ....................................................................................166
4.4 ........................................................................................171
4.5 ........................176
4.6 .................................................................198
4.7 ...................................202
4.7.1 -...........................................................202

.., .., .. Free Pascal Lazarus

4.7.2 ................................................................202
4.8 ......................................................................206
4.9 ......................................210
5 Free Pascal ............213
5.1 ........................................................213
5.2 ......................................................................214
5.3 ............................................................216
5.4 - ..................................................217
5.4.1 -...................................................217
5.4.2 - ...............221
5.5 .........230
5.6 .........231
5.7 ...............................................232
5.7.1 .........................................232
5.7.2 .............................................................235
5.8 ....................................................237
5.9 ..........................................................241
5.10 ..........242
5.11 ..................................................................................................245
5.11.1 ...246
5.11.2
getmem freemem............................................................................249
5.12 ....................................................................252
5.13 ....................................282
6 Free Pascal......................................................285
6.1 - ......................................................................287
6.2 .........................300
6.3 ...............................................................341
6.4 ......................................344
7 Free Pascal.......................................347
7.1 .................................................................................347
7.2 ........................................348
7.2.1 AssignFile................................................................348
7.2.2 reset, rewrite...........................................................349
7.2.3 loseFile..................................................................349
7.2.4 rename.....................................................................350
7.2.5 erase.........................................................................350

.., .., .. Free Pascal Lazarus

7.2.6 eof...............................................................................350
7.2.7 ...............................................350
7.3 Free Pascal......................................376
7.4 Free Pascal.....................390
7.5 ......................................396
8 ........................................................399
8.1 .............................................................................399
8.2 ............................................................................405
8.3 ..........415
8.4 ..........416
9 - .............................421
9.1 .......................................................................421
9.2 ...............................................................................432
9.3 ....................................................437
9.4 ...................................................................451
9.5 ......................................467
10 Free Pascal......................................................................471
10.1 Lazarus...................................................471
10.2 ................................................................482
10.3 ....................................495

.., .., .. Free Pascal Lazarus

,
.
,
() .
Pascal, ,
. ,
Pascal. Pascal Delphi, c .
Free Pascal,
.
Free Pascal ,
,
.
.
Free Pascal Linux, Windows. ,
Lazarus. Lazarus Delphi.

. , - , .
, -. . .
, Linux
Windows .

.., .., .. Free Pascal Lazarus

.

Free Pascal, .
(, , ) Free Pascal. : -. Free Pascal, .
. -. .
.

. . . .
.
Free Pascal. .

Free Pascal Linux Windows.
-. .
. Free Pascal.
- Free Pascal.
Lazarus,
. .

.., .., .. Free Pascal Lazarus

25 , ,
.

www.teacher.dn-ua.com,
www.teacher.ucoz.net.
.
.., .., ..
, 2009 .

.., .., .. Free Pascal Lazarus

10


,

,
- . .. 17 . ,
, 65
. . .. 60 . ,
, -,
.

.
.. 15 . ,
40 . ,
40 . , .
, -
. 30
. . . 14 . , .

.., .., .. Free Pascal Lazarus

11

1 Free

Pascal

Free Pascal. Free Pascal Pascal,
60- XX .
. Pascal,
, . ,
.
Pascal , .
1.1
:
1. . ,
.
2. . - ( Free Pascal)
.
3. .
. .
( ) . .
, , ,
, . , ,
, .
4. . .
.
, -

.., .., .. Free Pascal Lazarus

12

Pascal1 .

. :
,

;
,
,
.
,
.
Pascal 2.
Pascal.
1. , 3
, ,
( Windows .obj, Linux
.o).
( )
.
2.

. , , . .

Pascal, Pascal Borland (Borland Pascal), Free Pascal
Lazarus.
1 .
2 .
3 Pascal () (, sin(x),
cos(x) .) .

.., .., .. Free Pascal Lazarus

13

1.2 Free Pascal


Free Pascal
Linux. Linux Synaptic. Ubuntu Synaptic. ALT Linux
Synaptic.
Synaptic . 1.1.
,
( 4). Ubuntu Linux
. ALT Linux
.
Synaptic (. . 1.1)
. fpc (. . 1.2).
Free Pascal,
Synaptic fpc (Free Pascal
Compiler Meta Package) (
)
, .
.
fp Free Pascal
fpc fp-ide.
Linux fp. . 1.3 Free Pascal
Linux.
Free Pascal Windows
http://www.freepascal.org/down/i386/win32.var . Free Pascal
.
Next,
Back, Cancel.
Free Pascal.
.
4 , .

.., .., .. Free Pascal Lazarus

14

Browse.... ,
.
: Full
Installation (), Minimum Installation (), Custom
Installation ( ),
, ,
, Free Pascal,
Install. , Cancel.
Free Pascal Windows
: Free Pascal
Free Pascal. , . 1.4.
Free Pascal,
.
Free Pascal .
,
Pascal,
fpc name.pas
fpc Free Pascal, name.pas . Linux name (
Windows name.exe).
fpc (
make).
Free Pascal :
,
,
. .
.
, .

.., .., .. Free Pascal Lazarus

15

1.1: Synaptic

.., .., .. Free Pascal Lazarus

1.2: Free Pascal Synaptic

1.3: Free
Pascal Linux

1.4: Free Pascal

16

.., .., .. Free Pascal Lazarus

17

Free Pascal
. , .
.
1.2.1 Free Pascal
Free Pascal . (File New)
(File Open) ,
( ).

F10, Esc. ,
, .
Free Pascal ,
. .
() Free
Pascal .

Edit:
Copy (Ctrl+C) ;
Cut (Ctrl+X) ;
Paste (Ctrl+V) ;
Clear (Ctrl+Del) ;
Select All ;
Unselect .
Copy Cut .
Shift (). ,
Edit Undo Redo, .
, :
Ctrl+K+B ;
Ctrl+K+K ;
Ctrl++ ;
Ctrl+K+Y ;

.., .., .. Free Pascal Lazarus

18

Ctrl+K+C , ;
Ctrl+K+V , ;
Ctrl+K+W ;
Ctrl+K+R ;
Ctrl+K+P ;
Ctrl++ ;
.
Free Pascal
File :
New ;
Open (F3) ;
Save (F2) ;
Save As ;
Exit (Alt+X) ;

NONAMEOO.PAS (NO NAME ).

.
. Save As .
,
.
.
Free Pascal . Alt+i, i ( Alt+5
). Alt+0, ,
Enter.
1.2.2 Free Pascal
, .
Compile Compile ( Alt+F9).
. ,
.

.., .., .. Free Pascal Lazarus

19

- ,
, . .

Run Run ( Ctrl+F9),
,
. Free Pascal.
OC Windows
Alt+F5. .
Linux . Free Pascal
Geany (http://www.geany.org),
.
1.3 Geany
Geany
Linux5. Geany . Geany
Synaptic.
Geany.
1. Pascal (
) New (with
Template) Pascal source file.
(. 1.5), (. 1.6).
2.
. (F8). . (. 1.6) .
.
5 Geany Windows (http://www.geany.org/Download/Releases)

.., .., .. Free Pascal Lazarus

20

. ,
.
(error)
(warning). , .
3. (F5).
(. 1.7), .
Geany ( ) , .
. pas . 1.8. Compile
, %f , %e
.

Free Pascal . Linux Geany6.
(,
gedit, tea, kate .), .
Windows fp-ide.
1.4 Lazarus
Lazarus - .
, () ,
.

7 , .
.
, , .
6 .
7 , .

.., .., .. Free Pascal Lazarus

21

1.5: Geany c Free Pascal

.., .., .. Free Pascal Lazarus

22

. , Lazarus
,
.
Lazarus
, - ,
.
1.4.1 Lazarus Linux
Lazarus Synaptic (. . 1.1)
. (. . 1.9)
(Lazarus, fpc, fpc-source) .
Lazarus Free Pascal,
Lazarus, fpc, fpc-source (
) , .
Synaptic ,
Lazarus. .
Lazarus
. Lazarus8.
. Linux (, Ubuntu 8.10 )
Lazarus .
, Lazarus, :
http://www.freepascal.ru/article//lazarus/20080316091540/,
http://forum.sources.ru/index.php?showtopic=243159,
http://forum.ubuntu.ru/index.php?topic=18539.0;all.
, LANG=C startlazarus.
, ,
.
8 , Lazarus Linux
.

.., .., .. Free Pascal Lazarus

23

1.6: Geany c Free Pascal

.., .., .. Free Pascal Lazarus

1.7:

1.8:
Free Pascal

1.9:
Lazarus

24

.., .., .. Free Pascal Lazarus

25

1. Lazarus c 9.
2. Tools Conigure Build Lazarus... .
Conigure Build Lazarus Quick
Build Options
Build Options Build All, LCL interface IDE gtk2 (betta), Build , Lazarus .
3. Lazarus ( startlazarus)
Lazarus.
, Lazarus
Synaptic,
http://sourceforge.net/project/showfiles.php?group_id=89339 .

http://freepascal.ru/article//lazarus/20080316091540.
1.4.2 Lazarus Windows
Lazarus Windows.
http://sourceforge.net/project/showfiles.php?group_id=89339.
Lazarus
. ,
Lazarus Setup.
(. 1.10),
. 10.
(. 1.11) .
. , .
9 Ubuntu sudo LANG=C startlazarus
10 .

.., .., .. Free Pascal Lazarus

26

1.10: .
.
(. 1.12)
Lazarus.
. .
11.

1.11:
Lazarus

11
.

.., .., .. Free Pascal Lazarus

27

1.12: Lazarus
(. 1.13). .
, . . , 12, Lazarus13.
,
Lazarus, ,
, .
.
, . .
Lazarus
Lazarus Lazarus.
12 .
13 .

.., .., .. Free Pascal Lazarus

28

1.13:

1.4.3 Lazarus
. 1.15 ,
Lazarus. . ,
.
, ,
. 1.14.

1.14:

.., .., .. Free Pascal Lazarus

29

1.15: Lazarus

.., .., .. Free Pascal Lazarus

30


.
() , . ,
,
. ,
, .
1.4.4 Lazarus
, Lazarus, .
.
Lazarus
.
:
, , ...;
, ,
;
, ,
;
, ;
;
;
.
, , .
:
,
;
,
, , ;
,
, ;
,
;
.

.., .., .. Free Pascal Lazarus

31

Lazarus.

,
14,
.
... (. 1.16),
, .
... ,
.

1.16:
. , - , .
, . , .

14 , .
.

.., .., .. Free Pascal Lazarus

32

. :
,
( . .
1.4.8);
, ( . . :
);
;
LazDoc ;
.
. .
... ... .
. /
, .

. ,
.
.
, ,
.

:

;
,
, ;
,
..., ;
,
..., ..
, , :

.., .., .. Free Pascal Lazarus

33

;
;
;
(,
);

;
;
;
- ,
;
;
-
;
+... -
;
\ - /
,
;

/ , ;
- ;
, ; .

.
15
. .

15 , . .

.., .., .. Free Pascal Lazarus

34

Lazarus
.
, .
.

.
1.4.5
(. 1.14) .
, . 16.
,
,
.

(. 1.17) ...
1.4.6 Lazarus
(. 1.15)
(. 1.18) .
. - /, F12
.

,
.
, , , .
,
.
,
, .
16 .

.., .., .. Free Pascal Lazarus

1.17:

1.18:

35

.., .., .. Free Pascal Lazarus

36

, Lazarus , .
(. 1.19, 1.20),
....
, Lazarus .

...(. 1.21).
() ,
() Ok.

1.19: Windows

.., .., .. Free Pascal Lazarus

37

1.20: Linux
1.21:

.., .., .. Free Pascal Lazarus

38

...(. 1.22) .

1.22: ,
Ubuntu Linux
Fixed
Misc, ISO 10646-1 (. 1.23).
, Lazarus .

.
, b, ,
begin ... end. (. 1.24, 1.25),

.... , ,

.., .., .. Free Pascal Lazarus

1.23: Ubuntu

1.24:
Windows

39

.., .., .. Free Pascal Lazarus

40

( ) b begin ... end


. ... . ,
b Enter.
, .
(. 1.25) .
, Ok ,
.

1.25:
Linux
, , .
,
(. 1.26) . , .

.., .., .. Free Pascal Lazarus

41


. . , ,
.

1.26:

,
, . ,
repeat ... until, , r. :
;
(. 1.26)
r,
repeat until ;
(. 1.27, 1.28) r - repeat until;
, ,
repeat until;;
Ok .
. , , .
, .
, ,
.

.., .., .. Free Pascal Lazarus

1.27: Windows

1.28: Linux

42

.., .., .. Free Pascal Lazarus

43

1.4.7
17 (.
1.15). ,
(. 1.29).

1.29:
,
.
,
, , , ..

:
, ;
,
.
.
Standard, .
, .
1.4.8
. ,
. . 1.30
.
: , , . , . , .
. ,
, . , .
17 () , ()
.

.., .., .. Free Pascal Lazarus

44

, ,
. .
, Caption () , Height ()
Width () ,
Enabled ()
True () False (). . ,
Font ().
+. ,
,
+ 1.30:
.


. , ,
.
(, Font).

(, Enabled).
1.4.9 Lazarus
Lazarus :
,
Free Pascal, .
, , . , .

, , . .
.

.., .., .. Free Pascal Lazarus

45

.... (. 1.31, 1.32)


.
.

1.31:
Linux

1.32: Windows

,
.
Unit1 (. 1.33, 1.34).
Primer_1 ( ( )),
. Unit1.pas, .
(. 1.35, 1.36),
.
Project118, .
. Primer_1 (. 1.37, 1.38)
Unit1.pas, Unit1.lfm19,
Form1, Project1.lpn
Project1.lpi, .
18 Unit1 Project1 .
19 Unit1.

.., .., .. Free Pascal Lazarus

1.33: Windows

1.34: Linux

46

.., .., .. Free Pascal Lazarus

1.35:
Windows

1.36:
Linux

47

.., .., .. Free Pascal Lazarus

48

1.37: Windows

1.38: Linux
, . - .
.
Form1. .
Caption (). Form1. -

.., .., .. Free Pascal Lazarus

49

1 (. 1.39).
1 (. 1.40). , Height () Width (), ,
,
.

1.39:
1.40:
Caption

Position (
). ,
(. 1.41).
poScreenCenter,
.
, .
.
(. 1.29) Tbutton.
, :
, .
, . 1.42.
: Form1 Button1. ,
.
Button1 Caption Height,
Width. !,
135 , 25 .
( ).

.., .., .. Free Pascal Lazarus

1.41:
Position

50

1.42:

, ,
.
, F9
(. 1.43).
, . 1.44.

1.43:

Lazarus

1.44:

, . ,
. , , . , :

.., .., .. Free Pascal Lazarus

51

unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls,
Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
initialization
{$I unit1.lrs}
end.
. ,
. , - , , .
,
!. , ,
: ! !.
,
(
) . ,
Button1 , . , . OnClick
(. 1.45).

:

.., .., .. Free Pascal Lazarus

52

procedure TForm1.Button1Click(Sender: TObject);


begin
end;
, .
TForm1.Button1Click:
Form1 Button1
Click. , begin end, 1.45: - OnClick
.
begin end :
Button1.Caption:='! !';
.
, . :
(:=) Caption Button1 '! !'. , . , :
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Caption:='! !';
end;
, , (. 1.46).

.
1.46:

.., .., .. Free Pascal Lazarus

53

1.4.10
, . . ,
. ,
.
. :
, , 1 = 40
= 16.38 .
,
( ) ,
.
,
..., Primer_2
...
Standard . Label.
. Edit.
, , .
Button. .
, . 1.47.

1.47:

.., .., .. Free Pascal Lazarus

54

. Label2 Label3 , , Label4 .


Edit1 Edit2 : .
Button1 Label4.

. 1.1-1.4.
1.1

Caption


Height
230
Width
400
Font.Name Arial
Font.Size 10

1.2.
Label1 Label2 Label3 Label4
Caption
-

:
Height 15
15
15
15

Width
60
30
35
85

Top
20
50
105
25

Left
25
115
115
200

.., .., .. Free Pascal Lazarus

55

1.3.

Edit1
Edit2

Text


Height
25
25

Width
135
135

Top
40
95

Left
175
175

1.4.


Caption


Height
25

Left
200

Top20
150

Width
80

,
. 1.48.

1.48:

.
. Button1 OnClick, Button1
. begin end 20 Top Left
.

.., .., .. Free Pascal Lazarus

56

, :
procedure TForm1.Button1Click(Sender: TObject);
var
pud, funt: integer; kg: real;
begin
pud:=StrToInt(Edit1.Text);
funt:=StrToInt(Edit2.Text);
kg:=pud*16.38+funt*16.38/40;
Label4.Caption:=' :
'+FloatToStr(kg);
end;
.
1. . procedure TForm1.Button1Click,
,
.
2. (var
variable );
3. pud funt.
21.
4. kg.
5. (begin ).
6. , . Text Edit1 . (, '360' ),
, StrToInt
. pud. :=
. , a:=3.14 : a 3.14.
3.14:=a .
7. Edit2
funt. 21 .

.., .., .. Free Pascal Lazarus

57

, ,
.
8. ,
kg. ,
, , +.
, . ,
, , .
9. Caption Label4.
, . ' :', kg. + () . , kg , FloatToStr.
.
10. (end ).

. . .
.
. ( ).
. 1.49.
,
22, .
, .
, ,
() () ( . Linux, .obj
Windows).
Ctrl+F9.
,
.
22 , .

.., .., .. Free Pascal Lazarus

58

1.49:
,
, , .
( - ) .
( - )
, Linux ./project1, Windows
projec1.exe. . 1.50 .
,

.
,

. ,
.
1.50:
(Ctrl+F2).

.., .., .. Free Pascal Lazarus

59

, , .
(Ctrl+F11), .lpi ( project1.lpi).
1.4.11 Lazarus
Lazarus
, Free Pascal
. .
, ...,
(. 1.31, 1.32)
.

(. 1.51),
.
Free
Pascal ,
1.51: - .

program
. (. 1.51) Project1.
.
.
, , , . . 1.51 ,
uses. . , . SysUtils,
, Classes, .

.., .., .. Free Pascal Lazarus

60

,
. begin end . ,
.
.
, .
, . ,
,
, .
. . : -
,

180 , 18060 .

:
program Project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
var
gradus,minuta:integer; radian: real;
begin
write('gradus=');
readln(gradus);
write('minuta=');
readln(minuta);
radian:=gradus*pi/180+minuta*pi/(180*60);
writeln('radian=', radian);
end.
, , ,
, .

.., .., .. Free Pascal Lazarus

61

:
gradus=165
minuta=30
radian=2.8885199120506E+000
, , ,
( ):
Var
// .
gradus,minuta:integer;
// .
radian: real;
:
begin
// .
// gradus=
write('gradus=');
// gradus.
readln(gradus);
// minuta=.
write('minuta=');
// minuta.
readln(minuta);
//.
radian:=gradus*pi/180+minuta*pi/(180*60);
// .
writeln('radian=', radian);
end. // .
,
. (read)
(write) .
1.4.12 -
read. :
read (x1, x2, , xn); readln (x1, x2, , xn);
x1, x2, , xn .
.

.., .., .. Free Pascal Lazarus

62

read, , .
,
,
(Enter). Enter.
readln read, ,
readln
readln . , Enter
, .
write
writeln. :
write(x1, x2, , xn); writeln(x1, x2, , xn);
x1, x2, , xn , , . , .
write writeln
. writeln,
.
, write('gradus=');
gradus=, ,
gradus,
readln(gradus);
gradus. writeln('radian=', radian);
: radian=
radian.
, # . # # # # # # # # # # # E # # #, # - 0 9. , , E, 10, ,
E. ,
0.35469000000-01=0.35469000000*10-1=0.035469,
-5.43286710000+02=-5.43286710000*102=-543.28671.

.., .., .. Free Pascal Lazarus

63

, .
write writeln :
write(:__:_);

, ;
__ ( ,
, ),
;
_ ,
.
,
gradus=165
minuta=30
radian=2.8885199120506E+000
, writeln('radian=', radian);
radian .

writeln('radian=', radian:5:3);
:
gradus=165
minuta=30
radian=2.889
radian (
).

.., .., .. Free Pascal Lazarus

64

Free Pascal
Lazarus Free
Pascal: , , , .
2.1 Lazarus
Lazarus ,
.
:
(.lpi);
(.lpr);
(.lrs);
(.lfm);
(.pas);

,
.
, , ,
, , , .
:
unit _;
// .
interface
// .
implementation
// .
end.
// .
unit, . , interface, , , :
interface
uses _;
type _;

.., .., .. Free Pascal Lazarus

65

const _;
var _;
procedure _;

function _;

implementation , (
, , ). Lazarus 23.
, Lazarus ,
Free Pascal, Geany.
. .
2.2
:
;
uses modul1, modul2, , moduln;
;
.
program, , (. . 2.3 ), , :
program my_prog001;
uses modul1, modul2, , moduln .
. , , uses.
:
;
;
;
23 . 4.

.., .., .. Free Pascal Lazarus

66

.
Free Pascal , ,
, .
Pascal , Free Pascal .
, ..,
. Free Pascal
:
program _;
uses modul1, modul2, , moduln;
const _;
type _;
var _;
begin
_;
end.
begin, Pascal, . Pascal (
). ; - . end.
,
, .
:
program _;
uses modul1, modul2, , moduln;
const _;
type _;
var _;
begin
_1;
_2;
...
end.

.., .., .. Free Pascal Lazarus

67

Free Pascal:
program one;
const a=7;
var b,c: real;
begin
c:=a+2; b:=c-a*sin(a)
end.
2.3
Free Pascal
:
A, B, C, x, y, z;
0, 1, 2, 9;
+ ,, /, =, <, >, [, ], ., (, ), ;, :, {, }, $, #, _, @,
, ^.
. ,
. , .. , . 24,
, .
, . .
, ABC, abc, Abc
. () .
. , . . .
// . {}
(* *). , {} (* *)
24 , , , , ,
.

.., .., .. Free Pascal Lazarus

68

.
:
{
!}
(* .*)
// ,
//
// .
2.4 Free Pascal

- .
: , , , . .
, ,
. (),
, . (), . ,
. . . Free
Pascal var:
var _: _;
, :
var _1,,_N: _;
:
var
// .
ha: integer;
// .
hb, c: real;
,
.
. :
const _ = ;

.., .., .. Free Pascal Lazarus

69

:
const
h=3;
// .
bk=-7.521; // .
c='abcde'; // .
.
2.4.1

. ,
, .
char.
:
var
c: char;
: '', 'b', '+'.
2.4.2
, , .
. 2.1.
2.1

Byte
0 .. 255
1
Word
0 .. 65535
2
LongWord
0 .. 4294967295
4
ShortInt
-128 .. 127
1
Integer
-2147483648 .. 2147483647
4
LongInt
-2147483648 .. 2147483647
4
Smallint
-32768 .. 32767
2
Int64
263 .. 263
8
Cardinal
0 .. 4294967295
4

:

.., .., .. Free Pascal Lazarus

70

var
b: byte;
i, j: integer;
W: word;
L_1, L_2: longint;
2.4.3

. mE p, m (
), p ( )25.
26, . :
36.142 + 2 = 36.142102 = 3614.2;
7.25E 5 = 7.25105 = 0.0000725.
Pascal .
. 2.2.
2.2

Single
1.5-45 .. 3.4E+38
78
4
Real
2.9E-39 .. 1.7E+38
15 16
8
Double
5.0-324 .. 1.7E+308
15 16
8
Extended 3.4-4932 .. 3.4E+4932
19 20
10
Comp
-263 .. 263
19 20
8
Currency -922337203685477.5808 .. 19 20
8
922337203685477.5807
:
var
r1, r2: real; D: double;
25 , , , .
26 .

.., .., .. Free Pascal Lazarus

71

2.4.4 -
- TDateTime .
,
, .
2.4.5
:
(true) (false). Pascal
boolean. , Lazarus,
. 2.3.
2.3

Boolean
1
ByteBool
1
WordBool
2 a
LongBool
4 a
:
var
FL: boolean;
2.4.6

, Lazarus . type:
type __ = _;
,
:
var _: __;
.
2.4.7

, :
var _:(_1,_2,,_N);
, , . :

.., .., .. Free Pascal Lazarus

72

var
animal: (fox, rabbit);
color: (yellow, blue, green);
:
// .
type
year_times = (winter, spring, summer, autumn);
// .
var yt: year_times;
2.4.8

:
var _: _ .. _;
,
, . ,

. :
var
date: 1..31;
symb: a..h;
:
type
//
// .
Week_days = (Mo, Tu, We, Th, Fr, Sa, Su);
//
// .
Working_days = Mo.. Fr
// .
var
days: Working_days;
2.4.9
. Free Pascal ,
, , .
27.
27 . 5.

.., .., .. Free Pascal Lazarus

73

. array of:
: array [_] of _;
:
;
_ .
; ; , ,
, :
[1_..1_,
2_..2_, , ]
:
var
// 10 .
a:array [1..10] of byte;
//
//(3 , 3 ).
b:array [1..3, 1..3] of real;
.
, :
type
//
// .
massiv=array [0..4, 1..2, 3..5] of word;
// .
var
M: massiv;

, (, ),
:
_[_]
: a[5], b[2, 1], M[3, 2, 4].
. Lazarus , , .

.., .., .. Free Pascal Lazarus

74

. :
_: string;
:
_: string[_];
:
const S=;
var
Str1: string;
Str2: string[255];
Stroka: string[100];
, , 255 . Str1 Str2 .
28 ,
, .
.
record end:
_ = record _ end;
, _ , _ . :
// .
//
//
// .
type
student = record
name: string;
age: byte;
end;
var
//
// .
a, b, c: student;

:
_._
28 . .

.., .., .. Free Pascal Lazarus

75

:
a.name:=Ivanov Ivan;
a.age:=18;
b.name:=a.name;
with _ do :
with a do
begin
name:=Petrov Petr;
age:=19;
end;

. 0
255. , , .
set of:
_ = set of __;
:
type TwoNumbers = set of 0..1;
var
Num1, Num2, Num3: TwoNumbers;
29
.
( ,
). , . Lazarus :
__ = file of _;
:
__ = file;
:
__ = TextFile;
:
var
f1: file of byte;
f2: file;
f3: TextFile;
2.4.10
,
_: _
29 . 7 .

.., .., .. Free Pascal Lazarus

76


_ . . ,
. ,
, .
. .
30 ,
, ( ).
, . ,
:
var _: ^;
. :
var p: ^integer;
// , p
// int
//, p,
// integer.
Free Pascal , - . pointer:
var _: pointer;
:
var x, y: pointer;

,
, .
2.5

(, ,
), ,

a+b*sin(cos(x)).
30 . 5.11

.., .., .. Free Pascal Lazarus

77

. 2.4 Free Pascal.


2.4. Free Pascal

/- /

/- /

/- /

/-

div

mod

not
/ /
and
/ /
or

/ /
xor
/ /
shl

shr

in

<

/-
/
>

/-
/
<=

/-
/
>=

/-
/
=

/-
/
<>

/-
/

.., .., .. Free Pascal Lazarus

78

, , . Free Pascal
:
1.
not.
2.
*, /, div, mod, and, shl, shr.
3.
+, , or, xor.
4.
=, <>, >, <, >=, <=.

.
.
2.5.1
+, , *, / . .
( ):
div ( , ), , 17 div 10=1;
mod , , 17 mod 10=7.
: and, or, xor, not, shl, shr.
.
(and)31. ,
:
1 and 1=1, 1 and 0=0, 0 and 1=0, 0 and 0=0.
, =14 =24,
=0000000000001110 =0000000000011000. A and B 0000000000001000 8 (. 2.1). , A&B=14&24=8.

2.1:
A and B
31 .

.., .., .. Free Pascal Lazarus

79

(or)32. , :
1 or 1=1, 1 or 0=1, 0 or 1=1, 0 or 0=0.
, =14 =24
A or B=30 (. 2.2).

2.2:
A or B
(xor). , xor :
1 xor 1=0, 1 xor 0=1, 0 xor 1=1, 0 xor 0=0.
(not).
. not (. 2.3).

2.3: not A
(M shl L). M L . 15 shl 3. 15
1111. 3 1111000.
120. , 15 shl 3 =120 (. 2.4).

2.4: 15 shl 3

32

.., .., .. Free Pascal Lazarus

80

, , , . , M shl L
M 2 L.
(M shr L).
M L , M 2 L. , 15 shr 1=7
(. 2.5), 15 shr 3= 2.

2.5: 15 shr 1
2.5.2
.
: >, >=, <, <=, =, <>, in. true () false ().
>, >=, <, <=, =, <> (. . 2.4).
, in. , ,
. true (),
, .
2.5.3
Free Pascal
or, and, xor, not. true () false (). . 2.5 .
2.5.
A
B
Not A
A and B
A or B
A xor B
t
t
f
t
t
f
t
f
f
f
t
t
f
t
t
f
t
t
f
f
t
f
f
f
, .

.., .., .. Free Pascal Lazarus

81

2.5.4
.
@ .
:
Var
a:real; //
adr_a:^real; // real

// adr_a
// a
adr_a:=@a;
^ , :
Var
a:real; //
adr_a:^real; // real

// a
//, adr_a.
a:=adr_a^;
2.6
Free Pascal (. 2.6):
2.6.

abs(x)
//

sin(x)

cos(x)

arctan(x)

pi

exp(x)
ex
ln(x)

.., .., .. Free Pascal Lazarus

sqr(x)
sqrt(x)

82



int(x)

frac(x)

round(x)


trunc(x)


random(n)


0 n
, Math33
arccos(x)

arcsin(x)

arccot(x)

arctan2(y,x)
y/x
cosecans(x)

sec(x)

cot(x)

tan(x)

lnXP1(x)
(+1)
log10(x)

log2(x)


logN(n,x)

n
n.
n , n
( n
) 34:
33 ,
Unit Math.
34 : xn, n ln(x), .

.., .., .. Free Pascal Lazarus

83

nln X

X =e
, X 0
,
X n =e nln X , X 0
:

exp(n*ln(x)) X;

-exp(n*ln(abs(x))) X.
X
n, n k/l,
l . l ,
, ,
: .
X ,
1
xn= n .
x
, , , , X n,
n .
, ,
. 2.7.
2.7.


length(S)
S

concat(S1,S2, )


copy(S, n, m)

,
,

delete(S, n, m) ,
,

S1, S2,
n
S m-
n S m-

.., .., .. Free Pascal Lazarus

84

insert(S, n, m) ,
n

S m-
,

pos(S1, S2)
,

S2 S1
x

chr(x)
ord(c)


StrToDateTame(S)

s

StrToFloat(S)

s
StrToInt(S)

Val(S,X,Kod)


S X,

, Kod=0.


DataTimeToStr(V)



.
FloatToStr(V)



IntToStr(V)


FloatToStrF( V,

F,P,D)
V
F P, D.

FloatToStrF(V,F,P,D). . . 2.8 .

.., .., .. Free Pascal Lazarus

85

2.8. FloatToStrF

ffExponent
ffFixed
ffGtneral
ffNumber
ffCurency

, P ,
D : 1.2345+10.
, P , D
: 12.345.

, .
. ,
.
, ffNumber, .

FloatToStrF :
var
n:integer;
m:real;
St:string;
begin
n:=5;
m:=4.8;
St:=' .';
// chr(13) .
// m
// ,
// .
Label1.Caption:=''+St+' '
+IntToStr(n)+'.'+chr(13)+
' '+
FloatToStrF(m,ffFixed,4,2);
End;
:
. 5 .
4.80.
. 2.9 ,
.

.., .., .. Free Pascal Lazarus

86

2.9.

date

-

now

-

time

-

, , 35.
Free Pascal . 2.10.
2.10.

adr(x)
dispose()

x.
,
.
Freemen(p,size) ,
.
GetMem(p,size)
p size.
New(p)
p .
SizeOf(x)

x.


Lazarus.

.
2.1. a, b . S, P , (. 2.6).
35 , .

.., .., .. Free Pascal Lazarus

87

, , .
2.6: :
2.1
S = r rar br c ,
abc
r=
:
;
2
:
2
2
2
b c a
cos()=
;
2bc
b
:
sin()= sin a ;
a
:
= - (+);
:
1.
a, b ( a, b ).
2.
S, P, , .
3.
S, P, , .
1.
. , . ( Caption) . 2.11. ,
. 2.7.
2.11. (. 2.7)

Caption
Form1

Label1

Label2
a=
Label3
b=
Label4
=
Label5

Label6
alfa=
Label7
betta=
Label8
gamma=

.., .., .. Free Pascal Lazarus

88

Caption
Label9
P=
Label10
S=
Button1

, .

Lazarus , .

TForm1.Button1Click
2.7: - implementation:
2.1
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
interface. , .
. , begin end,
.
TForm1.Button1Click
:
procedure TForm1.Button1Click(Sender: TObject);
// :
// a, b, ;
// alfa, betta, gamma ;
//
S - ;
//
r -
// .
var a, b, c, alfa, betta, gamma, S, r: real;
begin
// Edit1, Edit2, Edit3
// ,

.., .., .. Free Pascal Lazarus

89

// StrToFloat()
//
// , b, c.
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
c:=StrToFloat(Edit3.Text);
// .
R:=(a+b+c)/2;
// ,
// :
// sqrt() .
S:=sqrt(r*(r-a)*(r-b)*(r-c));
// alfa .
// :
//
arccos() - x;
//
sqr() .
alfa:=arccos((sqr(b)+sqr(c)-sqr(a))/2/b/c);
// betta .
// :
//
arcsin() - x;
betta:=arcsin(b/a*sin(alfa));
// gamma .
//
// pi.
gamma:=pi-(alfa+betta);
// .
alfa:=alfa*180/pi;
betta:=betta*180/pi;
gamma:=gamma*180/pi;
//
// +
// FloatToStrF(),
//
// ,
//
// ,
// .
//

.., .., .. Free Pascal Lazarus

90

// .
Label6.Caption:='alfa='+
FloatToStrF(alfa,ffFixed,3,0);
Label7.Caption:='betta='+
FloatToStrF(betta,ffFixed,3,0);
Label8.Caption:='gamma='+
FloatToStrF(gamma,ffFixed,3,0);
// FloatToStrF()
// ,
// ,
// , .
//
// .
Label9.Caption:=' P='+
FloatToStrF(2*r,ffFixed,5,2);
Label10.Caption:=' S='+
FloatToStrF(S,ffFixed,5,2);
end;
, ,
.
. :
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls,
Graphics, Dialogs, StdCtrls, Math;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label10: TLabel;
Label2: TLabel;

.., .., .. Free Pascal Lazarus

91

Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var a, b, c, alfa, betta, gamma, S, r: real;
begin
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
c:=StrToFloat(Edit3.Text);
r:=(a+b+c)/2;
S:=sqrt(r*(r-a)*(r-b)*(r-c));
alfa:=arccos((sqr(b)+sqr(c)sqr(a))/2/b/c);
betta:=arcsin(b/a*sin(alfa));
gamma:=pi-(alfa+betta);
alfa:=alfa*180/pi; betta:=betta*180/pi;
gamma:=gamma*180/pi;
Label6.Caption:='alfa='+
FloatToStrF(alfa,ffFixed,3,0);
Label7.Caption:='betta='+
FloatToStrF(betta,ffFixed,3,0);
Label8.Caption:='gamma='+
FloatToStrF(gamma,ffFixed,3,0);
Label9.Caption:=' P='+

.., .., .. Free Pascal Lazarus

92

FloatToStrF(2*r,ffFixed,5,2);
Label10.Caption:=' S='+
FloatToStrF(S,ffFixed,5,2);
end;
initialization
{$I unit1.lrs}
end.
. 2.8 , ,
, .

.
Geany.
New with Tamplate
Pascal Source File.

2.8: - .
2.1
program pr3;
//
// , . .2.6.
uses math;
// .
var a,b,c,r,s,alfa,betta,gamma:real;
BEGIN
// .
writeln(' ');
readln(a,b,c);
// .
R:=(a+b+c)/2;
// ,
// :
// sqrt() .
S:=sqrt(r*(r-a)*(r-b)*(r-c));
// alfa .

.., .., .. Free Pascal Lazarus

93

// :
//
arccos() - x;
//
sqr() .
alfa:=arccos((sqr(b)+sqr(c)-sqr(a))/2/b/c);
// betta .
// :
//
arcsin() - x;
betta:=arcsin(b/a*sin(alfa));
// gamma .
//
// pi.
gamma:=pi-(alfa+betta);
// .
alfa:=alfa*180/pi;
betta:=betta*180/pi;
gamma:=gamma*180/pi;
// .
writeln(' =',S:6:2);
writeln('alf=',alfa:6:2,
' bet=',betta:6:2,' gam=',gamma:6:2);
end.
Geany (F8),
(F5). . 2.9 .

2.9:
2.1

.., .., .. Free Pascal Lazarus

94

2.7
Lazarus.
, .
1.
. .
2.
c . .
3.
d. S P .
4.
d . S .
5.
a, b, c.
, , .
6.
h. d. ,
. V
S.
7.
a S. c, b .
8.
S.
a, d S1 .
9.
c
. S
a.
10. D:
(x1,y1), B(x2,y2) C(x3,y3). .
11. . .
12. c . .
13. d. S
P.
14. d
. S .
15. b S.
.

.., .., .. Free Pascal Lazarus

95

16. P . .
19. P. a,
d S.
20. c
h. S .
21. : (x1,y1),
B(x2,y2) C(x3,y3). .
22. ,
S, h, . m .
23. .
n n .
24. . n n- .
25. h. .

.., .., .. Free Pascal Lazarus

96

3
- : if, case, while..do,
repeat..until, for..do. .
3.1
, 36. , , .
-. . ,
, .
, .
:

() (. 3.1). :
();

() (. 3.2). :
() () ;

, (. 3.3). , ;

(. 3.4). .
() .
: , .

36 - algorithmi, algorismus,
-.

.., .., .. Free Pascal Lazarus

97

3.1:

3.2: 3.3:
()
3.4:
()


,
(. 3.5).

(. 3.6).

(. 3.7).
, .
.
Free Pascal, .

3.5:

3.6:

3.7:

3.2
Free Pascal : . := .
.
:
_ := ;

.., .., .. Free Pascal Lazarus

98

, , .
. , , (), .
, a:=b ,
b.
a b , , b, .
3.3
Free Pascal,
, begin end:
begin
_1;
...
_n
end;
.
3.4
Free Pascal ,
, : if case. .
3.4.1 ifthenelse

, , , . - Free Pascal ifthen
else, :
if then _1 else _2;
ifthenelse , 37, _1 _2 Free Pascal.
37 : .

.., .., .. Free Pascal Lazarus

99

.
, .
(True), _1. , (False), _1 _2. , ifthenelse,
. 3.8.

3.8: if...then...else
, x y, :
write('x='); readln(x);
write('y='); readln(y);
if x=y then
writeln(' x y')
else
writeln(' x y');
, , , :
if then
begin
_1;
_2;

end

.., .., .. Free Pascal Lazarus

100

else
begin
_1;
_2;

end;
else , :
if then ;

if then
begin
_1;
_2;

_n;
end;
: ( ) , ,
, . . 3.9.
,
else :

3.9:
if

else

write('x=');
readln(x);
write('y=');
readln(y);
z:=0;
{ c
, x y.}
if (x<>y) then
z:=x+y;
{ z .}
writeln(' z=',z);

.., .., .. Free Pascal Lazarus

101

. :
else if,
else. ,
if _1 then
if _2 then
_
else _;
_ _2,
if _1 then
begin
if _2 then
_;
end
else _;
if _1.

: =, <>, <, >, <=, >=. and, or not.
Free Pascal , ,
.
, , [a, b]. :
if (x>=a) and (x<=b) then.

if x>=a and x<=b then


,
x>= (a and x) <=b.
if 38.
3.1. x. ,
. 3.10, y=f(x).
38 ,
Free
Pascal.

.., .., .. Free Pascal Lazarus

102

,
. 3.10,
:
4,
x2
y x = 1,
x1
2
x , 2 x1
:
1. .
2. x (
).

3.10:
3.1

3.
x
-2, . 4,
. 5.
4.

: y=4, . 8.
5.
x
1, . 6,
. 7.
6.

: y=1, . 8.
7.

2
: y=x .
8.
x y.
9.
.
-,

3.11: - - , 3.1
. 3.11.
Free Pascal :
var x,y: real; begin
write('x='); readln(x);
if x<=-2 then y:=4 else if x>=1 then y:=1
else y:=sqr(x);
writeln('x=',x:5:2,'
y=',y:5:2);end.

.., .., .. Free Pascal Lazarus

103

3.2. x y. (x; y) (. 3.12).


. 3.12, x=-1, x=3,
y=-2 y=4. (x; y)
,
: x -1, x3, y
-2 y 4. .
-,
, . 3.13. 3.12:
3.2
3.2 .

3.13: 3.2

.., .., .. Free Pascal Lazarus

104

var
x,y:real;
begin
write('x=');
readln(x);
write('y=');
readln(y);
if (x>=-1) and (x<=3) and (y>=-2) and (y<=4)
then
writeln(' ')
else
writeln(' ');
end.
3.3. ax2+bx+c=0.
: , b
.
: x1 x2
, .
: d, .
.
1.
.
2.
, b .
3.
d
2
d =b 4ac .
4.
d<0, .5, .6.
5.
.8.
b d
b d
6.
x1=
x2=
.
2a
2a
7.
x1 x2 .
8.
.
-, ,
. 3.14.
, :

.., .., .. Free Pascal Lazarus

3.14:
{ .}
var a,b,c,d,x1,x2: real;
begin
{ .}
writeln(' ');
readln(a,b,c);
{ .}

105

.., .., .. Free Pascal Lazarus

106

d:=b*b-4*a*c;
{ ,}
if d<0 then
{ , ,}
writeln(' ')
else
begin
{ x1, x2}
x1:=(-b+sqrt(d))/2/a;
x2:=(-b-sqrt(d))/(2*a);
{ .}
writeln('X1=',x1:6:3, ' X2=',x2:6:3)
end
end.
3.4.
ax2+bx+c=0.
: , b
.
: x1 x2
x1 x2 .
: d, .
:
1.
a, b c.
2.
d d =b24ac .
3.
. d0,
:
b d
b d
x1=
x2=
2a
2a
.
, ,
b d
b d
i
i
39
,
.
2a
2a
2a
2a
,
39 a+ib, a , b
, i 1 .

.., .., .. Free Pascal Lazarus

107

. x1 b

, x2
2a
d , x1+ix2 x1
2a
ix2.
. 3.15 - .

3.15: 3.4

.., .., .. Free Pascal Lazarus

108

-, . 3.15. 1 . 2
. 3
, ,
, 4 (
x1, x2), 5 ( x1+ix2,
x1-ix2). , ( 6, 7) ( 8).
, :
var a,b,c,d,x1,x2: real;
begin
writeln(' ');
readln(a,b,c);
d:=b*b-4*a*c;
if d<0 then
begin
{ ,
,
,
.}
writeln(' ');
{
.}
x1:=-b/(2*a);
{
.}
x2:=sqrt(abs(d))/(2*a);
writeln(' ',
a:1:2,x^2+,b:1:2,x+,c:1:2,=0);
{
x1ix2}
writeln(x1:1:2,'+i*(',x2:1:2,')');
writeln(x1:1:2,'-i*(',x2:1:2,')');
end
else
begin
{

.., .., .. Free Pascal Lazarus

109

x1, x2}
x1:=(-b+sqrt(d))/2/a;
x2:=(-b-sqrt(d))/(2*a);
{ .}
writeln(' ',
a:1:2,x^2+,b:1:2,x+,c:1:2,=0);
writeln('X1=',x1:1:2, ' X2=',x2:1:2)
end
end.
3.5.
ax3+bx2+cx+d=0.
ax 3bx 2cxd =0
(3.1)
a (3.1) :
3
2
(3.2)
x rx sx t=0
d
b
c
r = , s= , t= . (3.2)
a
a
a
r
x= y
: y 3 pyq=0 (3.3),
3
2
3
3sr
2r rs
p=

, q= t .
3
27 3
(3.3) 3
2
p
q
(. 3.1): D= .
3
2
3.1.


D0
1
2
D0
3
:
y 1=uv
uv uv
y2=

i 3
(3.4)
2
2
y3=

uv uv

i3
2
2

.., .., .. Free Pascal Lazarus

110

q
3 q
D , v=
D .
2
2
(3.1)
, . ,
:

3
y1 =2 cos ,
3
2
4
3
3
y2=2 cos
, y 3=2 cos
,
(3.5)
3
3
3
3
3

p
q .
=
, cos=
27
2
,
(3.3) (3.4),
(3.5). (3.3) (3.4) (3.5) r
x k = y k , k =1,2 ,3... 3
(3.1).
-
.3.16 - 3.17.

u=

3.16:

.., .., .. Free Pascal Lazarus

111

3.17: ()
(. 3.16 3.17). 1 ,

.., .., .. Free Pascal Lazarus

112

2-3 . 4 . 5 . , (3.5)
( 6-7).
(3.4) ( 9, 10). 8 11 .
40.
var
a,b,c,d,r,s,t,p,q,ro,fi,x1,x2,x3,u,v,h,g:real;
begin
{ .}
write('a=');readln(a);
write('b=');readln(b);
write('c=');readln(c);
write('d=');readln(d);
{
(3.2).}
r:=b/a; s:=c/a; t:=d/a;
{
(3.3).}
p:=(3*s-r*r)/3;
q:=2*r*r*r/27-r*s/3+t;
{
.}
d:=(p/3)*sqr(p/3)+sqr(q/2);
{ ,
then (3.5),
else (3.4)}
if d<0 then
begin
ro:=sqrt(-p*p*p/27);
40 u v .

q
3 q
3 q
D0, u=
D , v=
D .
2
2
2
q
3 q
3 q

D0, u= D, v= D .
2
2
2
, u v .

.., .., .. Free Pascal Lazarus

113

{
fi,
,
.}
fi:=-q/(2*ro);
fi:=pi/2-arctan(fi/sqrt(1-fi*fi));
{
x1, x2 x3}
x1:=2*exp(1/3*ln(ro))*cos(fi/3)-r/3;
x2:=2*exp(1/3*ln(ro))*
cos(fi/3+2*pi/3)-r/3;
x3:=2*exp(1/3*ln(ro))*
cos(fi/3+4*pi/3)-r/3;
writeln('x1=',x1:1:3,
' x2=',x2:1:3,' x3=',x3:1:3);
end
else
begin
{ u v
. }
if -q/2+sqrt(d)>0 then
u:=exp(1/3*ln(-q/2+sqrt(d)))
else
if -q/2+sqrt(d)<0 then
u:=-exp(1/3*ln(abs(-q/2+sqrt(d))))
else
u:=0;
if -q/2-sqrt(d)>0 then
v:=exp(1/3*ln(-q/2-sqrt(d)))
else
if -q/2-sqrt(d)<0 then
v:=-exp(1/3*ln(abs(-q/2-sqrt(d))))
else
v:=0;
{
.}
x1:=u+v-r/3;
{

.., .., .. Free Pascal Lazarus

114

.}
h:=-(u+v)/2-r/3;
g:=(u-v)/2*sqrt(3);
writeln('x1=',x1:1:3,' x2=',h:1:3,'+i*',
g:1:3,' x3=',h:1:3,'-i*',g:1:3);
end
end.
3.6. a, b 4+b+=0. .
: a, b, c.
: 1, 2, 3, 4.
y=x2
y2+by+=0
.
(. 3.18):
1.
a, b c
( 1).
2.
d ( 2).
3.
d < 0 ( 3), , (
4), y1 y2 ( 5).
4.
y1<0 y2<0 ( 6) , , ( 7).
5. y10 y20 ( 8),
y1 , y2 ( 9) (
10).
6. 4) 5) , y1. y10 ( 11), y1 ( 12), ( y20)
y 2 ( 13). ( 14).

.., .., .. Free Pascal Lazarus

115

3.18:

.., .., .. Free Pascal Lazarus

116

Free Pascal :
var
a,b,c,d,x1,x2,x3,x4,y1,y2: real;
begin
{ .}
writeln(' ');
readln(a,b,c);
{ .}
d:=b*b-4*a*c;
{ ,}
if d<0 then
{ }
writeln(' ')
{ 0,}
else
{ :
a,b,c ,
d ,
x1,x2,x3,x4 ,
y1,y2 ay^2+by+c=0.}
begin
{ .}
y1:=(-b+sqrt(d))/2/a;
y2:=(-b-sqrt(d))/(2*a);
{ <0,}
if (y1<0) and (y2<0) then
{ .}
writeln(' ')
{ 0,}
else if (y1>=0) and (y2>=0) then
begin
{ .}
x1:=sqrt(y1); x2:=-x1;
x3:=sqrt(y2); x4:=-sqrt(y2);
{ .}
writeln('X1=',x1:6:3,' X2=',x2:6:3);
writeln('X3=',x3:6:3,' X4=',x4:6:3);
end

.., .., .. Free Pascal Lazarus

117

{
1. y1<0 y2<0
2. y1>=0 y2>=0,
y1>=0}
else if (y1>=0) then
{ }
begin
x1:=sqrt(y1); x2:=-x1;
writeln('X1=',x1:6:3,'
X2=',x2:6:3);
end
else
{ y1>=0 , }
begin
x1:=sqrt(y2); x2:=-x1;
writeln('X1=',x1:6:3,'
X2=',x2:6:3);
end

end
end.
3.4.2 case
case , -
.
case of
__1: _1;
__2: _2;

__N: _N
else
_
end;
. __1, _1. __2, _2 . ,
_,
else.

.., .., .. Free Pascal Lazarus

118

(
char boolean), . _ , , .
, .
.
else ,
:
case of
__1: _1;
__2: _2;

__N: _N;
end;
, case . :
case of
__1: begin
_A;
_B;
end;
__2: begin
_C;
_D;
_E;
end;

__N: _N;
end;
3.7. , D, , 31
.
mod,
, , 1-
. ( R)

.., .., .. Free Pascal Lazarus

119

D , ,
, . , , . 3.19.
,
:
var d:byte;
begin
write(' D='); readln(D);
{ D 7.}

3.19: 3.7

.., .., .. Free Pascal Lazarus

120

case D mod 7 of
{ }
{ }
1: writeln('');
2: writeln('');
3: writeln('');
4: writeln('');
5: writeln('');
6: writeln('');
0: writeln('');end;end.

else. , R , .. 1, 2, 3, 4, 5, 6 0.
3.8. m
.

. m 12, 1 2,
, m 3 5, , m 6 8 , ,
m 9, 10 11 . ,
m
1 12 , , . case
else.
Var m:byte;
begin
write(' m=');
readln(m);
{ m.}
case m of
{ m }
{ .}
12,1,2: writeln('');
3..5: writeln('');
6..8: writeln('');
9..11: writeln('')

.., .., .. Free Pascal Lazarus

121

{ m
,
.}
else
writeln(' !!!');
end
end.
3.5 .
Lazarus
, , .
. , , , , , .
, , , .
MessageDlg, . :
MessageDlg(, _,
[_], );

, ;

_ (. 3.2);

_ ( ),
(. 3.3);

, , F1, , .
. 3.2. .


mtInformation

mtWarning

mtError

mtConfirmation

mtCustom

.., .., .. Free Pascal Lazarus

122

. 3.3. .


mbYes

mbNo

mbOk

mbCancel

mbAbort

mbRetry

mbIgnore

mbHelp

( 3.3).
Free Pascal.
Lazarus. 41 (. 3.20).


(Label1,
Label2,
Label3, Label4)
(Edit1, Edit2, Edit3).

3.20: -
Label542.
Button1.

:
, ;
a 43.

, .
Val(S,X,Kod), S X. 41 . .
42 Label5.Visible:=false.
43 .

.., .., .. Free Pascal Lazarus

123

, Kod ,
,
X. Kod S,
, X .
:
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,x1,x2: real;
kod1,kod2,kod3:integer;
begin
// .
// Edit1
//
//, ,
// kod1=0
// a.
val(Edit1.Text,a,kod1);
val(Edit2.Text,b,kod2);
val(Edit3.Text,c,kod3);
// ,
if (kod1=0) and (kod2=0) and (kod3=0) then
// .
//
// ,
if a=0 then
// .
MessageDlg('
', mtInformation,[mbOk],0)
else
//
begin
d:=b*b-4*a*c;
Label5.Visible:=true;
if d<0 then
Label5.Caption:=' '+
chr(13)+' '
else
begin

.., .., .. Free Pascal Lazarus

124

x1:=(-b+sqrt(d))/2/a;
x2:=(-b-sqrt(d))/(2*a);
Label5.Caption:='X1='+
FloatToStr(x1)+chr(13)+
'X2='+FloatToStr(x2);
end;

end
else
// ,
// .
MessageDlg(' ',
mtInformation,[mbOk],0);
end;
. 3.21 - 3.24.

3.21:
a 0

3.22:
-
,
( B)

3.23: 3x2+4x+5=0
( )

3.24:

.., .., .. Free Pascal Lazarus

125

, ,
. , . , , . 0 9,
. ,
.
BackSpace (#8 ). , , ,
.
OnKeyPress. Edit2
OnKeyPress, . :
// Edit2.
procedure TForm1.Edit2KeyPress(Sender: TObject;
var Key: Char);
begin
//
// ,
if not(Key in [#8,',','-','0'..'9']) then
begin
//
MessageDlg(' ',
mtInformation,[mbOk],0);
Abort; // .
end;
end;
3.6
, ,
. ,
, . ,
44. ,
, .
44 .
- ,
.
, ,
(http://ru.wikipedia.org/wiki/%D0%98%D1%82%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F).

.., .., .. Free Pascal Lazarus

126

. -, - ,
.
-, , .
Free Pascal
, : while, repeat
until for.
3.6.1 while .. do
. 3.25 - . , Free Pascal, :
while do ;
while .. do Free Pascal,
, , .
while . . (True), . , , .
. (False), .
,
:
while do
begin
_1;
_2;
3.25:

_n;
end;

.

sin x
y=e
cos x [0;] 0.1.
:

.., .., .. Free Pascal Lazarus

127

var x,y:real;
begin
{
.}
x:=0;
{ .}
while x<=pi do
{
,
.}
begin
{ y.}
y:=exp(sin(x))*cos(x);
{ y.}
writeln('x=', x,'
y=', y);
{ x.}
x:=x+0.1;
end; { .}
end.
x y:
x= 0; y=1
x= 0.1; y=1.0995

x= 3.1; y=-1.0415
3.6.2 repeat until

,
(. . 3.26). , , ,
, . ,
.
Free Pascal
repeat
;
until ;

.., .., .. Free Pascal Lazarus

128

repeat .. until Free


Pascal, , , .

,
:

3.26:

repeat
_1;
_2;
.............
_N;
until ;

. , . . (False),
. , , .
, , , .
, y=esin x cos x
[0;] 0.1, :
var
x,y:real;
begin
{
.}
x:=0;
{ .}
repeat
{ }
y:=exp(sin(x))*cos(x);
writeln('x=',x,' y=',y);
x:=x+0.1; { .}
until x>pi;
{ ,

.., .., .. Free Pascal Lazarus

129

.}
end.
3.6.3 for do
,
,
. for
do :
for i:= in to ik do ;
for i:= ik downto in do ;
, i, in ik
.
i . in
ik : in , ik .
for
( 1).
,
:
for i:= in to ik do
begin
_1;
_2;
...........
_n;
end;
(.3.27) for do:
1. i in.
2.
(i>ik), .
3.
3.
.
4.
i .2 . .
, .

.., .., .. Free Pascal Lazarus

130

3.27:
for...do
, , - for , . 3.2845.

3.28: for...do -
, ,
for:
var i:integer; c:char;
begin
45 , - .

.., .., .. Free Pascal Lazarus

131

{ 1 10.}
for i:=1 to 10 do writeln(i);
{ 10 -10.}
for i:=10 downto -10 do writeln(i);
{ a r.}
for c:='a' to 'r' do writeln(c);
end;
y=esin x cos x
[0;] 0.1. ,
. , .
,
xn xk, d,
:
xk xn
n=
1 ,
(3.6)
dx
. , y=esin x cos x [0;] 0.1 :
var i,n:integer; x,y:real;
begin
{ :}
{n=(xk-xn)/dx+1; xk=pi, xn=0, dx=0.1}
n:=round((pi-0)/0.1)+1;
x:=0; { .}
{ ,}
{i ,
1 n 1.}
for i:=1 to n do
begin
{ .}
{ }
y:=exp(sin(x))*cos(x);
{ .}
writeln('x=',x,' y=',y);
x:=x+0.1;
{
.}
end;
{ .}
end.

.., .., .. Free Pascal Lazarus

132

3.7
. Free Pascal :
goto, break, continue, exit halt.
goto , ,
, :
: ;46.
break continue . , break repeat, while, for , . continue
, .
exit .
halt .
3.8
.
3.9. () .
: . : .
:
, ,
3.4.
3.4. =25 =15.

=25
=10
=10
=5

=15
=15
=5
=5
5
, . 3.29,
,
46 goto .
, ,
, .
.

.., .., .. Free Pascal Lazarus

133

, . , while
do.

3.29:

Free Pascal, 3.9:


var a,b:word;
begin
writeln(' ');
write('A='); readln(A);
write('B='); readln(B);
{ , .}
while a<>b do
{ , ,
,}
if a>b then
a:=a-b
{ .}
else
b:=b-a;
writeln('=',A);
end.

.., .., .. Free Pascal Lazarus

134

3.10. N (N!=123 N).


: N ,
.
: factorial
N, 1 N, .
: i , , 2, 3, 4 N. -
. 3.30.
, N.
factorial, , , . 3.30: ,
i.
N, ,
factorial , , factorial.
i N, , factorial.

Free Pascal.
Var factorial, n, i:integer;
begin
write('n='); readln(n);
factorial:=1;
for i:=2 to n do
factorial:=factorial*i;
writeln(factorial);
end.

.., .., .. Free Pascal Lazarus

135

3.11. an , n .
: a ,
n. : p
( ) a n.
: i ,
1 n 1,
.
- . 3.31.
,
n a,
n .
p.
3.31: - , - a
p. n .

3.5
2 : a=2, n=5.
, , .
3.5. a n
i
1
2
3
4
5
P
1
2
4
8
16
32
, .
Var a,p:real; i,n:word;
begin
write(' a=');
readln(a);
write(' n=');
readln(n);
p:=1;

.., .., .. Free Pascal Lazarus

136

for i:=1 to n do p:=p*a;


writeln('P=',P:1:3);
end.
3.12. ,
N.
: N .
: S .
: i ,
2, 4, 6, 8 , .
,

.
,
. , ,
(s=0).
- . 3.32.
i 2, , , ,
while do:
var
n,i,S:word;
begin
write('n=');
readln(n);
S:=0;
i:=2;
while i<=n do
begin
S:=S+i;
i:=i+2;
end;
writeln('S=',S);
end.

.., .., .. Free Pascal Lazarus

137

3.32:
, for do:
var
n,i,S:word;
begin
write('n=');
readln(n);

.., .., .. Free Pascal Lazarus

138

S:=0;
for i:=1 to n do
{
2 0, ,
, .}
if i mod 2 = 0 then
S:=S+i;
writeln('S=',S);
end.
3.6
n=7.
3.6.
i
1
2
3
4
5
6
7
S
0
0
2
2
6
6
12
12
, , ,
.
3.13. N. , (,
N=12 1, 2, 3, 4, 6. K=5).
: N .
: K N.
: i ,
N.
-, . 3.33,
: K, , ,
(k=0).
,
i N.
1 N/2 c 1.
, , i
N, K .
N/2 .
, , .

.., .., .. Free Pascal Lazarus

139

var
N,i,K:word;
begin
write('N=');
readln(N);
K:=0;
for i:=1 to N div 2 do
{ N
i, }
if N mod i= 0 then
{
.}
k:=k+1;
writeln(' K=',K);
end.
3.33:

3.7
N=12.
3.7. N
i
1
2
3
4
5
6
K
0
1
2
3
4
4
5
3.14. N. ,
. N ,
N. 13 , 1 13, N=12 ,
1, 2, 3, 4, 6 12.
: N .
: .
: i , N.
(. 3.34) ,
, N 2
N/2. .

.., .., .. Free Pascal Lazarus

140

, N
(pr:=true).
, i 2
N/2.
, N i. ,
, N
(Pr:=false).

, .

. ,
,
.

Pr.

Pr=true, N ,
N .

Free Pascal

break.

3.34:

:
var N,i:integer; Pr:boolean;
begin
write('N='); readln(N);
Pr:=true; {, .}
for i:=2 to N div 2 do
{ , }
if N mod i = 0 then
begin
Pr:=false; { }
break;
{ .}

.., .., .. Free Pascal Lazarus

141

end;
{ }
if Pr then
{ .}
writeln(' ',N,' - ')
else
writeln(' ',N,' ');
end.
3.15. N M, N M , N M.
. 3.35.

3.35:

.., .., .. Free Pascal Lazarus

142

, . N M, , .
( i
N M) . , k
.
3.14.
Free Pascal,
:
var N,M,i,j,k: longint; Pr:boolean;
begin
repeat
write('N='); readln(N);
write('M='); readln(M);
until (N>0) and (M>0) and (N<M);
k:=0;
{ }
{ i N M}
for i:=N to M do
begin
{ .}
Pr:=true;
for j:=2 to i div 2 do
if i mod j = 0 then
begin
Pr:=false;
reak;
end;
{ ,
1.}
if Pr then k:=k+1;
end;
if k=0 then writeln(' ')
else writeln(' ',k);
end.

.., .., .. Free Pascal Lazarus

143

3.16. N. .
: N .
: kol .
: M N.
,
,
. , N=12345, kol = 5.
3.8.
3.8.
kol
N
1
12345
2
12345 div10=1234
3
1234 div 10=123
4
123 div 10=12
5
12 div 10=1
1 div 10=0

. 3.36. , , :
var M,N:longint; kol:word;
begin
{ ,
. , , .}
repeat
write('N=');readln(N);
until N>0;
M:=N; { N. }
kol:=1; { .}
while M div 10 > 0 do
{ , 10.}
begin
kol:=kol+1;
{ .}
M:=M div 10;
{ .}
end;
writeln('kol=', kol); end.

.., .., .. Free Pascal Lazarus

144

3.36:
3.17. N. ,
(,
1101111011 ).
: N . : pos . : i , M
N.
, ,
47. ,
kol .
,
, , .
N=12345
3.9.
47 .

.., .., .. Free Pascal Lazarus

145

3.9.
i


1 120405
120405 mod 10= 5 6
2 12040 div10=1204 12040 mod 10 = 0 5
3 1204 div 10=120
1204 mod 10 = 4
4
4 120 div 10=12
120 mod 10 = 0
3
5 12 div 10=1
12 mod 10 = 2
2
6 1 div = 0
1 div 10 = 1
1
-
. 3.37.
, :
var
M,N:longint;
i,pos,kol:word;
begin
{ ,}
{ .}
{ , }
{ , }
repeat
write('N=');
readln(N);
until N>0;
// kol - .
M:=N; { N. }
kol:=1; { .}
while M div 10 > 0 do
{ ,}
{ 10.}
begin
kol:=kol+1;
{ .}
M:=M div 10;
{ .}
end;
writeln('kol=', kol);
M:=N;
pos:=0;
{ .}

.., .., .. Free Pascal Lazarus

3.37: 3.17

146

.., .., .. Free Pascal Lazarus

147

for i:=1 to kol do


begin
{ 0.}
if (M mod 10 = 0) then
begin
pos:=kol-i+1; { .}
writeln(' ', pos, '- .');
end;
M:=M div 10;
{ .}
end;
if pos=0 then
writeln(' 0.');
end.
3.9 Lazarus
, InputBox.

:
:=InputBox(_,,);

_ , ;
;
,
;
,
;

var
S:string;
begin
S:=InputBox(' ',
': ',
' ');
end;
, . 3.38. . -

.., .., .. Free Pascal Lazarus

148

, , , , . S
'
'.
3.38:
Cancel

.
, InputBox ,
:
var S:string; gradus,radian:real;
begin
S:=InputBox(' ',
' ','0,000');
gradus:=StrToFloat(S);
radian:=gradus*pi/180;
MessageDlg(' '
+FloatToStr(radian),MtInformation,[mbOk],0);
end;
, .
.
3.18. N . .
: N ; , .
: Max , .
: i , .

(. 3.39). ,
Max, .

.., .., .. Free Pascal Lazarus

149


. , Max.
. ,
, Max.
.
, .
Max 48.

3.39: - Label1
- Button1 (. 3.40).


.
procedure Tform1.Button1Click(
Sender: TObject);
var
i,N:integer;
max,X:real;
S:string;
begin
//
//.
S:=InputBox('',
48 () ,
, min,
, , .

.., .., .. Free Pascal Lazarus

150

' .','0');
N:=StrToFloat(S);
// .
S:=InputBox('
',' .','0');
X:=StrToFloat(S);
//, 1- .
max:=X;
//
// i=2, .. .
for i:=2 to N do
begin
// .
S:=InputBox('
',' .','0');
X:=StrToInt(S);
//
//, Max
// .
if X>max then max:=X;
end;
// .
MessageDlg(' - '
+FloatToStr(max),MtInformation,[mbOk],0);
end;
. 3.40 - 3.42.

3.40: 3.18

.., .., .. Free Pascal Lazarus

151

3.41: 3.18

3.42: 3.18
3.19. , 0 . , 49, , .
- . 3.43.
50
. Button1,
.
procedure TForm1.Button1Click(Sender: TObject);
var
N,k,min:integer;
S:string;
begin
// .
S:=InputBox(' ', ' . 0 ','0');
N:=StrToInt(S);
49 , 11, -3, 5, 12, -7, 5, 8,-9, 7, -6, 10, 5,0. 5. 3.
50 ()
3.18.

.., .., .. Free Pascal Lazarus

3.43:
//,
// K=0. K
//- .
k:=0;

152

.., .., .. Free Pascal Lazarus

153

// ,
// .
while N<>0 do
begin
// ?
if N>0 then
begin
// N>0 K=0, 1-
// , ,
// Min=N,
// 1.
if k=0 then
begin
k:=1;
min:=N;
end
// ,
// ,
// , Min.
//
// 1.
else if N<min then
begin
min:=N;
k:=1;
end
// ,
//
// 1.
else if N=min then k:=k+1;
end;
// .
S:=InputBox(' ', ' . 0 ','0');
N:=StrToInt(S);
end;
//
if k<>0 then

.., .., .. Free Pascal Lazarus

154

// ,
//
// ,
MessageDlg('MIN = '+IntToStr(min)+
' K='+IntToStr(k),MtInformation,[mbOk],0)
else
// ,
// .
MessageDlg(' ',
MtInformation,[mbOk],0);
end;
3.20. , N
.
, . , , .
k 0.
, . N . ( i
1 N). :
(A), (i=1), , A B (B:=A). (i1), AB ( ). <0, k 1.
B A.
- . 3.44.
Label1 Label2,
Edit1 Button1 (. 3.45). , , .
procedure TForm1.Button1Click(Sender: TObject);
var
N,A,B,i,k:integer;
S:string;

.., .., .. Free Pascal Lazarus

155

3.44: 3.20
begin
N:=StrToInt(Edit1.Text);
S:=InputBox(' ', ' . 0 ','0');
A:=StrToInt(S);
k:=0;
for i:=1 to N do
begin
S:=InputBox(' ', ' . 0 -

.., .., .. Free Pascal Lazarus

156

','0');
A:=StrToInt(S);
if (i<>1) then
if A*B<0 then
k:=k+1;
B:=A;
end;
MessageDlg('K = '+IntToStr(k),
MtInformation,[mbOk],0);
end;
. 3.46-3.47.

3.45:
3.19

3.46:
3.19

3.47:

3.19

3.10
- .
3.10.1
. y=f(x),
, f().
. 3.48 -3.55.

.., .., .. Free Pascal Lazarus

3.48: 1

3.49: 2

3.50: 3

157

.., .., .. Free Pascal Lazarus

3.51: 4

3.52: 5

3.53: 6

158

.., .., .. Free Pascal Lazarus

159

3.54: 7

3.55: 8
x y. (x; y) .
. 3.56 - 3.63.

3.56: 9

3.57: 10

.., .., .. Free Pascal Lazarus

3.58: 11

3.60: 13

3.62: 15

3.59: 12

3.61: 14

3.63: 16

160

.., .., .. Free Pascal Lazarus

161

:
17. (x0, y0) R0
(x1, y1). , .
18. , =x2+bx+c
=dx2+mx+n. , .
19. , =x3+bx2+x+d
=kx3+mx2+nx+p. , .
20. (x0, y0) R0 ,
.
21. (x0, y0) R0,
.
22. , =bx2+x+d =kx+m.
, .
23. O(0,0) R0
y=ax+b. , .
, .
24. = x2+bx+c .
25. , =x4+bx3+x2+dx+f
=bx3+mx2+dx+p. , .
3.10.2
1. , N.
2. , N.
3. ,
N.
4. n. :
n!
P= n
i .
i=1

5. , 0 . .
6. , 0 . , .

.., .., .. Free Pascal Lazarus

162

7. N .
8. N .
9. , 0 . .
10. P. ,
P.
11. , L .
L , L.
, 6=1+2+3 28=1+2+4+7+14.
3.13.
12. , 0 . .
13. N ,
.
14. N ,
.
15. , 0 . .
16. N .
, .
17. , 0
.
(. 11).
18. N . .
19. P. (. 11), P.
20. N . .

.., .., .. Free Pascal Lazarus

163

21. , 0
. , .
22. P. P!.
23. N .
.
, , .
24. P. .
25. , N (
).

.., .., .. Free Pascal Lazarus

164

4
,
,
, .
.
,
, . Free Pascal : . , , ,
, , .
4.1 .

, , . , , , . . .
.
, ( ).
.
. , ,
,
. , , , , . ,
, - ,
.

.., .., .. Free Pascal Lazarus

165


() :
,
;
,
, ;
, ,

;

, ( );
,
.
4.2 .
.
, .
.

, .
, .
. , .
. , .
. . ,

.., .., .. Free Pascal Lazarus

166

.
: - -.
-
,
.
- 51 , , ,
. . ,
-, -.
. .
4.3
:
procedure _(_);
label
_;
const
_;
type
_;
var
_;
begin
// .
end;
, procedure
, _ Free Pasacal , _
51 .

.., .., .. Free Pascal Lazarus

167

, .
-:
procedure name_1(r:real; i:integer; c:char);
:
procedure name_2(a,b:real; i,j,k:integer);
:
procedure name_3;
-, var,
- var :
procedure name_4(x,y:real; var z:real);
//x, y -,
//z -.
,
52 (, , , , ) ,
.

:
_(__);

:
a:=5.3; k:=2;
s:=a;
name_1(a, k, s);
, :
name_3;
4.1. ax2+bx+c=0.
3.3
(. 3.14).
. ,
a=0, .
52 , .

.., .., .. Free Pascal Lazarus

168

: x=-c/b, ,
b0. , -.
:
//
// .
procedure korni(a,b,c:real;var x1,x2:real;
var pr:boolean);
//
//(-):
//a,b,c ;
//
//(-):
//x1,x2 ;
//pr ,
// ,
//
// .
var
d:real;
begin
d:=b*b-4*a*c;
if d<0 then
pr:=false
else
begin
pr:=true;
x1:=(-b+sqrt(d))/2/a;
x2:=(-b-sqrt(d))/(2*a);
end
end;
//
//
var a_,b_,c_,x1_,x2_,x_:real; pr_:boolean;
begin
write('a_:='); readln(a_);
write('b_:='); readln(b_);
write('c_:='); readln(c_);
if a_=0 then
// _=0,

.., .., .. Free Pascal Lazarus

169

// .
begin
// bx+c=0.
if b_<>0 then
begin
x_:=-c_/b_;
writeln('x=',x_);
end
else
writeln(' ');
end
else
// ax^2+bx+c=0.
Begin
// .
korni(a_,b_,c_,x1_,x2_,pr_);
if pr_=false then
writeln(' ')
else
writeln('x1=',x1_,' x2=',x2_);
end;
end.
4.2. N .
.
max_min,
:
.
:
// max
// min M.
// :
//M - ( ),
//max min -
//( ).
procedure max_min(M:longint; var max:byte;
var min:byte);
var i: byte;
begin

.., .., .. Free Pascal Lazarus

170

i:=1;
while M div 10>0 do
begin
if i=1 then
begin
//,
max:=M mod 10; //
min:=M mod 10; //.
i:=i+1;
end;
// max min
if M mod 10 > max then max:=M mod 10;
if M mod 10 < min then min:=M mod 10;
M:=M div 10;
end;
end;
var
X:longint; N,i,X_max, X_min:byte;
begin
//
write('N='); readln(N);
for i:=1 to N do
begin
// .
write('X=');
readln(X);
if X>0 then // ,
//
begin
// .
max_min(X,X_max,X_min);
// .
writeln(' max=',X_max,' min=',X_min);
end;
end;
end.

.., .., .. Free Pascal Lazarus

171

4.4
:
function _(_):;
label
_;
const
_;
type
_;
var
_;
begin
// .
end;
: function, Free Pascal - _;
, - _, - ( ,
, , ).
:
function fun_1 (x:real):real;
function fun_2(a, b:integer):real;
53 (, ,
, , )
, .
, .
:
function fun_2(a, b:integer):real;
begin
fun_2:=(a+b)/2;
end;

, :
_ (__);
53 , .

.., .., .. Free Pascal Lazarus

172

:
y:=fun_1(1.28);
z:=fun_1(1.28)/2+fun_2(3,8);
4.3. N ,
.
, , . 3.14 (. 3.33).
, . , , ,
. ,
, 3.13 (. 3.32).
:
prostoe , ,
N, true (),
false () ;
soversh , ; N, true (),
false () .
:
//, .
function prostoe(N:word):boolean;
var i:word;
begin
prostoe:=true;
for i:=2 to N div 2 do
if N mod i = 0 then
begin
prostoe:=false;
break;
end;
end;
//,
// .
function soversh(N:word):boolean;
var i:word; S:word;

.., .., .. Free Pascal Lazarus

173

begin
soversh:=false;
S:=0;
for i:=1 to N div 2 do
if N mod i =0 then S:=S+i;
if S=N then soversh:=true;
end;
var X:word; K,kol_p,kol_s,i:byte; Sum,Pro:real;
begin
// .
// .
write('K='); readln(K);
Sum:=0; // .
Pro:=1; // .
kol_p:=0;
// .
kol_s:=0;
// .
for i:=1 to K do
begin
// .
Writeln('X='); readln(X);
// ,
if prostoe(X) then
begin
// ,
Pro:=Pro*X;
// .
kol_p:=kol_p+1;
end;
// ,
if soversh(X) then
begin
// ,
Sum:=Sum+X;
// .
kol_s:=kol_s+1;
end;
end;
// ,
if kol_s<> 0 then

.., .., .. Free Pascal Lazarus

174

begin
// .
Sum:=Sum/kol_s;
writeln('
', Sum:5:2);
end
else
// :
writeln('
.');
// ,
if kol_p<>0 then
begin
// .
Pro:= exp(1/kol_p*ln(Pro));
writeln('
',Pro:5:2);
end
else// :
writeln('
');
end.
4.4. . 0 . , -.
, . , 123454321, 678876 . , , .
,
.
:
cifra_kol (
3.16);
palindrom ,
.
:
//
// M.

.., .., .. Free Pascal Lazarus

175

function cifra_kol(M:longint):byte;
begin
cifra_kol:=1;
while M div 10 > 0 do
begin
cifra_kol:=cifra_kol+1;
M:=M div 10;
end;
end;
// ,
// M,
// kol ,
// .
function palindrom(M:longint;kol:byte):boolean;
var i:byte; j:longint;
begin
j:=1;
// 10 kol-1
//( ).
for i:=1 to kol-1 do
j:=j*10;
palindrom:=true; // - .
for i:=1 to kol div 2 do
begin
// M div j
//( ).
// M mod 10
//( ).
// ,
if M div j <> M mod 10 then
begin
// .
palindrom:=false;
break;
// .
end;
//
// 1-
M:=M-(M div j)*j;

.., .., .. Free Pascal Lazarus

176

// .
M:=M div 10;
/ .
j:=j div 100;
/
end;
end;
// .
var X:longint; pr:boolean;
begin
// .
write('X=');readln(X);
// .
pr:=false;
while X<>0 do // ,
begin
if palindrom(X,cifra_kol(X)) then
begin
pr:=true; // ,
break;
// .
End;
// .
write('X=');readln(X);
end;
if pr then writeln('
-.')
else writeln('
.');
end.
4.5
, Lazarus.
4.5. , , . , , .
, , , , .

.., .., .. Free Pascal Lazarus

177

:
- ,
-

, -
18060

1806060

,
180

180
;

, ;
60,
;
.

function gradus_radian(gradus,minuta,secunda:byte):real;

,
. ,
.
,

procedure radian_gradus(radian:real;
var gradus,minuta,secunda:byte);
, .
Lazarus. , ,
. 4.1, . 4.2.
4.1.

Caption


Height
265

Width
325

BorderIcons.BiMaximize false

.., .., .. Free Pascal Lazarus

178

BorderStyle
bdDialog
,

Position
poScreenCenter

Edit, Label
Button .
RadioButton
.
. ,
, .
, 4.1: Checked.
4.5

true, false.
RadioButton1 RadioButton2,
: ,
. RadioButton1
TForm1.RadioButton1Click .
, ,
.
,
, . ,
, TForm1.FormCreate .

.., .., .. Free Pascal Lazarus

179

OnCreate.
TForm1.FormCreate
.
, , :
Button1 ;
Button3 ( );
Button2 .

. . 4.4 .
4.5.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Edit1: TEdit;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit4: TEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);

.., .., .. Free Pascal Lazarus

180

procedure Button2Click(Sender: TObject);


procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// .
procedure TForm1.Button1Click(Sender: TObject);
//
// .
function gradus_radian
(gradus,minuta,secunda:byte):real;
begin
gradus_radian:=
gradus*pi/180+minuta*pi/180/60+
secunda*pi/180/60/60;
end;
// .
procedure radian_gradus(radian:real;
var gradus,minuta,secunda:byte);
begin
gradus:=trunc(radian*180/pi);
minuta:= trunc((radian*180/pi-gradus)*60);
secunda:=trunc(((radian*180/pigradus)*60-minuta)*60);
end;
var
grad,min,sec:byte;
rad:real;

// .
// .
// .

.., .., .. Free Pascal Lazarus

181

// .
kod_g,kod_m,kod_s,kod_r:integer;
begin
// .
if RadioButton1.Checked then
begin
Val(Edit1.Text,grad,kod_g);
// .
Val(Edit2.Text,min,kod_m);
// .
Val(Edit3.Text,sec,kod_s);
// .
// ,
if (kod_g=0) and (kod_m=0) and (kod_s=0) then
begin
// Label2
Label2.Visible:=true;
// .
// gradus_radian
// .
Label2.Caption:=' ' +chr(13)+
FloatToStrF(gradus_radian(grad,min,sec),
ffFixed,8,6)+' ';
end
else
// .
MessageDlg(' !',
MtWarning,[mbOk],0);
end;
// .
if RadioButton2.Checked then
begin
// .
Val(Edit4.Text,rad,kod_r);
// ,
if (kod_r=0)then
begin
// Label2
Label2.Visible:=true;
// .
// .

.., .., .. Free Pascal Lazarus

182

radian_gradus(rad,grad,min,sec);
Label2.Caption:=' ' +chr(13)
+IntToStr(grad)+' '+IntToStr(min)
+' '+IntToStr(sec)+' ';
end
else
// .
MessageDlg(' !',
MtWarning,[mbOk],0);
end;
end;
// .
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
// .
procedure TForm1.Button3Click(Sender: TObject);
begin
//
// .
Edit1.Text:='00';
Edit2.Text:='00';
Edit3.Text:='00';
Edit4.Text:='00.000';
Label1.Caption:=' ';
Label1.Font.Size:=10;
Label3.Caption:='';
Label4.Caption:='';
Label5.Caption:='';
Button1.Caption:='';
Button2.Caption:='';
Button3.Caption:='';
Edit4.Enabled:=false;
Label2.Visible:=false;
RadioButton1.Checked:=true;
RadioButton2.Checked:=false;
end;

.., .., .. Free Pascal Lazarus

// .
procedure TForm1.FormCreate(Sender: TObject);
begin
// .
Edit1.Text:='00';
Edit2.Text:='00';
Edit3.Text:='00';
Edit4.Text:='00.000';
Label1.Caption:=' ';
Label1.Font.Size:=10;
Label3.Caption:='';
Label4.Caption:='';
Label5.Caption:='';
Button1.Caption:='';
Button2.Caption:='';
Button3.Caption:='';
Edit4.Enabled:=false;
Label2.Visible:=false;
RadioButton1.Checked:=true;
RadioButton2.Checked:=false;
end;
//
// RadioButton1.
procedure Tform1.RadioButton1Click(
Sender: TObject);
begin
if RadioButton1.Checked then
begin
Edit1.Enabled:=true;
Edit2.Enabled:=true;
Edit3.Enabled:=true;
Label5.Enabled:=true;
Label3.Enabled:=true;
Label4.Enabled:=true;
Edit4.Enabled:=false;
end;
end;

183

.., .., .. Free Pascal Lazarus

4.2:
4.3:


//
// RadioButton2.
procedure Tform1.RadioButton2Click(
Sender: TObject);
begin
if RadioButton2.Checked then
begin
Edit4.Enabled:=true;
Button1.Enabled:=true;
Edit1.Enabled:=false;
Edit2.Enabled:=false;
Edit3.Enabled:=false;
Label3.Enabled:=false;
Label4.Enabled:=false;
Label5.Enabled:=false;
end;
end;
end.
4.6. :
ax+b=0;
ax2+bx+c=0;
ax3+bx2+cx+d=0.

184

.., .., .. Free Pascal Lazarus

x=-b/a,

3.4 3.5.

(. 4.4). . 4.1, Caption,

.

185

4.4:
4.6
,
. CheckBox RadioGroup
.
CheckBox ,
- . , Checked
(true, false).
,
.
RadioGroup
.
Items
, ItemIndex. .
, , Items . ,
,
, .
, . 4.5.

ItemIndex 1. , .

.., .., .. Free Pascal Lazarus

4.5:

186



, ,

ItemIndex
,
, .

, , . . 4.6 - 4.8 , .

, ,
( )
. :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls,
ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Button1: TButton;

.., .., .. Free Pascal Lazarus

187

Button2: TButton;
RadioGroup1: TRadioGroup;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// .
procedure TForm1.Button1Click(Sender: TObject);
// .
// korni_1:
//a,b ,
// ;
//x_ - ,
// .
procedure korni_1(a,b:real;var x_:string);
//x -
var x:real;
begin
x:=-b/a;
x_:=FloatToStrF(x,ffFixed,5,2);
end;
// .
// korni_2:
//a,b,c ,
// ;
//x1_,x2_ - ,
// ;

.., .., .. Free Pascal Lazarus

188

//pr ,
// , 1,
// ,
// , 2, .
procedure korni_2(a,b,c:real;
var x1_,x2_:string;var pr:byte);
//x1,x2 - ,
//d .
var d,x1,x2:real;
begin
d:=b*b-4*a*c;
if d<0 then
begin
x1:=-b/(2*a);
x2:=sqrt(abs(d))/(2*a);
x1_:= FloatToStrF(x1,ffFixed,5,2)+
'+i*'+FloatToStrF(x2,ffFixed,5,2);
x2_:= FloatToStrF(x1,ffFixed,5,2)+
'-i*'+FloatToStrF(x2,ffFixed,5,2);
pr:=2;
// .
end
else
begin
x1:=(-b+sqrt(d))/2/a;
x2:=(-b-sqrt(d))/(2*a);
x1_:= FloatToStrF(x1,ffFixed,5,2);
x2_:= FloatToStrF(x2,ffFixed,5,2);
pr:=1;
// .
end
end;
// .
// korni_3:
//a,b,c,d ,
// ;
//x1_,x2_,x3_ - ,
// ;
//pr ,
// , 1,

.., .., .. Free Pascal Lazarus

189

// ,
// , 2,
// .
procedure korni_3(a,b,c,d:real;
var x1_,x2_,x3_:string;var pr:byte);
//x1,x2,x3 - .
var r,s,t,p,q,ro,fi,u,v,x1,x2,x3,h,g:real;
begin
r:=b/a;
s:=c/a;
t:=d/a;p:=(3*s-r*r)/3;
q:=2*r*r*r/27-r*s/3+t;
d:=(p/3)*sqr(p/3)+sqr(q/2);
if d<0 then
begin
ro:=sqrt(-p*p*p/27);
fi:=-q/(2*ro);
fi:=pi/2-arctan(fi/sqrt(1-fi*fi));
// .
x1:=2*exp(1/3*ln(ro))*cos(fi/3)-r/3;
x2:=2*exp(1/3*ln(ro))*cos(fi/3+2*pi/3)-r/3;
x3:=2*exp(1/3*ln(ro))*cos(fi/3+4*pi/3)-r/3;
x1_:=FloatToStrF(x1,ffFixed,5,2);
x2_:=FloatToStrF(x2,ffFixed,5,2);
x3_:=FloatToStrF(x3,ffFixed,5,2);
pr:=1; // .
end
else
begin
if -q/2+sqrt(d)>0 then
u:=exp(1/3*ln(-q/2+sqrt(d)))
else
if -q/2+sqrt(d)<0 then
u:=-exp(1/3*ln(abs(-q/2+sqrt(d))))
else u:=0;
if -q/2-sqrt(d)>0 then
v:=exp(1/3*ln(-q/2-sqrt(d)))
else

.., .., .. Free Pascal Lazarus

190

if -q/2-sqrt(d)<0 then
v:=-exp(1/3*ln(abs(-q/2-sqrt(d))))
else v:=0;
// .
x1:=u+v-r/3;
// .
h:=-(u+v)/2-r/3;
g:=(u-v)/2*sqrt(3);
x1_:=FloatToStrF(x1,ffFixed,5,2);
x2_:=FloatToStrF(h,ffFixed,5,2)+
'+i*'+FloatToStrF(g,ffFixed,5,2);
x3_:=FloatToStrF(h,ffFixed,5,2)+
'-i*'+FloatToStrF(g,ffFixed,5,2);
pr:=2; //1
//2 .
end
end;
//
// .
var
a_,b_,c_,d_:real;
kod_a,kod_b,kod_c,kod_d:integer;
_x,_x1,_x2,_x3:string; _pr:byte;
begin
case RadioGroup1.ItemIndex of
0: // 1- .
Begin // .
// .
val(Edit1.Text,a_,kod_a);
val(Edit2.Text,b_,kod_b);
// .
if (kod_a=0) and (kod_b=0) then
begin
//1- .
if a_<>0 then
begin
// .
korni_1(a_,b_,_x);

.., .., .. Free Pascal Lazarus

191

// .
MessageDlg(' x='+
_x,mtInformation,[mbOk],0);
end
//1- ,
else
// .
MessageDlg(' !',
mtInformation,[mbOk],0);
end
else // .
MessageDlg(' !',
mtInformation,[mbOk],0);
end;
1: // 2- .
begin
// .
val(Edit1.Text,a_,kod_a);
val(Edit2.Text,b_,kod_b);
val(Edit3.Text,c_,kod_c);
// .
if (kod_a=0) and (kod_b=0) and (kod_c=0)
then begin
// .
if a_<>0 then
begin
// .
korni_2(a_,b_,c_,_x1,_x2,_pr);
// _pr
// :
//1 , 2 .
// .
if (CheckBox1.Checked=false) and
(CheckBox2.Checked=false) then
MessageDlg(' ',
mtInformation,[mbOk],0);
// .
if CheckBox1.Checked and

.., .., .. Free Pascal Lazarus

192

CheckBox2.Checked then
MessageDlg(' '+
chr(13)+' X1='+_x1+
' X2='+_x2,mtInformation,[mbOk],0);
// ,
// .
if CheckBox1.Checked and
(CheckBox2.Checked=false) and (_pr=1)
then
MessageDlg(' '+
chr(13)+' X1='+_x1+' X2='+_x2,
mtInformation,[mbOk],0);
// ,
// .
if (CheckBox1.Checked=false) and
CheckBox2.Checked and (_pr=1) then
MessageDlg('
.',
mtInformation,[mbOk],0);
// , .
if CheckBox1.Checked and
(CheckBox2.Checked=false) and (_pr=2) then
MessageDlg(' ',
mtInformation,[mbOk],0);
// , .
if (CheckBox1.Checked=false) and
CheckBox2.Checked and (_pr=2) then
MessageDlg(' '+
chr(13)+' X1='+_x1+' X2='+_x2,
mtInformation,[mbOk],0);
end
else
// .
MessageDlg(' 0!',
mtInformation,[mbOk],0);
end
// .
else
MessageDlg(' !',

.., .., .. Free Pascal Lazarus

193

mtInformation,[mbOk],0);
end;
2: // 3- .
Begin
// .
val(Edit1.Text,a_,kod_a);
val(Edit2.Text,b_,kod_b);
val(Edit3.Text,c_,kod_c);
val(Edit4.Text,d_,kod_d);
// .
if (kod_a=0) and (kod_b=0) and (kod_c=0)
and (kod_d=0)then
begin
// .
if a_<>0 then
begin
// .
// _pr
// :
//1 ,
//2 .
korni_3(a_,b_,c_,d_,_x1,_x2,_x3,_pr);
// .
if (CheckBox1.Checked=false) and
(CheckBox2.Checked=false) then
MessageDlg(' ',
mtInformation,[mbOk],0);
// .
if CheckBox1.Checked
and CheckBox2.Checked then
MessageDlg(' '+
chr(13)+' X1='+_x1+
' X2='+_x2+' X3='+_x3,
mtInformation,[mbOk],0);
// ,
// .
if CheckBox1.Checked and
(CheckBox2.Checked=false) and (_pr=1) then
MessageDlg(' '+

.., .., .. Free Pascal Lazarus

194

chr(13)+' X1='+_x1+' X2='+_x2+' X3='+_x3,


mtInformation,[mbOk],0);
// , .
if CheckBox1.Checked and
(CheckBox2.Checked=false) and (_pr=2) then
MessageDlg(' '+
chr(13)+' X1='+_x1,mtInformation,[mbOk],0);
// , .
if (CheckBox1.Checked=false) and
CheckBox2.Checked and (_pr=2) then
MessageDlg(' '+
chr(13)+' X1='+_x2+' X2='+_x3,
mtInformation,[mbOk],0);
// ,
// .
if (CheckBox1.Checked=false) and
CheckBox2.Checked and (_pr=1) then
MessageDlg('
.',
mtInformation,[mbOk],0);
end
else
MessageDlg(' 0!',
mtInformation,[mbOk],0);
end
else
// .
MessageDlg(' !',
mtInformation,[mbOk],0);
end;
end;
end;
// .
procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption:=' ';
Label2.Caption:='a=';
Label3.Caption:='b=';
Label4.Caption:='c=';

.., .., .. Free Pascal Lazarus

195

Label5.Caption:='d=';
Edit1.Text:='0.00';
Edit2.Text:='0.00';
Edit3.Text:='0.00';
Edit4.Text:='0.00';
Button1.Caption:=' ';
Button2.Caption:='';
Button3.Caption:='';
CheckBox1.Caption:=' ';
CheckBox2.Caption:=' ';
CheckBox1.Checked:=true;
Label4.Enabled:=false;
Label5.Enabled:=false;
Edit3.Enabled:=false;
Edit4.Enabled:=false;
CheckBox2.Enabled:=false;
RadioGroup1.ItemIndex:=0;
end;
// .
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
// .
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption:=' ';
Label2.Caption:='a=';
Label3.Caption:='b=';
Label4.Caption:='c=';
Label5.Caption:='d=';
Edit1.Text:='0.00';
Edit2.Text:='0.00';
Edit3.Text:='0.00';
Edit4.Text:='0.00';
Button1.Caption:=' ';
Button2.Caption:='';
Button3.Caption:='';

.., .., .. Free Pascal Lazarus

CheckBox1.Caption:=' ';
CheckBox2.Caption:=' ';
CheckBox1.Checked:=true;
Label4.Enabled:=false;
Label5.Enabled:=false;
Edit3.Enabled:=false;
Edit4.Enabled:=false;
CheckBox2.Enabled:=false;
RadioGroup1.ItemIndex:=0;
end;
// .
procedure Tform1.RadioGroup1Click(
Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:
// .
begin
Label2.Enabled:=true;
Label3.Enabled:=true;
Edit1.Enabled:=true;
Edit2.Enabled:=true;
Label2.Caption:='a=';
Label3.Caption:='b=';
Edit1.Text:='0.00';
Edit2.Text:='0.00';
Label4.Enabled:=false;
Label5.Enabled:=false;
Edit3.Enabled:=false;
Edit4.Enabled:=false;
CheckBox2.Enabled:=false;
end;
1:
// .
begin
Label2.Enabled:=true;
Label3.Enabled:=true;
Label4.Enabled:=true;
Edit1.Enabled:=true;
Edit2.Enabled:=true;

196

.., .., .. Free Pascal Lazarus

Edit3.Enabled:=true;
Label2.Caption:='a=';
Label3.Caption:='b=';
Label4.Caption:='c=';
Edit1.Text:='0.00';
Edit2.Text:='0.00';
Edit3.Text:='0.00';
Label5.Enabled:=false;
Edit4.Enabled:=false;
CheckBox2.Enabled:=true;
end;
2:
// .
begin
Label2.Enabled:=true;
Label3.Enabled:=true;
Label4.Enabled:=true;
Label5.Enabled:=true;
Edit1.Enabled:=true;
Edit2.Enabled:=true;
Edit3.Enabled:=true;
Edit4.Enabled:=true;
Label2.Caption:='a=';
Label3.Caption:='b=';
Label4.Caption:='c=';
Label4.Caption:='d=';
Edit1.Text:='0.00';
Edit2.Text:='0.00';
Edit3.Text:='0.00';
Edit4.Text:='0.00';
CheckBox2.Enabled:=true;
end;
end;
end;end.

197

.., .., .. Free Pascal Lazarus

198

4.6:

4.7:

4.8:

4.6
, . . -

.., .., .. Free Pascal Lazarus

199

, . , . ,

, , .

. .
.
4.7. n.
3.10
(. 3.29). factorial, . 4.9.

4.9:
:
function factorial(n:word):longint;
begin
if n<=1 then
factorial:=1
else
factorial:=n*factorial(n-1)
end;
var i:integer;
begin

.., .., .. Free Pascal Lazarus

200

write('i=');
read(i);
write(i,'!=',factorial(i));
end.
4.8. n- a (n )
a n n .
n. n 1
n
, a = n . n=0, a0=1.
a
stepen,
. 4.10.

4.10:
:
function stepen(a:real;n:word):real;
begin
if n=0 then stepen:=1
else
if n<0 then
stepen:=1/stepen(a,-n)

.., .., .. Free Pascal Lazarus

else
stepen:=a*stepen(a,n-1);

201

end;
var
x:real;k:word;
begin
writeln('x='); readln(x);
writeln('k='); readln(k);
writeln(x:5:2,'^',k,'=',stepen(x,k):5:2);
end.
4.9. n- .
,
, , (0, 1, 1, 2, 3, 5,
8, 13, 21, 34, ... ).
fibonachi .
4.11.

4.11:

:
function fibonachi(n:word):word;
begin
if (n=0)or(n=1) then fibonachi:=n

.., .., .. Free Pascal Lazarus

202

else fibonachi:=fibonachi(n-1)+fibonachi(n-2);
end;
var x:word;
begin
write(' x=');
readln(x);
writeln(x,' - = ',
fibonachi(x));
end.
4.7
.
4.7.1 -
-
-, const,
. - -, - .
Free Pascal -
- , ,
.
4.7.2


.
, .
: - -:
type
_=procedure (_);
_=function (_):;
, :

.., .., .. Free Pascal Lazarus

203

var
__1: _;
__2: _;
:
type
Fun1=function (x,y:real):real;
Fun2=function:string;
Proc1=procedure (x,y:real; var c,z:real);
Proc2=procedure ();
Var
F1,f2: Fun1;
p1,p2: Proc1;
mass:array [1..5] of Proc2;
54:
@_
.
4.10. , f(x) g(x).
VivodFunc. :
a b ;
n , (a, b);
ff .
type
{ func.}
func=function(x:real):real;
function VivodFunc (a,b:real;
N:word;ff:func):integer;
var
x,y,hx:real;
f:text;
begin
{ x.}
hx:=(b-a)/N;
x:=a;
54 (. 2.4.4)

.., .., .. Free Pascal Lazarus

204

while(x<=b) do
begin
y:=ff(x);
writeln('x=',x:5:2,' y=',y:7:2);
x:=x+hx;
end;
end;
{ f g far.}
function f(x:real):real;far;
begin
f:=exp(sin(x))*cos(x);
end;
function g(x:real):real;far;
begin
g:=exp(cos(x))*sin(x);
end;
begin
{ Vivodfunc f .}
VivodFunc(0,1,7,@f);
writeln;
{ Vivodfunc g .}
VivodFunc(0,2,8,@g);
end.
Free Pascal
.
4.10. , ,

VivodFunc. :
(a, b);
n (a, b);
ff, ;
m ff.
type
func=function(x:real):real;
{ VivodFunc }
{ ff

.., .., .. Free Pascal Lazarus

205

55.}
function VivodFunc(a,b:real;N:word;
ff:array of func; m:word):integer;
var
x,y,hx:real;
i:integer;
begin
hx:=(b-a)/N;
{ .}
for i:=0 to m-1 do
begin
x:=a;
while(x<=b) do
begin
{ i- x.}
y:=ff[i](x);
writeln('x=',x:5:2,' y=',y:7:2);
x:=x+hx;
end;
writeln;
end;
end;
function f(x:real):real;far;
begin
f:=exp(sin(x))*cos(x);
end;
function g(x:real):real;far;
begin
g:=exp(cos(x))*sin(x);
end;
{ fff.}
var fff:array[1..8] of func;
begin
{ fff.}
fff[1]:=@f; fff[2]:=@g;
VivodFunc(0,1,7,fff,2);{ .}
end.
55 . . 5.10

.., .., .. Free Pascal Lazarus

206

. .
4.8
,
: , , , . Lazarus . , .
:
UNIT ;
INTERFACE

IMPLEMENTATION

BEGIN

END.
UNIT .
, . EDIT
edit.pas.
INTERFACE,
:
, , . , .

IMPLEMENTATION ,
. ,
, .
,
. .
begin.

.., .., .. Free Pascal Lazarus

207


, ,
56 :
procedure sum(a,b:complex;var c:complex) a b, c;
procedure razn(a,b:complex;var c:complex) a b, c;
procedure umn(a,b:complex;var c:complex) a b, c;
procedure delenie(a,b:complex;var c:complex)
a b, c;
,
procedure vivod(a:complex).
.
UNIT compl;
INTERFACE
type
complex=record
x:real;
y:real;
end;
procedure sum(a,b:complex;var c:complex);
procedure razn(a,b:complex;var c:complex);
procedure umn(a,b:complex;var c:complex);
procedure delenie(a,b:complex;var c:complex);
procedure vivod(a:complex);
IMPLEMENTATION
procedure sum(a,b:complex;var c:complex);
begin
56

a+bi c+di (a+c) + (b+d)i, (ac) + (bd)i, (acbd) + (bc+ ad)i, -

abbd
bcad
2
i .
2
2
c d
c d 2

.., .., .. Free Pascal Lazarus

208

c.x:=a.x+b.x;
c.y:=a.y+b.y;
end;
procedure razn(a,b:complex;var c:complex);
begin
c.x:=a.x-b.x;
c.y:=a.y-b.y;
end;
procedure umn(a,b:complex;var c:complex);
begin
c.x:=a.x*b.x-a.y*b.y;
c.y:=a.y*b.x+a.x*b.y;
end;
procedure delenie(a,b:complex;var c:complex);
begin
c.x:=(a.x*b.x+a.y*b.y)/(b.x*b.x+b.y*b.y);
c.y:=(a.y*b.x-a.x*b.y)/(b.x*b.x+b.y*b.y);
end;
procedure vivod(a:complex);
begin
if a.y>=0 then
writeln(a.x:1:3,'+',a.y:1:3,'i')
else
writeln(a.x:1:3,'-',-a.y:1:3,'i')
end;
end.
Geany, ,
compl.pas. . , , .o ( Linux .obj Windows), .ppu.
.o. .o , ,
, ,
.
, .
.
uses compl;

.., .., .. Free Pascal Lazarus

var g,h,e:complex;
BEGIN
writeln(' ');
read(g.x,g.y);
vivod(g);
writeln(' ');
read(h.x,h.y);
vivod(g);
sum(g,h,e);
writeln(' ');
vivod(e);
razn(g,h,e);
writeln(' ');
vivod(e);
umn(g,h,e);
writeln(' ');
vivod(e);
delenie(g,h,e);
writeln(' ');
vivod(e);
end.
. 4.12.

4.12:

209

.., .., .. Free Pascal Lazarus

210

4.9
, .
1. , 0 . ,
, . , .
2. , 0 . ,
. .
3. N . ,
. .
4. N . .
.
5. N . . .
6. , 0
. ,
. .
7. , 0
. ,
. .
8. f(x)=x-2ex
f'(x), -5 5, 0.5.
f(x) f'(x) .
9. N . . .
10. N .

. .

.., .., .. Free Pascal Lazarus

211

11. , 0
. , , .
.
12. N .
, ,
.
.
13. ,
0 . .
.
14. N
. .
15. N
.
.
16. ,
0 . , 0.
, , ,
.
17. ,
0 .
. ,
.
18. N . .
.
19. ,
0 . .
, :
.

.., .., .. Free Pascal Lazarus

212

20. N .
. ,
.
21. ,
0 . . , 12345 54321. .
22. ,
0 . . , .
23. N . . , ,
, . , .
24. ,
0 .
.
.
25. f x= 5x 3sin x 2

x
4

g x= e , x0
a b, h. 5 2
x , x0

f(x) g(x) .

.., .., .. Free Pascal Lazarus

213

5 Free Pascal -


5.1
, . ( , , ..)
. ,
. (365) , temperature1, temperature2, temperature3, temperature365 temperature, (. 5.1).

5.1:
, .
, .
, 5.2, 7 , . 1 7. , , ,
. ,
,
, .

5.2: 7
,
,
.
5.3 ,
. . -

.., .., .. Free Pascal Lazarus

214

, .
, , , ,
, .

5.3:
, Free Pascal.
5.2
array of. :
,
. type :
type
_ = array [_] of
_;
_
. _ , :
type
massiv=array[0..12] of real;
// massiv 13 ,
// 0 12.
dabc=array[-3..6] of integer;
// dabc 10 ,
// -3 6.
var
x,y:massiv;
z: dabc;

.., .., .. Free Pascal Lazarus

215

, :
var
: array [_] of
_;
:
var
z,x: array[1..25] of word;
// z x 25 word,
// 1 25.
g:array[-3..7] of real;
// g 11 real,
// -3 7.
:
const
n=10;
m=12;
var
a: array[1..n] of real;
b: array[0..m] of byte;
,
!
() , ( ) :
type
massiv=array[1..200] of real;
matrica=array[1..300] of massiv;
var
ab:matrica;

:
Type
matrica = array [1..300,1..200] of real;
var
ab:matrica;

var ab:array [1..300,1..200] of real;

.., .., .. Free Pascal Lazarus

216


, 300 200 .
,
:
type
abc=array [1..4,0..6,-7..8,3..11] of real;
var b:abc;
5.3

( ). , x[1],
y[5], c[25], [8].
Free Pascal , (
). , C D
var C,D: array [0..30] of real;
C:=D;.
C
D.

,
,
,

,
5.4: - , , ,

n- (. 5.4-5.5).

for.

.., .., .. Free Pascal Lazarus

217

5.5: - for
5.4 -
Free Pascal -
,
.

1-, 2-, 3- ..
,
. , ,
(. 5.6 - 5.7).



, X[5], b[2] ..
5.4.1 -
5.6:
X
.

/ X while.
var x: array [1..100] of real;
i,n: integer;
begin

.., .., .. Free Pascal Lazarus

218

writeln (' '); readln(N);


i:=1;
while (i<=N) do
begin
write('x(',i,')= ');
readln(x[i]);
i:=i+1
end;
end.
// X for.
var i,n: integer;
x: array [1..100] of real;
begin
readln(N);
for i:=1 to N do
begin
write('x(',i,')= ');
readln(x[i])
end;
end.
for do ,


.
,

5.7:

X
.



a=(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8),
, , , .

.., .., .. Free Pascal Lazarus

219

// 1
for i: = 1 to n do
write (a[i]:3:1);

. 5.8. , .

5.8:
// 2
for i: = 1 to n do
write (a[i]:6:2);

. 5.9

5.9:

// 3
for i: = 1 to n do
write (a[i]:3:1,' ');

. 5.10.
// 4
writeln (' A');
for i:=1 to n do
writeln(a[i]:6:2);
. 5.11.

.., .., .. Free Pascal Lazarus

220

// 5
for i:=1 to n do
write ('a(',i,')=',a[i]:3:1,' ');

. 5.12.

5.10:

5.11:

5.12:
// 6
for i:=1 to n do
writeln ('a(',i, ')= ',a[i]:6:2);

. 5.13.

.., .., .. Free Pascal Lazarus

221

5.13:
5.4.2 -
-
,
TEdit.

a=(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8).
( TButton)
TEdit (. . 5.14).

5.14:

.., .., .. Free Pascal Lazarus

222

. 5.1 - 5.2 TButton


TEdit.
5.1: Edit1
Name1 Text
Edit1 ' '

Height Left

Top

Width

ReadOnly

23

184

492

True

103

5.2: Button1
Name1
label1

Caption Height

Left

Top

Width

Button1 25

177

392

239


a Edit1. : FloatToStr, . Button1Click
.
procedure TForm1.Button1Click(Sender: TObject);
var
// a.
a:array [1..8] of
real=(1.1,2.2,3.3,4.4, 5.5, 6.6, 7.7, 8.8);
i:integer;
// n
//
// .
n:integer=8;
S:string='';
begin
Edit1.Text:='';
// for
// a.
for i:=1 to n do
// Edit1
//,
// a[i].
Edit1.Text:=Edit1.Text+FloatToStr(a[i])+' ';
end;
, . 5.15.

.., .., .. Free Pascal Lazarus

223

5.15:
Lazarus
InputBox. ,
. . Button1Click .
procedure TForm1.Button1Click(Sender: TObject);
var i,n:byte; X:array [1..20] of real;
begin
// .
n:=StrToInt(InputBox('
','n=','7'));
for i := 1 to n do
// .
//
X[i]:=StrToFloat(InputBox('
',' '+IntToStr(i)+ '
','0,00'));
end;

(. . 5.16). , . 5.17.

.., .., .. Free Pascal Lazarus

224

5.16:

5.17:
MessageDlg:
for i:= 1 to n do
MessageDlg('X['+IntToStr(i)+']=
'+FloatToStr(X[i]), MtInformation, [mbOk],0),
(.
. 5.18).

,
, , ,
:

var
5.18:
i,n:byte;

X:array [1..20] of real;

S:string;

begin
//
// .
S:='';
for i:=1 to n do

.., .., .. Free Pascal Lazarus

225

// ,
//
// ,
// .
S:=S+FloatToStrF(X[i],ffFixed,5,2)+' ';
// .
Label2.Caption:=S;
//
//,
//MessageDlg(S,MtInformation,[mbOk],0);
- ,
TStringGrid ( ).
.
. 5.19 ,
TStringGrid57 ( ).
.
, .

5.19: ""
5.3.
5.3: TstringGrid

Name
ColCount

57 TStringGrid Additional.

.., .., .. Free Pascal Lazarus

RowCount

Cells

FixedCols

FixedRows

226


,
. , col row, Cells [col,row];
0 RowCount-1,
( 0 ColCount-1)


,


,
, :
( )
ssHorizontal, ssVertical ssBoth , ;
ssAutoHorizontal,
ssAutoVertical

ssAutoBoth , .
ssNone

ScrollBars

, ,
Options.goEditing (True) (False)

Options.goTab

, (True)
(False) b

DefaultColWidth

DefaultRowHeight

.., .., .. Free Pascal Lazarus

227

DefaultRowHeight

Height

TStringGrid

Width

TStringGrid

GridLineWidth
Left
Top
DefaultColWidth

,

- ,
,
.
,
TStringGrid . StringGrid1
StringGrid2 , . 5.4.
5.4: TStringGrid
Font

StringGrid1 StringGrid2

ColCount

RowCount

FixedCols

FixedRows

.., .., .. Free Pascal Lazarus

StringGrid1 StringGrid2

228

Options.goEditing True
False


Left
186
186

Top
72
216

Height
24
24

Width
518
518


. 5.20.

5.20:
,
.
:
procedure Tform1.Button1Click(
Sender: TObject) ;

.., .., .. Free Pascal Lazarus

229

var n,i:integer;
a:array [0..7] of real;
begin
for i:=0 to 7 do
// .
// ,
//
// .
a[i]:=StrToFloat(StringGrid1.Cells[i,0]);
for i:=0 to 7 do
// .
//
// .
StringGrid2.Cells[i,0]:=
FloatToStrF(a[7-i],ffFixed,5,2);
end;
, . 5.20,
, ,
, . 5.21.

5.21: -
, . , .
, (

.., .., .. Free Pascal Lazarus

230

, , ,
. .). , , (, , ..).
5.5

.
X, n . . S ,
, S
X.
- . 5.22. :
s:=0;
for i:=1 to n do s:=s+x[i];
writeln('s=',s:7:3);
X. , ,
, i
. - . 5.23.

5.22:

5.23:

.., .., .. Free Pascal Lazarus

231

:
p:=1;
for i:=1 to n do p:=p*x[i];
writeln('P=',P:7:3);
5.6

(Max)
(Nmax) X, n .
. ,
, Max, Nmax ( 1).
,
, .
,
Max,
Nmax i.



-
5.24: - . 5.24. -
:
Max:=X[1]; Nmax:=1;
for i:=2 to n do
if X[i]>Max then
begin
Max:=X[i];
Nmax:=i;
end;
write(' Max=',Max:1:3,' Nmax=',Nmax);

.., .., .. Free Pascal Lazarus

232

, , , if >
<.
5.7

. , X n ,
X[1] X[2] X[n],
,
X[1] X[2] X[n].
,
,
. 58.
.
5.7.1

. 59 .
. .
, , . , , ,
, , .
4.
, ,
58
.
59 - , .

233

.., .., .. Free Pascal Lazarus

. . (n1) n , (n-)
. , 1- n-1 (, n- , ,
).
(n1)-
. , .
. 5.5
.
,
,
n ,

n1 ,

.

.
5.25.
( 4) b,

5.25:
, .

5.5:


1
2
3
4
5




7
3
3
3
2

3
5
4
2
3

5
4
2
4
4

4
2
5
5
5

2
7
7
7
7

.., .., .. Free Pascal Lazarus

234

,
.
. 5.26 .
var i,j,n: byte; b:real;
X: array [1..100] of real;
begin
writeln (' ');
readln (n);
for i:=1 to n do
begin
write('X[',i,']=');
readln (X[i]);
end;
writeln (' X ');
for i:=1 to n do
write (x[i]:5:2,' ');
writeln;
for j:=1 to n-1 do
for i:=1 to n-j do
if X[i] > X[i+1] then
{
, }
begin { . }
b:=X[i];
{
. }
X[i]:=X[i+1];{
. }
X[i+1]:=b; {
b.}
end;
writeln(' ');
for i:=1 to n do
write (X[i]:5:2,' ');
writeln;
end.
>
< (. 3 . 5.25).

.., .., .. Free Pascal Lazarus

235

5.26:
5.7.2
()
() .
- . 5.27.
( 25)
( 6). . ( 26),
( 7), ,
( 8).
1, , (N),
N K ( 1) K.
. (. 5.27)
4 > <.


.

.., .., .. Free Pascal Lazarus

5.27:

// .
repeat
max:=x[1]; nom:=1;
for i:=2 to k do
if max < X[i] then
begin
max:=X[i]; nom:=i;
end;
b:=x[nom]; x[nom]:=x[k]; x[k]:=b;
k:=k-1;
until k=1;

236

.., .., .. Free Pascal Lazarus

237

5.8

.
X, 6 . , , , .
X[3]:=X[4]; X[4]:=X[5]; X[5]:=X[6];
, , i- (i+1)-.
- . 5.28.
:
m- X, n .
(m+1)- c m, (m+2)-
(m+1)- .., n-
(n1)-. 5.28:
3-
. 5.29.

5.29:

n m . 5.30.
60 , ( ) . , , ( )
.
.
60 .

.., .., .. Free Pascal Lazarus

238

, ,


( ).
.

5.30:
m-
n
5.1. X(n) .
, , , . , , , . 5.1 . 5.31. . . 5.32.
program upor_massiv;
var
i,n,j:byte;
X: array [1..100] of real;
begin
writeln (' ');
readln (n);
{ .}
for i:=1 to n do
begin
write('X[',i,']=');
readln (X[i]);
end;
writeln (' X ');
for i:=1 to n do
write (x[i]:5:2,' ');
writeln;

.., .., .. Free Pascal Lazarus

5.31: - 5.1

239

.., .., .. Free Pascal Lazarus

i:=1;
while(i<=n)do
{ X[i]
, }
if x[i]<0 then
begin
{ i.}
for j:=i to n-1 do x[j]:=x[j+1];
{ .}
{ .}
n:=n-1;
end
else
{ ,
.}
i:=i+1;
writeln(' :');
for i:=1 to n do write (X[i]:5:2,' ');
writeln;end.

5.32:
5.1

240

.., .., .. Free Pascal Lazarus

241

5.9
: b X(10)
.
,
, .
b (X[4]:=b;).
,
, , . . .
- . 5.33.
- b X(N) c m m+1 . 5.34.

5.33:
b X

5.34:
b X
, 61.
var i,n,m:byte; X: array [1..100] of real;
b:real;
begin
writeln ('N='); readln (n);
for i:=1 to n do
begin
write('X[',i,']='); readln (X[i]);
end;
writeln (' X');
for i:=1 to n do write (x[i]:5:2,' ');
61 X .

.., .., .. Free Pascal Lazarus

242

writeln;
writeln ('m='); readln (m);
writeln ('b='); readln(b);
for i:=n downto m+1 do
x[i+1]:=x[i];
x[m+1]:=b;
n:=n+1;
writeln(' ');
for i:=1 to n do write (X[i]:5:2,' ');
writeln;
end.
5.10
, .
(. 4), , .
. , 62,
:
type _= array [_] of ;
procedure _(_: _);

:
type
vector=array [1..10] of byte;
matrica=array [1..3, 1..3] of real;
procedure proc(A:matrica;b:vector;var x:vector);
,
_: string[_];
63, :
type _= string [_];
procedure _(_: _ );

62 , . .2.3.9.
63 , . .2.3.9.

.., .., .. Free Pascal Lazarus

243

:
type
stroka_5=string[5];
stroka_10=string[10];
function fun(Str: stroka_5):stroka_10;
,
. 64,
, :
__: array of array of ;
:
var
massiv_1: array of real;
massiv_2: array of array of char;
massiv_3: array of array of array of byte;


SetLength:
SetLength(_, __);
:
_:=NIL;
( ) . (
) :
high(_)

Free Pascal.

.
var
// .
x: array of real;
s:real;
i,n:integer;
Begin
write('n='); readln(n);
64 , , . .2.2.9.

.., .., .. Free Pascal Lazarus

244

//
//n :
SetLength(x,n);
for i:=0 to high(x) do read(x[i]);
s:=0;
for i:=0 to high(x) do s:=s+x[i];
writeln('=',s:7:3);
x:=NIL;
// .
end.
:
procedure
_(__:
array of ;);
:
//
//
// .
//
// .
procedure outputArray(X:array of integer);
var i:byte;
begin
//
// 0 high(X).
for i:=0 to high(X) do
// :
//X[_]=_.
writeln('X[',i,']=',X[i]);
end;
var
A:array [1..10] of integer;
C: array of integer;
i:byte;
begin
//
// 10 .
for i:=1 to 10 do A[i]:= 2*i+1;

.., .., .. Free Pascal Lazarus

245

//
//3 :
SetLengTh(C,3);
//
// 3 .
for i:=0 to 2 do C[i]:= 1-2*i;
// .
outputArray(A);
outputArray(C);
end.
outputArray
:
// : ,
// 0 10.
type massiv=array [0..10] of integer;
//
// .
procedure outputArray(X:massiv;nN,nK:byte);
// :
//1. X.
//2. nN.
//3. nK.
var i:byte;
begin
// nN nK.
for i:=nN to nK do
writeln('X[',i,']=',X[i]);
end;
5.11
,
, , . ,
. . -

.., .., .. Free Pascal Lazarus

246

.
.
. , , .
, . ,
.
5.11.1
Free Pascal .
, . 4 .
, .
.
^, , :
type massiv=array [1..2500] of real;
var a:^integer; b,c:^real; d:^massiv;
Free Pascal ,
.
pointer, :
var p,c,h: pointer;
. ,
,
.
,
, . . ,
.
:
Var
p1, p2:^integer; p3:^real; pp:pointer;

.., .., .. Free Pascal Lazarus

247

p1:=p2; ,
p1:=p3; , p1 p3
.
, pp:=p3; p1:=pp;
.
Free Pascal
, . , .
heaporg, heapend. heapprt.
new, . , ,
, :
var
i,j:^integer;
r:^real;
begin
new(i);
new(R);
new(j)
i , heapprt.
heapprt 4,
integer, i,
4 . new(r)
heapprt, 8 ,
real.
. ,
,
- ^, :
i^:=4+3;
j^:=17;
r^:=2 * pi;

.., .., .. Free Pascal Lazarus

248

, , ,
, , ^.
^ . ^
, , . ( !) , , :
r^:=sqr(r^)+sin(r^+i^)-2.3

r:=sqr(r^)+i^;
r
.

r^:=sqr(r);
r , (
, ) . r^:=i,
, r^, (). , . dispose(p), ,
, , .


new, dispose ,
.
,
!

.
heapptr mark. , , mark, .
release.
mark heapptr

.., .., .. Free Pascal Lazarus

249

( mark(ptr), ptr , heapptr).


release(ptr), ptr , , .
5.11.2 getmem freemem

getmem, freemem. getmem(p,size), , size
(size word), .
freemem(p,size), , size (size
word), , .
.

: ?
, .
,
( )
, ,
. i- x^[i].

.
5.2.
X(N).
.
Program din_mas1;
Var
x:array [1..150] of real;
i,n:integer; max,min:real;
begin
writeln(' ');
readln (n);
for i:=1 to N do

.., .., .. Free Pascal Lazarus

250

begin
write('x[',i,']='); readln(x[i]);
end;
max:=x[1]; min:=x[1];
for i:=2 to N do
begin
if x[i] > max then max:=x[i];
if x[i] < min then min:=x[i];
end;
writeln('=',max:1:4);
writeln('=',min:1:4);
end.

.
newdispose ( din_mas2) getmemfreemem ( din_mas2).
type massiw= array[1..150]of real;
var
x:^massiw;
i,n:integer;
max,min:real;
begin
{
150 .}
new(x);
writeln(' ');
readln(n);
for i:=1 to N do
begin
write('x(',i,')=');
readln(x^[i]);
end;
max:=x^[1];min:=x^[1];
for i:=2 to N do
begin
if x^[i] > max then max:=x^[i];
if x^[i] < min then min:=x^[i];
end;

.., .., .. Free Pascal Lazarus

251

writeln('=',max:1:4,
' =',min:1:4);
{ . }
dispose(x);
end.
type
massiw=array[1..150]of real;
var
x:^massiw;
i,n:integer;max,min:real;
begin
writeln(' ');
readln(n);
{ n . }
getmem(x,n*sizeof(real));
for i:=1 to N do
begin
write('x(',i,')=');
readln(x^[i]);
end;
max:=x^[1];min:=x^[1];
for i:=2 to N do
begin
if x^[i] > max then max:=x^[i];
if x^[i] < min then min:=x^[i];
end;
writeln('=',max:1:4,
' =',min:1:4);
{ . }
freemem(x,n*sizeof(real));
end.
:
1. .
2. ( new getmem).
3. .
4. ( dispose freemem).

.., .., .. Free Pascal Lazarus

252

5.12
5.3. , k . .
.
. , . 5.35 ,

5.35:



, ,
. , , .
. , 5.36,
m. B m . B , m=0 ( 2). ( 3)
A, A ( 5),
m , m ( 6). 7
, A B. B , k .

.., .., .. Free Pascal Lazarus

253

5.36: - B A
.
var a,b:array [1..200] of word; k,m,i:byte;
begin
write(' =');
readln(k);
m:=0;
for i:=1 to k do
begin
write('A[',i,']=');readln(A[i]);
if A[i]<0 then
begin
m:=m+1;
B[m]:=A[i];

.., .., .. Free Pascal Lazarus

254

end;
end;
if m>0 then
for i:=1 to m do write(B[i],' ')
else
write(' ');
end.
5.4. y n .
z , y, , , .
, - , . - 5.4 . 5.37.
.
var i,k,n: integer;
y,z:array [1..50] of integer;
begin
writeln(' n<=50'); readln (n);
for i:=1 to n do // y.
begin
write('y[',i,']='); readln(y[i]);
end;
k:=0;
//
// y z.
for i:=1 to n do
if y[i] < 0 then
begin
k:=k+1; z[k]:=y[i];
end;
//
// y z.
for i:=1 to n do
if y[i] >0 then
begin k:=k+1;
z[k]:=y[i]
end;

.., .., .. Free Pascal Lazarus

5.37: 5.4

255

.., .., .. Free Pascal Lazarus

256

//
//y z.
for i:=1 to n do
if y[i]=0 then
begin
k:=k+1;
z[k]:= y[i];
end;
// Y.
writeln (' Y:');
for i:=1 to n do
write(y[i],' ');
writeln;
// Z.
writeln (' Z:');
for i:=1 to n do
write (z[i],' ');
writeln;
end.
5.5. X .

: 1-
n- , 2- n-1- , , i
n+1-i. -

. 5.38.

5.38:
5.5.
5.5
type
massiv=array [1..100] of real;
var
x:massiv;
i,n:integer;

.., .., .. Free Pascal Lazarus

257

b:real;
begin
// .
writeln (' '); readln(n);
// .
for i:=1 to n do
begin
write ('x[',i,']=');
readln(x[i]);
end;
// ,
// 1- c n,
//2 (n-1), i- c (n+1-i)- .
for i:=1 to n div 2 do
begin
b:=x[n+1-i];
x[n+1-i]:=x[i];
x[i]:=b;
end;
// .
writeln(' ');
for i:=1 to n do
write(x[i]:1:2,' ');
end.
5.6. X, n ,
.
(k=0). . , 1
(k:=k+1). 4,
. (k>4), ( ).
- . 5.39.
.
const n=20;
var

.., .., .. Free Pascal Lazarus

X:array [1..n] of byte;


k,i,j:integer;
begin
for i:=1 to n do
readln(X[i]);
k:=0;
{ .}
j:=1;
{ .}
while j<=n do
{ .}
begin
{ , }
if x[j]=0 then
begin
k:=k+1; { }
if k>4 then
break
{ k 4, .}
{ j- .}
else
for i:=j to n-k do
X[i]:=X[i+1];
end
{ ,
.}
else
j:=j+1; { }
end;
{ .}
{
k.}
for i:=1 to n-k do
write(X[i],' ');
end.

258

.., .., .. Free Pascal Lazarus

259

n
i=1,n

J<=n

Xi

+
Xj=0

k=0
j=1

k=k+1

j=j+1

K>4

i=1,n-k
i=j,n-k
Xi

X i=Xi+1

5.39: 5.6
5.7. C(N).
. 0.
,
, . ,
, prostoe, ,
.

.., .., .. Free Pascal Lazarus

260

- .5.40.

5.40: - prostoe
Prostoe :
function Prostoe(N:integer):boolean;
true, N .
false. 5.7 . 5.41.

.., .., .. Free Pascal Lazarus

261

5.41: -
5.7
, ,
.
function prostoe(N:integer):boolean;
var i:integer; pr:boolean;
begin
if N<1 then
pr:=false
else

.., .., .. Free Pascal Lazarus

262

begin
{ , . }
pr:=true;
for i:=2 to N div 2 do
if (N mod i = 0) then
{ ,
, }
begin
{ }
pr:=false;
{ . }
break;
end; end;
prostoe:=pr;
end;
{ }
var
c:array [1..50] of word;
i,n:byte; S:word;
begin
write(' n=');
readln(n);
for i:=1 to n do
begin
write(' ',i,'- ');
readln(C[i]);
end;
S:=0;
for i:=1 to n do
{ , . }
if prostoe(C[i]) then
S:=S+C[i];
{ .}
writeln(' S=',S);
end.
5.8. , , (. 5.42).
, .

.., .., .. Free Pascal Lazarus

263

5.42:

.
1 n-1 ( , , , ). ( ), ( k) 65.
, : , .
, k
. k>1,
, (kol) 1.
, . (k>1),
(kol) 1. kol. - 5.8 . 5.43.
Free Pascal.
var
x:array[1..50] of real;
n,i,k,kol:integer;
begin
write('n=');
readln(n);
for i:=1 to n do
read(x[i]);
{
, }
{ k 1. }
k:=1; { . }
65 ,
, .

.., .., .. Free Pascal Lazarus

5.43: 5.8
kol:=0; { . }
for i:=1 to n-1 do
{

264

.., .., .. Free Pascal Lazarus

265

,
. }
if x[i]*x[i+1]<0 then
k:=k+1 { . }
else
begin
{ ,
. }
if k>1 then
kol:=kol+1;
{ }
{ . }
k:=1;
end;
{, . }
if k>1 then
{ , . }
kol:=kol+1;
if kol>0 then
write('
=',kol)
else
write(' ')
end.
5.9.
, .
(max),
(kon_max).
, ,
, ,
. : , , .
,
(kon) (k).
.
(kol) (k) .

.., .., .. Free Pascal Lazarus

266

. 1, 66 1. 1,
: ,
.
, k . k>1, , (kol) 1,
(kon:=i-1), (dlina:=k). , . (kol=1), , max k, kon_max kon ( ). (kol>1),
(k) (max).
k>max, (max:=k; kon_max:=kon;). ,
(k:=0).
,
, . , , .
- . 5.44.
.
var x:array[1..50] of integer;
n,i,k,kol,kon,max,kon_max,dlina:integer;
begin
{ .}
write('n=');
readln(n);
{ }
writeln(' ');
for i:=1 to n do
read(x[i]);
{
}
k:=0; { . }
kol:=0; { . }
66 .

.., .., .. Free Pascal Lazarus

5.44: - 5.9

267

.., .., .. Free Pascal Lazarus

{ }
for i:=1 to n do
{ 1, }
if x[i]=1 then
{
1.}
k:=k+1
else
{ 1, }
begin
{ , , k>1?}
if k>1 then
{ , }
begin
{ .}
kol:=kol+1;
{ ,
,}
kon:=i-1;
{ k.}
dlina:=k;
{ ,}
if kol=1 then
{ .}
begin
{ .}
max:=dlina;
{ ,
, kon_max.}
kon_max:=kon;
end
{ ,
,}
else
{
.}
if k>max then
{ ,}

268

.., .., .. Free Pascal Lazarus

269

begin
{ .}
max:=dlina; kon_max:=kon;
end;
end;
{ 1,

(k:=0).}
k:=0;
end;
{, . }
if k>1 then
{ , . }
begin
kol:=kol+1;
{ }
kon:=n; dlina:=k;
{ ,
.}
if kol=1 then
begin
max:=dlina; kon_max:=kon;
end
else
if k>max then
begin
max:=dlina; kon_max:=kon;
end;
end;
{ , }
if kol>0 then
{
.}
begin
writeln(' ,
=',kol);
writeln('
',kon_max-max+1,',

.., .., .. Free Pascal Lazarus

270

', kon_max,', ', max)


end { .}
else writeln(' , ')
end.
5.10. .
p- .


. :
1. .
2. .
3. .
4.
.
.
.
. . 10 . , ; ,
, . .
, 0. ,
, .

.
.
,
101 .
,
.
(
102 ),

.
- N 10- . 5.45.

.., .., .. Free Pascal Lazarus

5.45: - p-

271

.., .., .. Free Pascal Lazarus

272

, -
.
10, 0, , q,
1, 10.
10: 101 , 102 , .
q:=0.1, 10.
5.10
.
{ p- , :
N,
p, kvo .}
function perevod(N:real;P:word;kvo:word):real;
var i ,N1, ost: word;
s1, N2, r, s2:real;
q:real;
begin
{ ,
perevod,
.}
if N<0 then r:=-perevod(abs(N),P,kvo)
else
begin
{ N1 N2 N.}
N1:=trunc(N);N2:=frac(N);
s1:=0;s2:=0;
{ q
, 1
0 ,
q 10.}
q:=1;
{ . 0.}

.., .., .. Free Pascal Lazarus

273

while (N1<>0) do
begin
{ ost ,
N1 .}
ost:=N1 mod P;
{ 10 i s1.}
s1:=s1+ost*q;
{ N1 p
p.}
N1:=N1 div P;
{ .}
q:=q*10;
end;
{ q
, 0.1 ,
q 10.}
q:=0.1;
for i:=1 to kvo do
begin
{ 10.}
N2:=N2*p;
{
N2 . 10 i s2.}
s2:=s2+trunc(N2)*q;
{ }
N2:=frac(N2);
{ 10.}
q:=q/10;
end;
{ p- .}
r:=s1+s2;

.., .., .. Free Pascal Lazarus

274

end;
perevod:=r;
end;
var C:array[1..100] of real;
p,i,n:word;
begin
{ .}
Write('n=');readln(n);
{ .}
writeln(' C');
for i:=1 to n do read(C[i]);
{ .}
writeln('
');
readln(p);
{ .}
for i:=1 to n do
c[i]:=perevod(C[i],p,5);
{ .}
writeln(' C');
for i:=1 to n do
write(C[i]:1:5,' ');
end.
. 5.46.

5.46:
5.10
5.11. Y 3 , .

.., .., .. Free Pascal Lazarus

275

,
,
.
:
function vosem(N:word):boolean;
vosem ( N), true,
false .
,

. ,
.
.
function vosem(N:word):boolean;
var pr:boolean;
tsifra,tsifra_st:word; i:integer;
begin
i:=0;
{, N
.}
pr:=true;
{ N 0, }
while N<>0 do
begin
{
.}
tsifra:=N mod 8;
{ 8 .}
N:=N div 8; i:=i+1;
{ }
if i>1 then {
, 8-
N

(pr:=false) .}
if tsifra<=tsifra_st then

.., .., .. Free Pascal Lazarus

276

begin
pr:=false; break;
end;
tsifra_st:=tsifra;
end;
vosem:=pr;
end;
. , ,
. , (k)
1. k3 , .
,
5.11. : , , .
, . 5.47.

5.47: 5.11
5.65.7. Label1,
Edit1 Button1.

.., .., .. Free Pascal Lazarus

277

5.6: ,
Name

Caption (Text)

Width

Visible

Left

Top

label1 153
true
120 46
label2
false
110
192 96
label3 157
false
192 210
Edit1
true
7
40
288 40
Button1 OK
true
75
376 35
Button2 185
false
160 448
Button3
false
185
568 448
5.7:

1
2
Name
StringGrid1
StringGrid2
ColCount
7
7
RowCount
1
1
Visible
false
false
FixedCols
0
0
FixedRows
0
0
Options.goEditing true
true
OK (Button1) Edit1 ,
Label2, StringGrid1
. Label1, Edit1
Button1 .
OK . 5.48.

:
StringGrid1;

,
;
Label3, StringGrid2
.

.., .., .. Free Pascal Lazarus

278

.
5.11 , . 5.49

5.48:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls, Grids;
{ }
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;

.., .., .. Free Pascal Lazarus

279

procedure Button1Click(Sender: TObject);


procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type massiv=array[1..100] of word;
var
Form1: TForm1;
N:word;
X:massiv;
implementation
{ TForm1 }
{ vosem ,
N }
function vosem(N:word):boolean;
var pr:boolean;
tsifra,tsifra_st:word;
i:word;
begin
i:=0;
{, N
.}
pr:=true;
{ N 0, }
while N<>0 do
begin
{
.}
tsifra:=N mod 8;
{ 8 .}
N:=N div 8;
i:=i+1;
{ }

.., .., .. Free Pascal Lazarus

280

if i>1 then
{ ,
N (pr:=false)
.}
if tsifra<=tsifra_st then
begin
pr:=false;
break;
end;
tsifra_st:=tsifra;
end;
vosem:=pr;
end;
{ X(N) c
m.}
procedure udal(var X:Massiv; m:word;var N:word);
var i:word;
begin
for i:=m to N-1 do
x[i]:=x[i+1];
N:=N-1;
end;
{ .}
procedure TForm1.Button1Click(Sender: TObject);
begin
{ .}
N:=StrToInt(Edit1.Text);
{ ,
.}
Label1.Visible:=False;
Edit1.Visible:=False;
Button1.Visible:=False;
{ , .}
label2.Visible:=True;
StringGrid1.Visible:=True;
{
.}

.., .., .. Free Pascal Lazarus

281

StringGrid1.ColCount:=N;
{ .}
Button2.Visible:=True;
Button3.Visible:=True;
end;
{
.}
procedure TForm1.Button2Click(Sender: TObject);
var k,i:word;
begin
{ .}
for i:=0 to N-1 do
X[i+1]:=StrToInt(StringGrid1.Cells[i,0]);
k:=0;
{ .}
for i:=N-1 downto 0 do
{ }
if vosem(x[i]) then
begin
{ 1.}
k:=k+1;
{ , ,
, .}
if k<=3 then
udal(x,i,N);
end;
{
.}
label3.Visible:=True;
StringGrid2.Visible:=True;
StringGrid2.ColCount:=N;
{ .}
for i:=0 to N-1 do
StringGrid2.Cells[i,0]:=IntToStr(X[i+1]);
end;
{ .}

.., .., .. Free Pascal Lazarus

282

procedure TForm1.Button3Click(Sender: TObject);


begin
Close;
end;
initialization
{$I unit1.lrs}
end.

5.49: 5.11
5.13
1.
Y. X
Y. Y ,
.
2. ,
. B , .
3. . Y. X.

.., .., .. Free Pascal Lazarus

283

4. ,
1x i 2 , Y. Y.
5. X Y. ,
Y.
6. X. .
7. X=(x1, x2, ,x12)
Y = (y1, y2, , y12), X
. X : (y1, y2, , y12) = (x10, x11, x12, x1, x2, , x9). X Y.
8. X = (x1, x2, , x15) Y = (y1,
y2 , , y15), X .
, X, : (y1, y2, , y15) = (x5, x6, , x15, x1, x2, x3, x4). Y.
9. X .
, .
10. X,
. , .
11. , ,
. , .
12. .
13. , .
14. , .

.., .., .. Free Pascal Lazarus

284

15. X. . . Y,
X, .
16. X
Y. ,
Y. Y
.
17.
X. X , .
18. X Y.
Z, Y Z
.
Z.
19.
X Y Z. Z. Z .
20. X , .
21. X Y
. ,
.
22. , , . , .
23. .
24. , .
25.
, , .

.., .., .. Free Pascal Lazarus

285

6 Free Pascal
, : .
() :
: array [1_ .. 1_,
2_ .. 2_] of ;
, ,
1_ .. 1_
, 2_ .. 2_
.
,
var h: array [0..11,1..10] of real;
h, ( 0 11,
1 10).
, :
type
_=array [1_ .. 1_]
of ;
var
: array [2_ .. 2_]
of _;

type
_=array [_] of ;
var
: _;
:
type
massiv=array [1..30] of integer;
matrica=array [0..15,0..13] of real;
var
a, b: array [1..10] of massiv;
c:matrica;

.., .., .. Free Pascal Lazarus

286

a b 10 30 ,
,
.

:
[_, _]

[_] [_]
, h[2,4]67 h,
.

. ,
,
(, ,
. .) .
, , .
. 6.1 - , . 6.2 . i , j
, N , M
A.

6.1:

67 h[2][4]

6.2:

.., .., .. Free Pascal Lazarus

287

6.1 -
, ,
() .
,
.
- . 6.3.

,
, , ,
6.3: -

2 3 13 35
5 26 76 37
52 61 79 17


. 6.4.

Free
Pascal 5.2
,
Ai , j c
A[i,j]
A[i][j].
6.4:

- .
read.
for i:=1 to N do
for j:=1 to m do
read(A[i,j]);

.., .., .. Free Pascal Lazarus

288



Enter.
6.1.
.
- .
var
a: array [1..20,1..20] of real;
i,j,n,m: integer;
begin
{ }
writeln('
A');
readln(n,m);
{ . }
writeln(' ');
for i:=1 to n do
for j:=1 to m do
read(A[i,j]);
{ . }
writeln (' ' );
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:8:3, ' ');
{ .}
writeln
{ .}
end;
. 6.5 .

. ,
.
for i:=1 to N do
for j:=1 to m do
begin
write('A(',i,',',j,')=');
readln(A[i,j])
end;

.., .., .. Free Pascal Lazarus

289

6.5: 6.1
-
TStringGrid, .
.
6.2. 68 A.
- . 6.6. A(N,M) B(M,N).

A(4,3).
Label1 Label2
Caption A
6.6: B,
TStringGrid, A
,
. 6.1, .
6.1: StringGrid1, StringGrid2.

Top

StringGrid1

StringGrid2

30

30

68 , A(N,M)
.

.., .., .. Free Pascal Lazarus

290

StringGrid1 StringGrid2

Left

15

240

Height
Width
ColCount

130
200
4

130
200
5

RowCount
DefaultColWidth
DefaultRowHeight
Options.goEditing

5
30
20
true

4
30
20
false

. 6.7.

6.7:
,
, .

.., .., .. Free Pascal Lazarus

291

procedure TForm1.Button1Click(Sender: TObject);


const n=4;m=3; // A(n,m).
var
i,j:byte;
// :
//i , j .
// .
A:array [1..n,1..m] of integer;
// .
B:array [1..m,1..n] of integer;
Begin
//
// ,
// .
// .
for i:=1 to n do
// .
for j:=1 to m do
//
//A StringGrid1.
A[i,j]:=StrToInt(StringGrid1.Cells[j,i]);
// B,
//. - . 6.6.
// .
for i:=1 to n do
// .
for j:=1 to m do
B[j,i]:=A[i,j];
// B
// .
// .
for i:=1 to n do
// .
for j:=1 to m do
//
// .
StringGrid2.Cells[i,j]:=IntToStr(B[j,i]);
end;
. 6.8.

.., .., .. Free Pascal Lazarus

292

6.8: A(3,4)
-
TStringGrid A(4,3) B(3,4). A(N,M).
:
label1

;
label2 N=;
label3 M=;
label4 ;
label5 ;
Edit1 N;
Edit2 M;
StringGrid1 A;
StringGrid2
B;
Button1
;

.., .., .. Free Pascal Lazarus

293

Button2 ;
Button3
;
Button4
.
, . 6.9.

6.9:
A(N,M)
Visible False label4 label5, StringGrid1, StringGrid2,
Button2 Button3. , , (. . 6.10)69. A
B, N, M .
69 Caption .

.., .., .. Free Pascal Lazarus

294

6.10:
A(N,M)
type

{ TForm1 }
{ }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;

.., .., .. Free Pascal Lazarus

295

Label5: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
private
{ private declarations }
public
{ public declarations }
end;
var
{ A,B}
A,B:array[1..25,1..25] of integer;
{ }
N,M:integer;
Form1: TForm1;
.
procedure TForm1.Button4Click(Sender: TObject);
begin
Close;
end;
, , StringGrid1 StringGrid2 ( ), StringGrid1,
, ,
( label1, label2, label3,
Edit1 Edit2, ).
procedure TForm1.Button1Click(Sender: TObject);
var i:byte;kod_n,kod_m,kod:integer;
begin
// .
//
//
Val(Edit1.Text,N,kod_m); // M
Val(Edit2.Text,M,kod_n); // N.
//
//

.., .., .. Free Pascal Lazarus

296

// A B,
if (kod_n=0) and (kod_m=0) and (N>0) and
(N<26) and (M>0) and (M< 26) then
//
begin
// ,
StringGrid1.Visible:=true;
// ,
Label4.Visible:=true;
Button2.Visible:=true;//
// .
Button3.Visible:=true;
with StringGrid1 do
begin
// (RowCount)
// (ColCount)
// StringGrid1.
ColCount:=M+1;
RowCount:=N+1;
//
for i:=1 to RowCount-1 do
Cells[0,i]:=IntToStr(i);
for i:=1 to ColCount-1 do
Cells[i,0]:=IntToStr(i);
end;
StringGrid2.ColCount:=N+1;
StringGrid2.RowCount:=M+1;
end
else
begin
//
// .
MessageDlg(' !',
MtInformation,[mbOk],0);
//
// .
Edit1.Text:='4';
Edit2.Text:='3';

.., .., .. Free Pascal Lazarus

297

end;
end;
.

StrigGrid2,
B, (label5),
B. B StringGrid2. . .
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
// ,
// ,
StringGrid2.Visible:=true;
label5.Visible:=true;
for i:=1 to N do
// .
for j:=1 to M do
// .
// A
// StringGrid1.
A[i,j]:=StrToInt(StringGrid1.Cells[j,i]);
with StringGrid2 do
begin
for i:=1 to RowCount-1 do //
Cells[0,i]:=IntToStr(i);
// StringGrid2,
// B.
for i:=1 to ColCount-1 do
Cells[i,0]:=IntToStr(i);
end;
// B.
for i:=1 to N do
// .
for j:=1 to M do
// .
B[j,i]:=A[i,j];
// B
// .
for i:=1 to n do
// .
for j:=1 to m do
// .
//

.., .., .. Free Pascal Lazarus

298

// .
StringGrid2.Cells[i,j]:=IntToStr(B[j,i]);
Buuton1.Visible:=False; end;
,
.
:

StringGrid1,
StringGrid2;
StringGrid1, StringGrid2 labe4 label5, ;
;

(N=4, M=3).

:
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
begin
// StringGrid1.
with StringGrid1 do
for i:=1 to RowCount-1 do
for j:=1 to ColCount-1 do
Cells[j,i]:='';
// StringGrid2.
with StringGrid2 do
for i:=1 to RowCount-1 do
for j:=1 to ColCount-1 do
Cells[j,i]:='';
//
//StringGrid1, StringGrid2,
//labe4, label5.
StringGrid1.Visible:=False;
StringGrid2.Visible:=False;
label4.Visible:=False;
label5.Visible:=False;
//

.., .., .. Free Pascal Lazarus

299

// .
Button2.Visible:=False;
Button3.Visible:=False;
// .
Button1.Visible:=True;
//
// (N=4, M=3).
Edit1.Text:='4';
Edit2.Text:='3';
end;
. . 6.11
A(2,4).

6.11: A(2,4)

with _ do ;
.
With .
, A

.., .., .. Free Pascal Lazarus

300

for i:=1 to StringGrid1.RowCount-1 do


for j:=1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:='';

with StringGrid1 do
for i:=1 to RowCount-1 do
for j:=1 to ColCount-1 do
Cells[j,i]:='';
.
(. 6.12):

6.12:
(i=j),
;
(i>j),
;
(i<j), ;
,
i+j1=n;
i+j1<n ,
;
, , ,
i+j1>n.
6.2

.
6.3. ,
(. . 6.13).

.., .., .. Free Pascal Lazarus

6.13:

6.3

301


. (. . 6.14) : S
(S:=0). (
, )
,
, (
i<j).


:
var
a:array [1..15,1..10]
of real;
i,j,n,m: integer;
s: real;
begin
write(' ');
writeln('');
write('n - ');
writeln(': ');
readln (n);
write('m ');
writeln(': ');
readln (m);
writeln(' A:');

6.14: -
6.3 ( 1)

for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
s:=0;
for i:=1 to n do
for j:=1 to m do
{ ,}
if j>i then
s:=s+a[i,j];{ . }

.., .., .. Free Pascal Lazarus

302

writeln(' ');
for i:=1 to n do
begin
for j:=1 to m do
{ ,
!}
write(a[i,j]:8:3,' ');
writeln
end;
writeln(' ', s:8:3);
end.
. 6.15.

6.15: 6.3
. 6.16.
i<j , , ,
, . 6.13.

.., .., .. Free Pascal Lazarus

303



, .
, ,
i (i+1)
. , 1 N,
i+1 M.
,

6.16: - - .
6.3 ( 2)
6.4.
A, .
.
, 6.17, .
, . ,
, ,
.
. 6.17, , , . , A1,1
,
, A N , N ,
. , N ( 6.17 ), (N div 2 +1, N div 2 +1),
. N ( . 6.17) .

.., .., .. Free Pascal Lazarus

304

6.17: 6.4
. ,
. , i
1 N, Ai , i . , , :
i+j-1=N j=N-i+1,
, i=1,2,,N Ai , N i1
. , ,
: A1, i , (i=1,2,,N), A N ,i , (i=1,2,,N) Ai ,1 , (i=1,2,,N), Ai , N
(i=1,2,,N).
, , . (i=1,2,,N)
Ai , i Ai , N i1 .
for i:=1 to N do
begin
if (a[i,i]>0) then
k:=k+1;
if a[i,N-i+1]>0 then k:=k+1;
end;

, ,
, .

.., .., .. Free Pascal Lazarus

305


, .
for i:=2 to N-1 do
begin
{ . }
if (a[1,i]>0) then
k:=k+1;
{ . }
if (a[N,i]>0) then
k:=k+1;
{ . }
if (a[i,1]>0) then
k:=k+1;
{ . }
if (a[i,N]>0) then
k:=k+1;
end;
, , , .
, N , 70, .
if (N mod 2 <>0) and (a[n div 2+1,n div 2+1]>0)
then k:=k-1;

6.4 . . 6.18
6.4.
var
a:array [1..10,1..10] of integer;
i,j,N,k:integer;
begin
write('N=');
readln(N);
// .
writeln(' A');
for i:=1 to N do
for j:=1 to N do
read(a[i,j]);
// .
writeln(' A:');

70 (N div 2 +1, N div 2 +1)

.., .., .. Free Pascal Lazarus

6.18: 6.4
for i:=1 to N do
begin
for j:=1 to N do
write(a[i,j],' ');
writeln;
end;
k:=0;
// ,
// .
for i:=1 to N do
begin
if (a[i,i]>0) then
k:=k+1;
if a[i,N-i+1]>0 then k:=k+1;
end;
// ,
// .
for i:=2 to N-1 do
begin
if (a[1,i]>0) then k:=k+1;
if (a[N,i]>0) then k:=k+1;
if (a[i,1]>0) then k:=k+1;

306

.., .., .. Free Pascal Lazarus

307

if (a[i,N]>0) then k:=k+1;


end;
{ , , , k . }
if (n mod 2<>0) and (a[N div 2+1,N div 2+1]>0)
then
k:=k-1;
writeln('k=',k);
end.
6.5. , .
, , . ,
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
. , ,
(pr:=true) .
(i:=1,2,...,N) (j:=1,2,...,N) . ( i= j )
, ( i j ),
71, pr false ( ).
pr, pr
true, , .
var a:array[1..10,1..10] of real;
i,j,n:integer;
pr:boolean;
begin
writeln(' ');
readln(n);
writeln(' ');
for i:=1 to n do
71 and or, if
((i=j) and (a[i,j]<>1)) or ((i<>j) and (a[i,j]<>0)) then

.., .., .. Free Pascal Lazarus

308

for j:=1 to n do
read(a[i,j]);
{, ,

.
,
, .}
pr:=true;
for i:=1 to n do
for j:=1 to n do
if ((i=j) and (a[i,j]<>1)) or ((i<>j)
and (a[i,j]<>0)) then
{
, }
begin
{ ,
, .}
pr:=false;
{ . }
break;
end;
{
.}
if pr then
writeln(' ')
else
writeln(' ');
end.
6.6. , .

,
. -
. 6.19.
.

.., .., .. Free Pascal Lazarus

6.19: - 6.6

309

.., .., .. Free Pascal Lazarus

310

var a:array[1..25,1..25] of real;


i,j,n,m:integer;
max,min:real;
begin
{ .}
writeln(' ');
readln(n,m);
{ .}
writeln(' ');
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
{ .}
for j:=1 to m do
begin
{
(j-) .}
max:=a[1,j];
min:=a[1,j];
{ (j-) .}
for i:=2 to n do
begin
{ ,
.}
if a[i,j]>max then max:=a[i,j];
{ ,
.}
if a[i,j]<min then min:=a[i,j];
end;
{
.}
a[n,j]:=max-min;
end;
{ .}
writeln(' ');

.., .., .. Free Pascal Lazarus

311

for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:7:3,' ');
writeln;
end;
end.
,
. (. 6.9)
A(N,M), 6.2. . ,
Caption label5
A. Caption .
. 6.20.

6.20: 6.6
, ,
.
.
StringGrid1, A

.., .., .. Free Pascal Lazarus

312

, . 6.19,
StringGrid2.
6.6 .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls,Grids;
//
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
A:array[1..25,1..25] of real;

.., .., .. Free Pascal Lazarus

313

N,M:integer;
Form1: TForm1;
implementation
{ TForm1 }
// .
procedure TForm1.Button4Click(Sender: TObject);
begin
Close;
end;
//
// .
procedure TForm1.Button1Click(Sender: TObject);
var i:byte;kod_n,kod_m,kod:integer;
begin
// .
//
// N M.
Val(Edit1.Text,N,kod_m);
Val(Edit2.Text,M,kod_n);
//
//
// A B,
if (kod_n=0) and (kod_m=0) and (N>0) and
(N<26) and (M>0) and (M< 26) then
//
begin
// ,
StringGrid1.Visible:=true;
// ,
Label4.Visible:=true;
//
Button2.Visible:=true;
// .
Button3.Visible:=true;
with StringGrid1 do
begin
ColCount:=M+1;
RowCount:=N+1;

.., .., .. Free Pascal Lazarus

314

//
for i:=1 to RowCount-1 do
Cells[0,i]:=IntToStr(i);
// .
for i:=1 to ColCount-1 do
Cells[i,0]:=IntToStr(i);
end;
StringGrid2.ColCount:=M+1;
StringGrid2.RowCount:=N+1;
end
else
begin
//
// .
MessageDlg('

!',MtInformation,[mbOk],0);
//
// .
Edit1.Text:='4';
Edit2.Text:='3';
end; end;
// .
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
max,min:real;
begin
StringGrid2.Visible:=true;
label5.Visible:=true;
for i:=1 to N do
// .
for j:=1 to M do // .
// A
// StringGrid1.
A[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);
with StringGrid2 do
begin
for i:=1 to RowCount-1 do //
Cells[0,i]:=IntToStr(i); //
// 2- .

.., .., .. Free Pascal Lazarus

315

for i:=1 to ColCount-1 do


Cells[i,0]:=IntToStr(i);
end;
// 6.6.
for j:=1 to m do
begin
{
(j-) .}
max:=a[1,j];
min:=a[1,j];
{ (j-) .}
for i:=2 to n do
begin
{ ,
.}
if a[i,j]>max then max:=a[i,j];
{ ,
.}
if a[i,j]<min then min:=a[i,j];
end;
{
.}
a[n,j]:=max-min;
end;
// A

// .
for i:=1 to N do
// .
for j:=1 to M do // .
// A
StringGrid2.
StringGrid2.Cells[j,i]:=FloatToStr(A[i,j]);
// .
Button1.Visible:=False;
end;

.., .., .. Free Pascal Lazarus

316

// .
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
begin
// StringGrid1.
with StringGrid1 do
for i:=1 to RowCount-1 do
for j:=1 to ColCount-1 do
Cells[j,i]:='';
// StringGrid2.
with StringGrid2 do
for i:=1 to RowCount-1 do
for j:=1 to ColCount-1 do
Cells[j,i]:='';
//
//StringGrid1, StringGrid2,labe4, label5.
StringGrid1.Visible:=False;
StringGrid2.Visible:=False;
label4.Visible:=False;
label5.Visible:=False;
//
// .
Button2.Visible:=False;
Button3.Visible:=False;
// .
Button1.Visible:=True;
//
// (N=4, M=3).
Edit1.Text:='4';
Edit2.Text:='3';
end;
initialization
{$I unit1.lrs}
end.
. 6.21 .

.., .., .. Free Pascal Lazarus

317

6.21: 6.6
6.7. n- r-
A(K,M).
n- r-
. . 6.22.

.
. 6.23.
type matrica=
array [1..15,1..15] of real;
var
6.22:
a:matrica; b:real;
-
i,j,k,m,n,r:byte;
6.7
begin
// .
write ('k=');readln(k);
write ('m=');readln(m);
// A.

.., .., .. Free Pascal Lazarus

writeln(' A');
for i:=1 to k do
for j:=1 to m do read(a[i,j]);
// ,
// .
repeat
write('n=');readln(n);
write('r=');readln(r);
{ , n r
m .}
until (n<=m) and (r<=m) and (n<>r);

6.23: 6.7
{ r
n.}
for i:=1 to k do
begin
b:=a[i,n];
a[i,n]:=a[i,r];
a[i,r]:=b
end;
writeln(' A');
for i:=1 to k do
begin
for j:=1 to m do

318

.., .., .. Free Pascal Lazarus

319

write(a[i,j]:7:3,' ');
writeln;
end;
end.
6.8. A(m,n) ,
, c
.
.
. , , , .
- . 6.24.
.
. 6.25 .
var
a:array [1..15,1..15] of real;
j,i,k,m,n:byte;
b:real;
begin
// .
writeln(' m n');
readln(m,n);
// .
writeln(' ');
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
// .
for i:=1 to m do
if (i mod 2)=0 then
{ , }
begin
{ . }

.., .., .. Free Pascal Lazarus

6.24: - 6.8

320

.., .., .. Free Pascal Lazarus

{
.}
for k:=1 to n-1 do
for j:=1 to n-k do
if a[i,j] > a[i,j+1] then
begin
b:=a[i,j];
a[i,j]:=a[i,j+1];
a[i,j+1]:=b;
end
end
else { ,
.}

6.25: 6.8
{
.}
for k:=1 to n-1 do
for j:=1 to n-k do
if a[i,j] < a[i,j+1] then
begin
b:=a[i,j];
a[i,j]:=a[i,j+1];
a[i,j+1]:=b;
end;

321

.., .., .. Free Pascal Lazarus

322

// .
writeln(' A');
for i:=1 to m do
begin
for j:=1 to n do
write (a[i,j]:7:3,' ');
writeln
end
end.
6.9.
A(n,m). P(n), , ,
0.
: ,
,
. , ,
5.7.
.
function prostoe(N:integer):boolean;
var i:integer; pr:boolean;
begin
if N<1 then pr:=false
else
begin
pr:=true;
for i:=2 to N div 2 do
if (N mod i = 0) then
begin
pr:=false;
break;
end;
end;
prostoe:=pr;
end;
(. 5.45)

function perevod(N:real;P:word;kvo:word):real;

.., .., .. Free Pascal Lazarus

323

p- ( 5.10).
perevod. perevod4 , .
{ N
.}
function perevod4(N:word):word;
var
s1,i ,q, ost: word;
begin
{ s1 .}
s1:=0;
{ q
, 1
0 ,
q 10.}
q:=1;
{ .
0.}
while (N<>0) do
begin
{ ost ,
N 4 ( ).}
ost:=N mod 4;
{ 10 i s1.}
s1:=s1+ost*q;
{ N 4 4.}
N1:=N1 div 4;
{ .}
q:=q*10;
end;
{ .}

.., .., .. Free Pascal Lazarus

324

perevod:=s1;
end;
, .
(i:=1,2,..,n) : S (S:=0), (j:=1,2,...,m), , Ai , j , ,
S. j ,
i (S>0), , , S

P (P[i]:=perevod4(S)).
- . 6.26.

6.26: - 6.9
:
function prostoe(N:integer):boolean;
var i:integer; pr:boolean;
begin
if N<1 then pr:=false

.., .., .. Free Pascal Lazarus

325

else
begin
pr:=true;
for i:=2 to N div 2 do
if (N mod i = 0) then
begin
pr:=false; break;
end;
end;
prostoe:=pr;
end;
function perevod4(N:word):word;
var s1,q, ost: word;
begin
{ s1 .}
s1:=0;
{ q
, 1
0 ,
q 10.}
q:=1;
{ .
0.}
while (N<>0) do
begin
{ ost ,
N 4 ( ).}
ost:=N mod 4;
{ 10 i s1.}
s1:=s1+ost*q;
{ N 4 4.}
N:=N div 4;
{ .}
q:=q*10;

.., .., .. Free Pascal Lazarus

326

end;
{ 4- .}
perevod4:=s1;
end;
var S,i,j,n,m: word;
a:array[1..25,1..25] of word;
p:array[1..25] of word;
begin
// .
writeln(' ');
readln(n,m);
writeln(' A');{ .}
for i:=1 to n do
for j:=1 to m do read(A[i,j]);
{
.}
for i:=1 to n do
begin
S:=0;{ .}
{ i- .}
for j:=1 to m do
{ i-
, .}
if prostoe(A[i,j]) then
s:=s+A[i,j];
{ ,
p[i].}
if s>0 then p[i]:=perevod4(s)
{ ,
p[i]:=0.}
else p[i]:=0;
end;
// P.
writeln(' P');
for i:=1 to n do write(P[i],' ');
writeln;
end.

.., .., .. Free Pascal Lazarus

327

. 6.27.

6.27:
6.9
6.10.
A(N,M) B(M,L).
.
,
.
- , , . , A(N,M) B(M,L) C(N,L). C i , j i- A j-
B. C i , j
:
M

C i , j = Aik B kj , i = 1,N j = 1,L.

(6.1)

k =1

C(3,2)
A(3,3) B(3,2).
C 11 C 12
a 11 b11a 12 b21a 13 b31 a11 b12a12 b22a 13 b32
C 21 C 22 = a21 b11a 22 b21 a23 b31 a 21 b12 a 22 b22 a23 b32 .
C 31 C 32
a 31 b11a 32 b21a 33 b31 a31 b 12a 32 b22a 33 b32
, AB BA .
-, C

.., .., .. Free Pascal Lazarus

328

(6.1), . 6.28. . . 6.29.

6.29:
6.28: -


// .
type matrica=array [1..15,1..15] of real;
var a,b,c:matrica; i,j,M,N,L,k:byte;
begin
// .
writeln(' n,m l'); readln(N, M, L);
writeln(' A');// A.
for i:=1 to N do
for j:=1 to M do read(a[i,j]);
writeln(' B');// B.
for i:=1 to M do
for j:=1 to L do read(b[i,j]);
for i:=1 to N do // C.
for j:=1 to L do
begin

.., .., .. Free Pascal Lazarus

329

{ C[i,j] i- j- .}
c[i,j]:=0;
for k:=1 to M do
c[i,j]:=c[i,j]+a[i,k]*b[k,j];
end;
writeln(' C=A*B');// C=AB.
for i:=1 to N do
begin
for j:=1 to L do
write(c[i,j]:7:3,' ');
writeln;
end;
end.
6.11 A(N,M) , .
. ,
.
72.
, ,
.
:
1. Prostoe, , P
word . true, P
false .
Function Prostoe (P:word):Boolean;
2. Udal, X ,
. : X N, . :
Procedure Udal(var X:massiv; var N:word);
massiv
(, massiv = array [1..200] of word). -
Udal . 6.30.
72 , , .

.., .., .. Free Pascal Lazarus

330

6.30: - Udal
. , , i- . xi = x j , , -

.., .., .. Free Pascal Lazarus

331

j. .
3. Nalichie true, a b, false . :
Function Nalichie(a:word; b:massiv; N:word);
- . 6.31.
4. Vozr .
. .
Vozr : (-) N
(-).
:
Procedure Vozr(var x:massiv;
N:word);
6.11, .
6.32-6.33. ( 1-4)
, .
Pr false,
, Pr true.
0 (k:=0) ( 5).
6.31:
-
Nalichie
, , Prostoe. ( 8),
, ( 9).
, max, k 1 ( 1), , , -

.., .., .. Free Pascal Lazarus

332

mas k73.
, Pr true ( 10).
, Aij
max. Aij max ( 11), max Aij ,
k 1 ( ), mas[k] i , (
12). Aij =max ( 13), , max. k 1 mas[k] , , max.

( 6-14) max , k , mas
k , . Pr
true, , false .
( 15), ( 16),
Udal ( 17) mas , 74. ( 18), mas ( 19),
b ( 20-21) Vozr ( 22).
b i-
( 23-24).
( 25-27).
.

73 mas , .
74 , mas .

.., .., .. Free Pascal Lazarus

333

6.32: - 6.11 ()

.., .., .. Free Pascal Lazarus

6.33: - 6.11 ()
{ massiv
. }
type massiv=array[1..200] of word;
{ prostoe ,
N (true) (false). }
function prostoe(N:word):boolean;
var pr:boolean;i:word;
begin

334

.., .., .. Free Pascal Lazarus

335

if N>0 then
begin
{, N (pr=true)}
pr:=true;
{, N -
2 N/2.}
for i:=2 to n div 2 do
{ i,
N, }
if N mod i =0 then
begin
{ N (pr=false) }
pr:=false;
{ . }
break;
end
end
else pr:=false;
{
pr. }
prostoe:=pr;
end;
{ udal x ,
. , N -,
udal.}
procedure udal(var x:massiv; var n:word);
var i,j,m:word;
begin
i:=1;
{ ,
i=1,2,,N;i-
j=i+1,i+2,,n. }
while(i<=n) do
begin
j:=i+1;
while(j<=N) do

.., .., .. Free Pascal Lazarus

336

{ x[i] x[j], }
if x[i]=x[j] then
begin
{ (x[j]) . }
for m:=j to N-1 do x[m]:=x[m+1];
{
1,
, j-
. }
N:=N-1;
End
{ x[i] x[j], . }
else j:=j+1;
i:=i+1;
end;
end;
{ nalichie true, a
b, false . }
function
nalichie(a:word;b:massiv;n:word):boolean;
var
pr:boolean;
i:word;
begin
{, b
a, pr=false}
pr:=false;
{ . }
for i:=1 to N do
{ b a, pr true}
if b[i]=a then
begin
pr:=true;
{ . }

.., .., .. Free Pascal Lazarus

337

break
end;
{
pr. }
nalichie:=pr
end;
{ vozr x . }
procedure vozr(var x:massiv; n:word);
{ X -,
vozr. }
var i, j, b :word;
begin
for i:=1 to N-1 do
for j:=1 to N-i do
if x[j]>x[j+1] then
begin
b:=x[j];
x[j]:=x[j+1];
x[j+1]:=b;
end
end;
//
var
N, M, i, j, k, max :word;
A:array[1..20,1..20] of word;
pr, L: boolean;
mas, b:massiv;
begin
{ . }
write('N=');readln(N);
write('M=');readln(M);
writeln(' Matrica A');
for i:=1 to N do
for j:=1 to M do
read(A[i,j]);
{ , -

.., .., .. Free Pascal Lazarus

338

. }
Pr:=false;
{ , ,
0. }
k:=0;
{ . }
for i:=1 to N do
for j:=1 to M do
begin
{ , , A[I,j] . }
L:=Prostoe(A[i,j]);
{ }
if L then
{ ,}
if not Pr then
begin
{ pr true,}
Pr:=true;
{ 1,
k:=1}
k:=k+1;
{ max,
, , . }
max:=A[i,j];
{ mas[k] ,
A[I,j]}
mas[k]:=i
end
else
{ A[i,j] , max . }
if A[i,j]>max then
{ A[I,j]> max, }
Begin
{ 1, .. . }

.., .., .. Free Pascal Lazarus

339

k:=1;
{ max A[i,j], }
max:=A[i,j];
{ mas[k] , A[I,j]}
mas[k]:=i
end
else
{ A[i,j]=max ( ,
), }
if A[i,j]=max then
begin
{ 1. }
k:=k+1;
{ mas[k] , A[I,j]}
mas[k]:=i
end
end;
{ pr false,
, , }
if not Pr then writeln(' A ')
else
begin
{ mas, ,
, . }
Udal(mas,k);
{ . }
for i:=1 to N do
begin
L:=Nalichie(i,mas,k);
{ mas,}
if L then
begin
{ b}
for j:=1 to M do
b[j]:=A[i,j];

.., .., .. Free Pascal Lazarus

340

{ b . }
Vozr(b,M);
{ i-
A. }
for j:=1 to M do
A[i,j]:=b[j];
end
end;
writeln(' A');
for i:=1 to N do
begin
for j:=1 to M do write(A[i,j],' ');
writeln;
end
end
end.
. 6.34.

6.34: 6.11

6.7-6.11 , , 6.2,
6.6.

.., .., .. Free Pascal Lazarus

341

6.3
. ,
( ).
.
massiv din_massiv.
type massiv=array [1..1000] of real;
din_massiv=^massiv;
X .
Var X: array[1..100] of din_massiv;
.
1. ( N , M
).
2. .
for i:=1 to N do
getmem(X[i],M*sizeof(real));
X[i] , M real. N .
3. , i- j- , X[i]^[j].
4.
.
for i:=1 to N do
freemem(b[i],M*sizeof(real));
.
6.12.
B(N,M) , .
,

, .

.., .., .. Free Pascal Lazarus

342

{ massiv 1000
. }
type massiv=array [1..1000] of real;
{ . }
din_massiv=^massiv;
{ matrica ,
.}
matrica=array [1..100] of din_massiv;
var
Nmax,Nmin,i,j,n,m,k:word;
{ b. }
b:matrica;
a,max,min:real;
begin
{ N M. }
write('N=');readln(N);
write('M=');readln(M);
{ N M.}
for i:=1 to N do
getmem(b[i],M*sizeof(real));
{ B. }
writeln('Matrica B');
for i:=1 to N do
for j:=1 to M do
read(b[i]^[j]);
{ , , ,

. }
for i:=1 to N do
begin
{ ,
i- .}
max:=b[i]^[1];
Nmax:=1;
min:=b[i]^[1];

.., .., .. Free Pascal Lazarus

343

Nmin:=1;
for j:=2 to M do
begin
if b[i]^[j]>max then
begin
max:=b[i]^[j];
nmax:=j
end;
if b[i]^[j]<min then
begin
min:=b[i]^[j];
nmin:=j
end;
end;
{ , nmin nmax }
if nmax<nmin then
begin
j:=nmax;
nmax:=nmin;
nmin:=j;
end;
{ i- , nmin nmax, . }
j:=1;
while nmax-1-j>=nmin+1 do
begin
for k:=nmin+1 to nmax-1 -j do
if b[i]^[k]>b[i]^[k+1] then
begin
a:=b[i]^[k];
b[i]^[k]:=b[i]^[k+1];
b[i]^[k+1]:=a;
end;
j:=j+1;
end;
end;
{ . }

.., .., .. Free Pascal Lazarus

344

writeln(' B');
for i:=1 to N do
begin
for j:=1 to M do
write(b[i]^[j]:6:2, ' ');
writeln
end;
{ . }
for i:=1 to N do
freemem(b[i],M*sizeof(real));
end.
. 6.35.

6.35: 6.12
, .
6.4
1.
A(n,m). .
2.
X(n,n),
, . , .

.., .., .. Free Pascal Lazarus

345

3. D, C(k,m), G
C.
4. (n,m),
.
5. (n,n).
, ,
, .
.
6. (n,m) , .
7. F(k,p) , .
8. , A(n,n) (
, ), (
, ) ( ).
9. A(n,n) (n,n) ( ), (n,n) ( ) D(n,n) ( , ) .
10. A(m,n) B(n,m).
C=(AB)4.
11. , B(n,n) A(n,n).
A B
.
12. ,
B(n,n).
13. , A(n,n).
14. A B.
.

.., .., .. Free Pascal Lazarus

346

15. A
B. B ,
, .
16. A(n,n), B(n,n),
C(n,n), D(n,n), . ,
.
17. A(n,n), B(n,n),
C(n,n), D(n,n), . ,
.
18. A(n,m), B(r,p),
C(k,q). , .
19. ,
A(n,n).
20. D(n,n), A(m,n) B(n,m). C=(BA). , C(n,n)
D(n,n). D
.
21. A(n,n), B(n,n),
C(n,n), D(n,n), . ,
, .
22. (n,m)
, ,
.
23. A(n,n), B(n,n),
C(n,n), D(n,n), . ,
,
, .
24. A B. B , .
25. A(n,n) , .

.., .., .. Free Pascal Lazarus

347

7 Free Pascal
FreePascal
.
Lazarus,
.
.
7.1

. , , . ,
, ,
. , .
C ,
:

.
, (, , ..), , .
, ,
, .

. .
. , .
.
. . .

.., .., .. Free Pascal Lazarus

348


.
(, f) text.
var f:text;
75 :
var f:file of ; 76

file.
.
type
massiv=array[1..25]of real;
ff=file of real;
var
a:text; { a
}
b:ff; { f
}
c:file of integer; { c
}
d:file of massiv; { d , 25 . }
.
7.2

,
.
7.2.1 AssignFile
. 75 .
76 f , , (, real, integer ..), , .

.., .., .. Free Pascal Lazarus

349

AssignFile(f,s), f , s
( , ).
AssignFile .
var
f:file of real;
begin
// assign Windows.
AssignFile (f, 'd:\tp\tmp\abc.dat');
// assign Linux.
AssignFile(f,'/home/pascal/6/pr1/abc.dat');
7.2.2 reset, rewrite

,
reset rewrite.
reset(f) ( f )
, f, , .
.
rewrite(f) ( AssignFile) .
!!! , f, , .
7.2.3 loseFile
CloseFile(f), f ,
, rewrite,
reset.
CloseFile(f)
, .
, ,
, . , .

.., .., .. Free Pascal Lazarus

350

closefile
, . ,
.
, .
!!! CloseFile. .
7.2.4 rename
, f,
, ,
rename(f,s), f , s
( ).
7.2.5 erase
, f, erase(f), f
.
.
7.2.6 eof
eof(f) (end of file), f ,
(true), ,
(false). ,

.
7.2.7
write:
write(f, x1, x2,..., xn);
write(f, x);

f ,
x, x1, x2, ..., xn , .

.., .., .. Free Pascal Lazarus

351


. write x1, x2, ...,
xn ( ), f.
, f, read:
read(f, x1, x2, x3,..., xn);
read(f, x);

f ,
x, x1, x2, ..., xn ,
.
read
, f, x1, x2, ...,
xn. . , read , . eof.
,
:
1. .
2. ( AssignFile).
3. ( rewrite).
4. ( write).
5. ( CloseFile).

.
7.1. n .
:
1. rewrite.
2. n.
3. ( i 1 n) a, write.
4. closefile.
,

.., .., .. Free Pascal Lazarus

352

.
program pr1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
var f:file of real;
i,n:integer;
a:real;
begin
//
// .
AssignFile(f,'/home/pascal/6/pr1/abc.dat');
// .
rewrite(f);
// .
write('n=');
readln(n);
//
// .
for i:=1 to n do
begin
write('a=');
readln(a);
write(f,a);
end;
// .
//
//.
CloseFile(f)
end.

7.2. /home/evgeniy/pascal/6/pr2/
dat. , , .
-

.., .., .. Free Pascal Lazarus

353

.
. 7.2
OpenDialog
.
Dialogs (. . 7.1).

7.1: Dialogs
:
FileName: String
;
Filter: String ,
;
.
,
(. . 7.2).

:
Filter name
(, , ); Filter

(

*.*,
*.pas.
7.2:

, |. , , .7.2,
.
OpenDialog1.Filter:=

' C|*.c| |*.pas| |*.*';

.
. 7.2 C.
InitialDialog .

.., .., .. Free Pascal Lazarus

354

DefaultExt ,
, .
OpenDialog Execute, .
Execute true, .
(Cancel), Execute false.
FileName.
, .
Var
s:String;
begin
if OpenDialog1.Execute then
s:=OPenDialog1.FileName;
{ , ,
s}.
end;
, 7.2. .
1. .
2. .
3. ,
, .
4. .
( ).
:
1. Label1 Label2 .
2. Memo1 ,
.
3. Memo2 ,
.
4. OpenDialog1 .

.., .., .. Free Pascal Lazarus

355

5. Buttom1 .
6. Buttom2 .
(. .
7.1 7.8).
7.1:
Caption
Name


Form_File

7.2: label1
Caption
Visible


False

7.3: label2
Caption
Visible

False

7.4: Memo1
Lines
Visible

''
False

7.5: Memo2
Lines
Visible

''
False

7.6: OpenDialog1
DefaultExt
InitDialog
dat
/home/evgeniy/pascal/6/pr2/
7.7: Button1
Name
Visible
Caption
Button_File
True

7.8: Button2
Visible
Caption Name
False
Button_Close
.
7.3. ,
, ,
Visible False. -

.., .., .. Free Pascal Lazarus

356

. 7.4.

7.3:

7.4:
.
.

.., .., .. Free Pascal Lazarus

357

Filter
OpenDialog1. FormCreate .
procedure TForm_File.FormCreate(Sender: TObject);
begin
OpenDialog1.Filter:=
' |*.dat| |*.*';
end;
:
1. .
2. .
3. Visible True
label1 Memo1.
4. Memo1.
5. .
6. .
7. Visible True
label2 Memo2.
8. Memo2.
9. Visible True
Button_Close.
Button_FileClick
.
procedure Tform_File.Button_FileClick(
Sender: TObject);
var
f:file of real;
s:string;
a:array[1..100] of real;
nmax,nmin,i,j,n:integer;
sum,max,min:real;
begin
// .
if opendialog1.execute then
begin
// s.
s:=OpenDialog1.FileName;

.., .., .. Free Pascal Lazarus

//
// .
AssignFile(f,s);
// .
Reset(f);
// .
n:=0;
//
// Memo1.
label1.Visible:=true;
Memo1.Visible:=true;
// sum
// .
Sum:=0;
// ,
// .
while not eof(f) do
begin
// 1.
n:=n+1;
//
// .
read(f,a[n]);
// .
sum:=sum+a[n];
// Memo1.
Memo1.Lines.Add(FloatToStr(a[n]));
end;
// .
CloseFile(f);
//
// .
sum:=sum/n;
// ,
// .
max:=a[1];min:=max;nmin:=1;nmax:=1;
for i:=2 to n do
begin

358

.., .., .. Free Pascal Lazarus

if a[i]>max then
begin
max:=a[i]; nmax:=i;
end;
if a[i]<min then
begin
min:=a[i]; nmin:=i;
end;
end;
//
// ,
//nmin nmax.
if nmax<nmin then
begin
i:=nmax;
nmax:=nmin;
nmin:=i;
end;
i:=nmin+1;
// ,
//
// .
while(i<nmax) do
begin
//
// ,
if a[i]<sum then
begin
// .
for j:=i to n-1 do a[j]:=a[j+1];
//
// 1.
n:=n-1;
nmax:=nmax-1;
end
//
// ,
else

359

.., .., .. Free Pascal Lazarus

360

// .
i:=i+1;
end;
//
// Memo2.
label2.Visible:=true;
Memo2.Visible:=true;
rewrite(f);// .
//
// Memo2.
for i:=1 to n do
begin
write(f,a[i]);
Memo2.Lines.Add(FloatToStr(a[i]));
end;
// , .
CloseFile(f);
Button_Close.Visible:=True;
end;
end;

.
.
procedure Tform_File.Button_CloseClick(
Sender: TObject);
begin
Close;
end;
.
,
. 7.4. ,
, . 7.5.
OK .
7.6. . 7.2 .

.., .., .. Free Pascal Lazarus

361


,
,
. . ,

.

,
7.5:

(
>100), .

7.6:

.., .., .. Free Pascal Lazarus

362

,
.
FreePascal

.

. ,
.
filesize(f)(f ), longint -
, f.
0.
filesize .
7.3. .
program Project1;
{$mode objfpc}{$H+}
uses Classes, SysUtils
{ you can add units after this };
//Massiw -
// 1000 .
type
massiw=array[1..1000] of real;
var
f:file of real;
//a - ;
a:^massiw;
n,i:word;
begin
//
// .
assignfile(f,'/home/pascal/6/pr1/abc.dat');
//
reset(f);
// n -

.., .., .. Free Pascal Lazarus

363

// f.
n:=filesize(f);
writeln(' ',n, ' ');
// a
// n .
getmem(a,n*sizeof(real));
for i:=1 to n do
begin
//
// .
read(f,a^[i]);
// .
write(a^[i]:1:3, ' ')
end;
// ,
// .
freemem(a,n*sizeof(real));
// .
closefile(f);
readln;
end.
filepos(f) longint
, f. filepos(f) 0.

filepos(f) filesize(f).
:
if filepos(f)=filesize(f) then
writeln(' ');
seek(f,n)
, f,
n ( 0). .
truncate(f), f , , , .
seek truncate -

.., .., .. Free Pascal Lazarus

364


.
7.4. /home/pascal/6/pr1/abc.dat
.
.

.
.
program Project1;
{$mode objfpc}{$H+}
uses Classes, SysUtils
{ you can add units after this };
var f:file of real;
i, nmax, nmin :integer;
a:array[0..200] of real;
max,min:real;
begin
assignfile(f,'/home/pascal/6/pr1/abc.dat');
reset(f);
//C .
for i:=0 to filesize(f)-1 do
begin
read(f,a[i]);
write(a[i]:1:2,' ');
end;
//
// .
max:=a[0]; nmax:=0;
min:=a[0]; nmin:=0;
//
// .
for i:=1 to filesize(f)-1 do
begin
if a[i]>max then
begin
max:=a[i];
nmax:=i

.., .., .. Free Pascal Lazarus

365

end;
if a[i]<min then
begin
min:=a[i];
nmin:=i
end;
end;
//
// .
//
// .
seek(f,nmax);
//
// .
write(f,min);
//
// .
seek(f,nmin);
//
// .
write(f,max);
// .
closefile(f);readln;
end.
. .
,
a . .

( ).
:
1. Label1 Label2 .
2. Edit1 ,
.
3. Edit2 , .

.., .., .. Free Pascal Lazarus

366

4. OpenDialog1 .
5. Button1 .
6. Button2 .
,
. 7.7.

7.7:
. FormCreate
.
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Caption:=
'
';
label1.Caption:=' ';
label1.Visible:=False;
label2.Caption:='
';

.., .., .. Free Pascal Lazarus

367

label2.Visible:=False;
Edit1.Text:='';
Edit1.Visible:=false;
Edit2.Text:='';
Edit2.Visible:=false;
OpenDialog1.Filter:=
' |*.dat| |*.*';
OpenDialog1.InitialDir:='/home/pascal/6/pr1';
Button1.Caption:=' ';
Button2.Caption:='';
Button2.Visible:=False;
end;
, , , TForm1.FormCreate .
, . 7.8.

, .
procedure TForm1.Button1Click(Sender: TObject);
var
f:file of real;
i,nmax,nmin:integer;
a,max,min:real;
s1,s:string;
begin
// .
if OpenDialog1.Execute then
begin
// s .
s:=OpenDialog1.FileName;
//
// .
assignfile(f,s);

.., .., .. Free Pascal Lazarus

7.8: 7.4
// .
reset(f);
// .
label1.Visible:=true;
Edit1.Visible:=true;
// s1
// .
S1:='';
//
//
// .
for i:=0 to filesize(f)-1 do
begin
//
// a.
read(f,a);
if i=0 then
//
// .
begin
max:=a;

368

.., .., .. Free Pascal Lazarus

nmax:=i;
min:=a;
nmin:=i;
end
else
begin
//
// ().
if max<a then
begin
max:=a;
nmax:=i
end;
if min>a then
begin
min:=a;
nmin:=i
end
end;
//
// s1.
s1:=s1+FloatToStr(a)+' ';
end;
//
// .
Edit1.Text:=s1;
// .
Edit1.ReadOnly:=true;
//
// .
//
// .
seek(f,nmax);
//
// .
write(f,min);
//
// .

369

.., .., .. Free Pascal Lazarus

370

seek(f,nmin);
//
// .
write(f,max);
// .
closefile(f);
reset(f);
// .
label2.Visible:=true;
Edit2.Visible:=true;
//
s1:='';
for i:=0 to filesize(f)-1 do
begin
read(f,a);
//
// s1.
s1:=s1+FloatToStr(a)+' ';
end;
//
// 2- .
Edit2.Text:=s1;
// .
Edit2.ReadOnly:=true;
// .
Button2.Visible:=True;
CloseFile(f);
end;
end;

.
.
procedure Tform_File.Button2Click(Sender:
TObject);
begin
Close;
end;
,

.., .., .. Free Pascal Lazarus

371

, . 7.5.
(.
. 7.9). .

7.9: 7.4

7.4 seek,
, . , , .
7.5. abc.dat.
.
, . : ,
. , .
program Project1;

.., .., .. Free Pascal Lazarus

372

{$mode objfpc}{$H+}
uses Classes, SysUtils
{ you can add units after this };
var
f:file of real;
max,min:real;
j, i,nmax,nmin:integer;
a:array [1..300] of real;
begin
assignfile(f,'/home/pascal/6/pr1/abc.dat');
reset(f);
// j
// .
j:=filesize(f);
// .
for i:=1 to j do read(f,a[i]);
for i:=1 to j do write(a[i]:1:2,' ');
writeln;
closefile(f);
// .
rewrite(f);
//
// .
max:=a[1];min:=a[1];
nmax:=1;nmin:=1;
//
// .
for i:=2 to j do
begin
if a[i]>max then
begin
max:=a[i];
nmax:=i
end;
if a[i]<min then
begin
min:=a[i];
nmin:=i;

.., .., .. Free Pascal Lazarus

373

end;
end;
// ,
//
// nmax nmin.
writeln(' ');
for i:=1 to j do
if (i<>nmax)and (i<>nmin) then
begin
write(f,a[i]);
// .
write(a[i]:1:2,' ');
end;
closefile(f);
readln;
end.
.
. nmin>nmax, nmin
nmax. , ( nmin nmax), . nmin. ,
nmax, . . .
program Project1;
{$mode objfpc}{$H+}
uses Classes, SysUtils
{ you can add units after this };
var
f:file of real;
a:real;
max,min:real;
i,nmax,nmin:integer;
begin
assign(f,'/home/pascal/6/pr1/abc.dat');
reset (f);

.., .., .. Free Pascal Lazarus

374

//
// .
writeln(' ');
for i:=0 to filesize(f)-1 do
begin
read(f,a);
write(a:1:2,' ');
if i=0 then
begin
max:=a;
nmax:=i;
min:=a;
nmin:=i
end
else
begin
if a>max then
begin
max:=a;
nmax:=i;
end;
if a<min then
begin
min:=a;
nmin:=i;
end
end
end;
writeln;
// nmin nmax.
if nmax<nmin then
begin
i:=nmax;
nmax:=nmin;
nmin:=i
end;
// ,
// nmin nmax,

.., .., .. Free Pascal Lazarus

375

// .
for i:=nmin to nmax-2 do
begin
seek(f,i+1);
read(f,a);
seek(f,i);
write(f,a);
end;
// ,
// nmax, .
for i:=nmax to filesize(f)-3do
begin
seek(f,i+1);
read(f,a);
write(a:1:2);
seek(f,i-1);
write(f,a);
write(a:1:2);
end;
// .
truncate(f);
closefile(f);
reset(f);
// .
writeln(' ');
for i:=1 to filesize(f) do
begin
read(f,a);
// .
write(a:1:2,' ');
end;
closefile(f);
end.

.
, .

.., .., .. Free Pascal Lazarus

376

7.3 Free Pascal


. reset rewrite.
Reset(var f: File; BuferSize:word);
Rewrite(var f: File; BuferSize:word);
BufSize
,
. , ,
(128) .
1 .

BlockWrite:
BlockWrite(var f:file; var X; Count:word;
var WriteCount:word);
f , X ,
, Count
BufSize, ,
WriteCount
.
BlockWrite Count , f77 X.
BlockWrite
WriteCount c Count.
BlockRead:
BlockRead(var f:file; var Y; Count:word;
var ReadCount:word);
f , Y ,
, Count
BufSize, ,
ReadCount BufSize, .
BlockRead , 77 Reset, Rewrite.

.., .., .. Free Pascal Lazarus

377

f, Count Y.
BlockRead ReadCount
c Count.

.
7.6.
.
.
, , .
program Project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
type
massiv=array[1..100000] of real;
var i,N:word;
f:file;
x:^massiv;
begin
Assignfile(f,'/home/pascal/6/pr_6/new_file.dat');
// ,
// 1 .
rewrite(f,1);
// N
//
write('N=');readln(N);
// f N,
// , 2 (sizeof(word)=2)
// N.
BlockWrite(f,N,sizeof(word));
// N x
// .
getmem(x,N*sizeof(real));
// .
writeln(' ');
for i:=1 to N do

.., .., .. Free Pascal Lazarus

378

begin
write('x(',i,')=');
readln(x^[i]);
end;
for i:=1 to N do
// f
// x^[i], , 8
//(sizeof(real)=8)
// x^[i].
BlockWrite(f,x^[i],sizeof(real));
//
//
// BlockRead
//BlockWrite(f,x^,N*sizeof(real));
//
//
//BlockWrite(f,x^,N*sizeof())
// .
// .
CloseFile(f);
// .
freemem(x,N*sizeof(real));
readln;
end.
7.6 (
).
:
1. Label1 Label2 .
2. Edit1 ,
.
3. Edit2 , .
4. OpenDialog1 .
5. Buttom1 .
,
. 7.10.

.., .., .. Free Pascal Lazarus

379

. 7.6 . .

7.10:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls,
Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
// :
//.

.., .., .. Free Pascal Lazarus

380

Button1: Tbutton;
// -
// .
Edit1: Tedit;
// -
// .
Edit2: Tedit;
//
Label1: TLabel;
Label2: Tlabel;
//
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
private declarations }
public
{ public declarations }
end;
massiv=array [1..50000] of real;
var
Form1: TForm1;
f:file;
implementation
{ TForm1 }
//
// ;
procedure Tform1.Button1Click(Sender: TObject);
var
x:^massiv;
y:array[1..3000] of real;
i,N:word;
max:real;
nmax:word;
s:string;
begin
// , .

.., .., .. Free Pascal Lazarus

381

if OpenDialog1.Execute then
begin
//
// s.
s:=OpenDialog1.FileName;
//
// , s.
AssignFile(f,s);
// ,
// 1 .
Reset(f,1);
// f (word) N ,
// , 2 (sizeof(word)=2)
// N.
BlockRead(f,N,sizeof(word));
// N x
// .
getmem(x,N*sizeof(real));
// f N
// x.
// N*sizeof(real)
// 1 .
// X ,
// .
BlockRead(f,x^,N*sizeof(real));
//
// Edit1.
Label1.Visible:=true;
Edit1.Visible:=true;
for i:=1 to N do
// x
// .
//
// .
Edit1.Text:=Edit1.Text+
FloatToStrF(x^[i],ffFixed,5,2)+' ';
// .
max:=x^[1];

.., .., .. Free Pascal Lazarus

382

nmax:=1;
for i:=2 to N do
if x^[i]>max then
begin
max:=x^[i];
nmax:=i;
end;
// .
for i:=nmax to N-1 do
x^[i]:=x^[i+1];
// .
N:=N-1;
// .
CloseFile(f);
AssignFile(f,s);
// .
Rewrite(f,1);
// f N,
// , 2
// (sizeof(word)=2)
// N.
BlockWrite(f,N,sizeof(word));
BlockWrite(f,N,sizeof(word));
//
// BlockRead.
BlockWrite(f,x^,N*sizeof(real));
// .
CloseFile(f);
// .
freemem(x,N*sizeof(word));
//
AssignFile(f,s);
Reset(f,1);
// f (word) N ,
// , 2 (sizeof(word)=2)
// N.
BlockRead(f,N,sizeof(word));
// N x

.., .., .. Free Pascal Lazarus

383

// .
getmem(x,N*sizeof(real));
// f N
// x.
//N*sizeof(real) 1 .
// X ,
// .
BlockRead(f,x^,N*sizeof(real));
//
// Edit2.
Label2.Visible:=true;
Edit2.Visible:=true;
// x
// Edit2.
for i:=1 to N do
Edit2.Text:=Edit2.Text+
FloatToStrF(x^[i],ffFixed,5,2)+' ';
// .
CloseFile(f);
freemem(x,N*sizeof(real));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//
// Edit1,
// Edit2, label1, label2 Button1.
// ,
// , .
Form1.Caption:=' ';
Label1.Width:=80;
Label1.Caption:=' ';
Edit1.Clear;
Label2.Caption:=
' ';
Label2.Width:=80;
Edit2.Clear;

.., .., .. Free Pascal Lazarus

384

Button1.Width:=150;
Button1.Caption:=' ';
Label1.Visible:=false;
Edit1.Visible:=false;
Label2.Visible:=false;
Edit2.Visible:=false;
end;
initialization
{$I unit1.lrs}
end.
, . 7.11. (. . 7.12).
. 7.13.

7.11: 7.6

.., .., .. Free Pascal Lazarus

385

7.12:

7.13:
7.7.
A(N,M), B(P,L) . , , A
B, C= AB .

.., .., .. Free Pascal Lazarus

386

. .
word N M, A(N,M), P L word B(P,L).

.
program Project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
var
f:file;
i,j,n,m,l,p:word;
a,b:array[1..20,1..20] of real;
begin
Assign(f,'Prim.dat');
// ,
// 1 .
rewrite(f,1);
write('N='); readln(N);
write('M='); readln(M);
// f N,
// , 2
//(sizeof(word)=2)
// N.
BlockWrite(f,N,sizeof(word));
// f M,
// , 2 (sizeof(word)=2)
// M.
BlockWrite(f,M,sizeof(word));
writeln('Matrica A');
for i:=1 to N do
for j:=1 to M do
begin
// .
read(A[i,j]);
// f

.., .., .. Free Pascal Lazarus

387

// A[i,j], , sizeof(real)
// A[i,j].
BlockWrite(f,A[i,j],sizeof(real));
end;
write('L='); readln(L);
write('P='); readln(P);
// 2
// L.
BlockWrite(f,L,sizeof(word));
// 2
// P.
BlockWrite(f,P,sizeof(word));
writeln('Matrica B');
for i:=1 to L do
for j:=1 to P do
begin
read(B[i,j]);
// sizeof(real)
// B[i,j].
BlockWrite(f,B[i,j],sizeof(real));
end;
// .
close(f);
end.
, A, B, ,
B .
program Project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
var
f:file;
k,i,j,n,m,l,p:word;
a,b,c:array[1..20,1..20] of real;
begin
//

.., .., .. Free Pascal Lazarus

388

// .
Assign(f,'Pr_7_6.dat');
//
// 1 .
reset(f,1);
// N f 2
// (sizeof(word)=2
// ).
BlockRead(f,N,sizeof(word));
// M f 2
//( sizeof(word)=2 ).
BlockRead(f,M,sizeof(word));
for i:=1 to N do
for j:=1 to M do
// A[i,j]
// f sizeof(real)
//( sizeof(real) ).
BlockRead(f,A[i,j],sizeof(real));
// L f 2 .
BlockRead(f,L,sizeof(word));
// P f 2 .
BlockRead(f,P,sizeof(word));
for i:=1 to L do
for j:=1 to P do
// B[i,j]
// f sizeof(real) .
BlockRead(f,B[i,j],sizeof(real));
// A .
writeln('Matrica A');
for i:=1 to N do
begin
for j:=1 to M do
write(A[i,j]:1:2,' ');
writeln
end;
// B .
writeln('Matrica B');
for i:=1 to L do

.., .., .. Free Pascal Lazarus

389

begin
for j:=1 to P do
write(B[i,j]:1:2,' ');
writeln
end;
//, ,
// ,
if M=L then
begin
// B
for i:=1 to N do
for j:=1 to P do
begin
c[i,j]:=0;
for k:=1 to M do
c[i,j]:=c[i,j]+a[i,k]*b[k,j]
end;
// C.
writeln('Matrica C=A*B');
for i:=1 to N do
begin
for j:=1 to P do
write(C[i,j]:1:2,' ');
writeln
end;
// f N, ,
//2 N.
BlockWrite(f,N,sizeof(word));
// f P, ,
//2 P.
BlockWrite(f,P,sizeof(word));
for i:=1 to N do
for j:=1 to P do
// f
//C[i,j], , sizeof(real)
// C[i,j].
BlockWrite(f,[i,j],sizeof(real));
end

.., .., .. Free Pascal Lazarus

390

else
writeln(' ');
// .
close(f);
end.
7.4 Free
Pascal
:
1. reset, rewrite, close, rename,
erase eof
() .
2. seek, trunate filepos .
3. append(f), f , .
,

.
4. write, writeln, read, readln
:
read(f, x1, x2, x3, ..., xn);
read(f, x);
readln(f, x1, x2, x3, ..., xn);
readln(f, x);
write(f, x1, x2, x3, ..., xn);
write(f, x);
writeln(f, x1, x2, x3, ..., xn);
writeln(f, x);
f . (read, readln) x, x1, x2, x3, , xn ,
. write, writeln
x, x1, x2, x3, , xn ,
.
write, writeln,

.., .., .. Free Pascal Lazarus

391

read, readln .
, , .
write
string.
writeln ,
.

read, readln . , , , IOResult. FreePascal
: -
.
.
, -
:
{$I+} - ;
{$I-} - .
, , {$I+}.
,
. .
-
, , .
, - ,
. -
.
IOResult, ,
: . IOResult
, -.
IOResult=0, - ,
IOResult . . 7.9.

.., .., .. Free Pascal Lazarus

392

7.9:

2

3

4

5

12

15

16

100

101

102
Assign
103

104

105

106

150


-:
1. , .
assign (f, 'abc.dat');
{$I-}
reset(f);
{$I+}
if IOResult<>0 then
writeln (' ')
else
begin
read(f,...);

close(f);
end;

.., .., .. Free Pascal Lazarus

393

2. , .
var i:integer;
begin
{$I-}
repeat
write(' i');
readln(i);
until (IOResult=0);
{$I+}
{ ,
}
end.
:

, , , , ;


. ,
.
, .
;

readln ,
,
.

.
7.8. abc.txt
A(N,M) B(N,M) . C=A+B,
abc.txt.
abc.txt :
( N
M), A B.
. 7.14 abc.txt,
A(4,5) B(4,5).

.., .., .. Free Pascal Lazarus

394

7.8 .

7.14: abc.txt
program project1;
{$mode objfpc}{$H+}
uses
Classes, SysUtils
{ you can add units after this };
var
f:Text;
i,j,N,M:word;
a,b,c:array[1..1000,1..1000] of real;
begin
// f
// .
AssignFile(f,'abc.txt');
// .
Reset(f);
// abc.txt

.., .., .. Free Pascal Lazarus

395

// N M.
Read(f,N,M);
//
// .
for i:=1 to N do
for j:=1 to M do
read(f,a[i,j]);
//
// B .
for i:=1 to N do
for j:=1 to M do
read(f,b[i,j]);
// C=A+B.
for i:=1 to N do
for j:=1 to M do
c[i,j]:=a[i,j]+b[i][j];
// f.
CloseFile(f);
// .
Append(f);
// C .
for i:=1 to N do
begin
for j:=1 to M do
//
// .
write(f,c[i,j]:1:2,' ');
// ,
// .
writeln(f);
end;
// .
CloseFile(f);
end.
abc.txt ,
. 7.15.

.., .., .. Free Pascal Lazarus

396

7.15: abc.txt C
7.5
. .
, .
1. , n .
.
.
2. , n .
.
.
3. , n .
,
, .
.
4. , n
. ,
, 10 .
.

.., .., .. Free Pascal Lazarus

397

5. , n .
, .
6. , n .
,
, .
7. , n
. ,
, .
8. , n .
, , .
9. , n .
. , .
10. , n .
, , . .
11. , n .
.
12. , n .
, .
13. , n .
, .
14. , n .

.
15. , n .

, .

.., .., .. Free Pascal Lazarus

398

16. , n .

.
17. , n .
.
18. , n .

.
.
19. , n .
,
.
20. , n .
,
5 7 ,
.
21. , n
. ,
, .
22. , n
.
.
23. , n
. .
24. , n .
, .
25. , n .
, ,
.

.., .., .. Free Pascal Lazarus

399

8
. . (record). ,
, . .
8. 1

. Free Pascal
. 2
.
.
- , - .
256 , ..
0 255.
255, , 1 .
char (1 ).
. . , . 1 , N
N .
string.

, :
s:='Q'; s1:='Privet';
, .
(
):
var str: string[20];
.
.
Free Pascal +. :

.., .., .. Free Pascal Lazarus

400

var s: string;
begin
s:='my ' + ' ' + 'text';
...
my text.
- .

. :
var s: string; c: char;
begin
s:='Privet';
c:=s[4];
...
v.
,
. 2.7. .
. . 2.7 :
var Str1, Str2, Str3 , Str4, Str5: String;
K, L : Integer;
begin
Str1:='';
// .
Str2:='';
// .
Writeln(' -', Str1);
Writeln(' -', Str2);
//--------------------------------// :
//
//
//--------------------------------// 1- 2- .
Str3:=Str1+' '+Str2; // .
Writeln(' -', Str3);
//--------------------------------// :
//
//---------------------------------

.., .., .. Free Pascal Lazarus

401

// .
L:= Length(Str3);
Writeln(' -',L,' ');
//--------------------------------// :
// 13
//--------------------------------Str4:=''; // .
// .
K:=Pos(Str4, Str3);
Writeln(' -',K);
//--------------------------------// :
// - 2
//--------------------------------// Str4 6
//, 8-, Str3.
Str4:=copy(Str3,8,6);
Writeln(' -',Str4);
//--------------------------------// :
// -
//--------------------------------// .
// -
// .
Str5:=Copy(Str3,1,Pos(' ',Str3)-1);
Writeln(' 3- - ',Str5);
//--------------------------------// :
// -
//--------------------------------//
// , 5- .
delete(Str3,5,2);
Writeln('3- -',Str3);
//--------------------------------// :

.., .., .. Free Pascal Lazarus

402

//
//--------------------------------end.
8.1. .
. . 5.5 .
, , Edit ,
. ,
. . (),
. .
, .
. ,
.

.
, . (. 8.1)
Edit1 , ListBox1 Button1 .
, Text Edit1 :
Text =1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0

8.1:

.., .., .. Free Pascal Lazarus

403

.
. 8.2.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
ListBox1: TListBox;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var Str1, Str2, Str3: String;
i: integer;
word: String;
x: array [0..100] of real;
Sum: real;
begin
// Edit1 .
Str1:=Edit1.text;
// ListBox1.
ListBox1.Items.Add(Str1);

.., .., .. Free Pascal Lazarus

404

// ,
if Str1[1] = ' ' then Delete(Str1,1,1);
// ,
// .
while Pos(' ',Str1) > 0 do
Delete(Str1,Pos(' ',Str1),1);
// .
if Str1[Length(Str1)] <> ' ' then
Str1:=Str1+' ';
i:=0; Sum:=0;
//
// .
repeat
// .
Word:=Copy(Str1,1,Pos(' ',Str1)-1);
// ,
// i-
x[i]:=StrToFloat(Word);
// .
sum:=sum+x[i];
inc(i);
//
// .
Delete(Str1,1,Length(Word)+1);
// ListBox1 .
ListBox1.Items.Add(Word);
// ,
// 0.
until Length(Str1) = 0;
//
//
// ListBox1.
Str2:='Summa ='+FloatToStr(sum);
//
//
//
// ListBox1.
Str3:='Kolichestvo elementov ='+IntToStr(i);

.., .., .. Free Pascal Lazarus

405

// .
ListBox1.Items.Add(str2);
// .
ListBox1.Items.Add(str3);
end;
initialization
{$I unit1.lrs}
end.

8.2: 8.1.
8.2

. Free Pascal
. , .
:
type
_ = record
1: ;
2 : ;
...
N : ;

.., .., .. Free Pascal Lazarus

406

end;

:
var _ : _;
,
. ,
, .
8.2. a, b . S.
. 2.1
.
. Triangle () a, b c
( ) .
program Project1;
type
// ,
// -
Triangle= record
a, b, c: real;
end;
// Triangle.
var x: Triangle;
p, s:real;
begin
write('a=');
readln(x.a);
// .
write('b=');
readln(x.b);
// b.
write('c=');
readln(x.c);
// c.
//
p:=(x.a+x.b+x.c)/2;
// //
// .
if p*(p-x.a)*(p-x.b)*(p-x.c)>0 then

.., .., .. Free Pascal Lazarus

407

begin
// .
s:=sqrt(p*(p-x.a)*(p-x.b)*(p-x.c));
writeln(' S=', s:7:2);
end
else
writeln('
.');

end.
, .
.
, Student, : , , , .
, : , , , .
type
adress = record
// .
//:
city,
//,
street: string;
//,
house,
//,
apartment: integer;
//.
end;
student = record
// .
//:
surname,
//,
name: string;
//,
group: string;
//,
//,
estimation: array [1..5] of integer;
residence: adress;
//.
end;
:
var Ivanov: student;
x: array [1..100] of student;
begin

.., .., .. Free Pascal Lazarus

408

Ivanov.group:='08';
Ivanov.residense.city:='';
// 5- =3
x[1].estimation[5]:=3;
...
C With
:
with <> do <>
:
with stud do
begin
with residence do
begin
city:='';
street :='';
house:=145;
apartment:=31;
end;
surname:='';
name:='';
birthday :='01.11.1990';
group :='07';
estimation[1]:=3; estimation[2]:=5;
estimation[3]:=4;
estimation[4]:=3; estimation[5]:=5;
end;
8.3. .
, ,
.
. (. 8.3) TEdit ,
StringGrid (ColCount=8, RowCount=1)
Tbutton:

Button1 ;

.., .., .. Free Pascal Lazarus

409

Button2 ;
Button3 StringGrid1
.
.

8.3: 8.3
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;

.., .., .. Free Pascal Lazarus

410

Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
adress = record
city, street : string;
//, ,
house, apartment: integer;//, .
end;
// .
student = record
surname , name : string; //, ,
group : string;
//,
//,
estimation: array [1..5] of integer;
residence : adress;
//,
s_ball: real;
// .
end;
var

.., .., .. Free Pascal Lazarus

411

Form1: TForm1;
// student.
x: array [0..100] of student;
//
// .
i: integer;
implementation
{ TForm1 }
// .
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;// 0.
end;
// .
procedure TForm1.Button1Click(Sender: TObject);
var sum, j:integer;
begin
// .
x[i].surname:= Edit1.Text;
x[i].name:= Edit2.Text;
x[i].group:= Edit3.Text;
x[i].residence.city:=Edit5.Text ;
x[i].residence.street:= Edit6.Text;
x[i].residence.house:=
StrToInt(Edit7.Text);
x[i].residence.apartment:=
StrToInt(Edit8.Text);
x[i].estimation[1]:=strToInt(Edit4.Text);
x[i].estimation[2]:=strToInt(Edit9.Text);
x[i].estimation[3]:=strToInt(Edit10.Text);
x[i].estimation[4]:=strToInt(Edit11.Text);
x[i].estimation[5]:=
strToInt(Edit12.Text) ;
// .
sum:=0;
for j:=1 to 5
do
sum:=sum+x[i].estimation[j];
x[i].s_ball:=sum/5; inc(i);

.., .., .. Free Pascal Lazarus

412

// .
Edit1.Text:= ''; Edit2.Text:= '';
Edit3.Text:= ''; Edit4.Text:= '';
Edit5.Text:= ''; Edit6.Text:= '';
Edit7.Text:= ''; Edit8.Text:= '';
dit9.Text:= ''; Edit10.Text:= '';
Edit11.Text:= ''; Edit12.Text:= '';
end;
// .
procedure TForm1.Button2Click(Sender: TObject);
var f:textfile; j: integer; s: string;
begin
// StringGrid
// , ,
// .
StringGrid1.RowCount:= i+1;
// .
StringGrid1.Cells[1,0]:='' ;
StringGrid1.Cells[2,0]:='' ;
StringGrid1.Cells[3,0]:='' ;
StringGrid1.Cells[4,0]:='' ;
StringGrid1.Cells[5,0]:='' ;
StringGrid1.Cells[6,0]:='/.' ;
StringGrid1.Cells[7,0]:=' ' ;
// j- .
for j:=1 to i do
begin
StringGrid1.Cells[1,j]:=
x[j-1].surname ;
StringGrid1.Cells[2,j]:=x[j-1].name;
StringGrid1.Cells[3,j]:=x[j-1].group;
StringGrid1.Cells[4,j]:=
x[j-1].residence.city;
StringGrid1.Cells[5,j]:=
x[j-1].residence.street;
s:=inttostr(x[j-1].residence.house)+
'/'+inttostr(x[j-1].residence.apartment);
StringGrid1.Cells[6,j]:=s ;

.., .., .. Free Pascal Lazarus

StringGrid1.Cells[7,j]:=
floattostr(x[j-1].s_ball);

413

end
// .
assignfile(f,'g:\student.txt');
rewrite(f);
for j:=1 to i do
begin
writeln(f,x[j-1].surname:20,
x[j-1].name:15,
x[j-1].residence.city:15,',',
x[j-1].residence.street:15,
x[j-1].residence.house:4,'/',
x[j-1].residence.apartment,
' Sr_ball=',x[j-1].s_ball:4:1);
end;
closefile(f);
end;
//
// .
procedure TForm1.Button3Click(Sender: TObject);
var j, k :integer;
temp: student; // .
f:textfile;
Begin
// surname .
for j:= 0 to i-1 do
for k:=j+1 to i-1 do
if x[j].surname > x[k].surname then
begin
// .
temp:=x[j]; x[j]:=x[k];x[k]:=temp;
end;
end;
initialization
{$I unit1.lrs}
end.
. 8.5 8.7.

.., .., .. Free Pascal Lazarus

8.5:

8.6:

414

.., .., .. Free Pascal Lazarus

415


, 8.5. ,
,
.
(.8.6).

,
(.8.7).

8.7:
8.3

. :
1. .
2. .
.
3. .
4. .
5. .
6. , .
7. *.

.., .., .. Free Pascal Lazarus

416

8. .
9. +.
10. , .
11. , .
12. .
.
13. .
14. ;.
15. : ;.
16. .
17. , .
18. .
19. ,
, .
20. , .
21. ,
.
22. , .
23. .
24. .
25. , .
8.4

1. 8.1:
8.1.

, . .
1999
2000
2001
2002

2,5

1,3

-0,2

-0,1

2003
0,6

...

.
2003
. .
2. 8.1. . -

.., .., .. Free Pascal Lazarus

417

2003 2 . . . .
3. 8.2:
8.2.

125,00

01.02.2007

...

,
. . .
4. 8.2. . , . .
5. 8.5:
8.5.

05.05.1994

112

9-

...

, .
. .
6. 8.5. ,
. 9- . . .
7. 8.6:
8.6.

, .
, $

Samsung CLP-310

25

20

26

550

...

.
. .

.., .., .. Free Pascal Lazarus

418

8. 8.6. . .
.
9. 8.6. . .
.
10. 8.6. ,
. 500$. .
11. 8.7:
8.7.

. .

12.03.1966

1250

...

,
: 20% , 10 ,
10%. 10 . .
12. 8.8. , .
. .
13. 8.8. , .
( 25 ). .
14. 8.8:
8.8.

, .
, $

255

203

198

510

...

.
. -

.., .., .. Free Pascal Lazarus

419

.
15. 8.8. .
. .
16. 8.9:
8.9.

. . 12.03.1966

.
1250
...
,
: 15%
. .
17. 8.9. , .
.
.
18. 8.10:
8.10.

. .

1971

25

...

: 10,
, .
.
19. 8.10. , . . .
20. 8.11:
8.11.

. .


1971

, $
6,5

15000

...

.
2005 . .

420

.., .., .. Free Pascal Lazarus

21. 8.11. 2000 .


. .
22. 8.12:
8.12.

. .

1 -

956-25-78 12.05.2003

3,65

...

.
, . .
23. 8.12. , 3.
.
24. 8.14:
8.14.

, .

12-08

12.06.2006

200

24

...

: 1 , 3 , . .
.
25. 8.14. 6 .
.

.., .., .. Free Pascal Lazarus

421

9 - -

- (). ,
, ,
.
9.1
-
. :
1. (, );
2. (, , , , . .);
3. , , ,
.
FreePascal .
, ,
, .
, () (). , " ". () , , . .
- ()
.
- :
, . .

. ()
, , . -

.., .., .. Free Pascal Lazarus

422

,
.
:
type
< > = class(< >)
< >
private
< ,
>
protected
< ,
->
public
< , >
published
< , >
end;

FreePascal . , , , , , TObject.
, . , ( public), ( private), . .
, public
.
, , . . ().
, , private,
, , . . .
(published) , , -

.., .., .. Free Pascal Lazarus

423


.
(protected) , , , -, .

, , . : " , ".
.
, . , :
1: _;
2: _;
...
, :
function 1 ( ): ;
procedure 2 ( );
, , implementation , ,
:
function _.1( ):
;
begin
;
end;
procedure _.2( );
begin
;
end;
class () ( ). :
var _ : _;

.., .., .. Free Pascal Lazarus

424


,
.. :
_.1:=;
_.1( );
...
With:
With _ do
begin
1:=;
1( );
...
end;
FreePascal , (,
, ..). . ,
,
.
,
Button1.
unit Unit1;
interface
uses
Classes, SysUtils, LResources, Forms, Controls,
Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
// TForm1
TForm1 = class(TForm)
// Button1
Button1: TButton;
//
// Button1
procedure Button1Click(Sender: TObject);
private
{ private declarations }

.., .., .. Free Pascal Lazarus

425

public
{ public declarations }
end;
var
// TForm1
Form1: TForm1;
implementation
{ TForm1 }
//
Button1
procedure TForm1.Button1Click(Sender: TObject);
begin
//
end;
initialization
{$I unit1.lrs}
end.
Free Pascal () . , .

.
, . :
constructor Create;
, , implemention , .
constructor _.Create;
begin
1:=1;
2:=2;
...
inherited Create;
end;

,
0, .
,
.

.., .., .. Free Pascal Lazarus

426

:
destructor Destroy;
- ,

___.free;
free ,
___.

78. Tcomplex, : x
, y
. :
Create, 0;
Modul() ;
Argument()
;
ComplexToStr()
- ,
.
, Button1,
Edit1 Edit2 ,
Memo1.
, . Memo1
: ,
. , .
. 9.1.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
78
http://kvant.mccme.ru./1982/03/komplesnye_chisla.htm

.., .., .. Free Pascal Lazarus

TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type
// .
TComplex = class
private
x: real;
// .
y: real;
//
public
constructor Create;
//.
// .
function Modul():real;
// .
function Argument():real;
//
// .
function ComplexToStr(): String;
end;
var
Form1: TForm1;
//
// .
chislo: TComplex;
implementation
//
constructor TComplex.Create;

427

.., .., .. Free Pascal Lazarus

428

begin
x:=0; y:=0;
inherited Create;
end;
//
// .
function TComplex.Modul(): real;
begin
modul:=sqrt(x*x+y*y);
end;
//
// .
function TComplex.Argument(): real;
begin
argument:=arctan(y/x)*180/pi;
end;
//
// .
function TComplex.ComplexToStr(): String;
begin
if y>=0 then
ComplexToStr:=FloatToStrF(x,ffFixed,5,2)+
'+' + FloatTostrF(y,ffFixed,5,2)+ 'i'
else
ComplexToStr:=FloatTostrF(x,ffFixed,5,2)+
FloatTostrF(y,ffFixed,5,2)+ 'i'
end;
// :
// ,
//,
//, .
procedure TForm1.Button1Click(Sender: TObject);
Var Str1: String;
begin
// ( )
// .
chislo:=TComplex.Create;
//

.., .., .. Free Pascal Lazarus

429

// .
chislo.x:=StrToFloat(Edit1.Text);
chislo.y:=StrToFloat(Edit2.Text);
Str1:='Kompleksnoe chislo '+
chislo.ComplexToStr();
// Memo
// ,
Memo1.Lines.Add(Str1) ;
//
Str1:='Modul chisla '+
FloatToStrF(chislo.Modul(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
// .
Str1:='Argument chisla '+
FloatToStrF(chislo.Argument(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
// .
chislo.Free;
end;
initialization
{$I unit1.lrs}
end.

9.1:

. Free Pascal , .

.., .., .. Free Pascal Lazarus

430

.
.
.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type
TComplex = class
private x, y: real;
public
// .
constructor Create(a,b:real);
function Modul():real;
function Argument():real;
function ComplexToStr(): String;
end;
var

.., .., .. Free Pascal Lazarus

431

Form1: TForm1;
chislo: TComplex;
implementation
//,
//
//
//
// .
constructor TComplex.Create(a,b:real);
begin
x:=a; y:=b;
inherited Create;
end;
function TComplex.Modul(): real;
begin
modul:=sqrt(x*x+y*y);
end;
function TComplex.Argument(): real;
begin
argument:=arctan(y/x)*180/pi;
end;
function TComplex.ComplexToStr(): String;
begin
if y>=0 then
ComplexToStr:=FloatToStrF(x,ffFixed,5,2)+
'+' + FloatTostrF(y,ffFixed,5,2)+ 'i'
else
ComplexToStr:=FloatTostrF(x,ffFixed,5,2)+
FloatTostrF(y,ffFixed,5,2)+ 'i'
end;
procedure TForm1.Button1Click(Sender: TObject);
Var Str1 : String;
x1, x2 : real;
begin
x1:=StrToFloat(Edit1.Text);
x2:=StrToFloat(Edit2.Text);
chislo:=TComplex.Create(x1,x2);
chislo.x:=StrToFloat(Edit1.Text);

.., .., .. Free Pascal Lazarus

432

chislo.y:=StrToFloat(Edit2.Text);
Str1:='Kompleksnoe chislo '+
chislo.ComplexToStr() ;
Memo1.Lines.Add(Str1) ;
Str1:='Modul chisla '+
FloatToStrF(chislo.Modul(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
Str1:='Argument chisla '+
FloatToStrF(chislo.Argument(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
chislo.Free;
end;
initialization
{$I unit1.lrs}
end.
9.2
- ( ).
, , . , . , TForm
() ,
.
.
private. :
. FreePascal .
- ,
. property, read write. , . :
propety _1: read _ write _2

.., .., .. Free Pascal Lazarus

433

read
, write .
_1 _2 ,
.
, ,
write read.
. , TPolygon. :
K ;
p , .
:
Create, p;
Perimetr() - ;
Show() - ( );
Set_Input() - .
. . , , ,

50. Label1.
,
. 9.2.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;

.., .., .. Free Pascal Lazarus

Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type
// Tpolygon.
TPolygon = class
// .
Private
K : integer;
p : array of real;
// .
Public
constructor Create;
//.
// .
function Perimetr():real;
// .
function Show():String;
Protected
// .
// .
procedure Set_Input(m:integer);
Published
// n.
// n K.
// read
// K. ,
//
// .
// Set_Input
// write ,
// K
// .
Property n: integer read K write Set_Input;
end;
var

434

.., .., .. Free Pascal Lazarus

435

Form1: TForm1;
//
// .
Figure: TPolygon;
implementation
// .
constructor TPolygon.Create;
var i:integer;
begin
K:=50;// .
// p.
SetLength(p,K);
for i:=0 to K-1 do p[i]:=0;
inherited Create;
end;
// .
function TPolygon.Perimetr():real;
var Sum:real; i:integer;
begin
Sum:=0;
for i:=0 to K-1 do Sum:=Sum+p[i];
Perimetr:=Sum;
end;
// .
function TPolygon.Show():String;
begin
Show:=' '+
IntToStr(K)+chr(13)+' = '+
FloatToStr(Perimetr())
end;
// K.
procedure TPolygon.Set_Input(m:integer);
begin
// ,
// K,
// .
if m>1 then K:=m else K:=50;
end;

.., .., .. Free Pascal Lazarus

436

{TForm1 }
// .
procedure TForm1.Button1Click(Sender: TObject);
var i, m:integer;
s:string;
begin
// .
s:=InputBox('','
','6');
Val(s,m);
// .
Figure:=TPolygon.Create;
with Figure do
begin
// .
Set_Input(m);
// .
for i:=0 to K-1 do p[i]:=random(50);
// .
s:=Show();
end;
// .
Label1.Caption:= s;
end;
initialization
{$I unit1.lrs}
end.

9.2:

.., .., .. Free Pascal Lazarus

437

9.3
- . : ,
,
.
,
, , .
(). -
,
.
Object Pascal TObject.
TObject,
.
- ;
, , . ,
, :
;
;
.
.
- .
. ,
-. ,
.
. - . , ,
.
.
VMT. VMT .
VMT

.., .., .. Free Pascal Lazarus

438

.
,
. DMT . DMT ,
. DMT ,
DMT ..
- VMT , .
,
.
, . .
. - , . .
,
,
virtual dynamic:
type
_ =class
...
; virtual;
...
end;
- , override:
type
_=class (_)
...
; override;
...
end;
. Ttriangle ()

.., .., .. Free Pascal Lazarus

439

. :
Proverka()
( 3 , );
Perimetr() ;
Square() - ;
a(), b(), c();
Set_Tr() ;
Show() .

R_TTriangle ( ),
, .
, 6
TEdit .
, , Label1
Label2. .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: Tbutton; //
// x1, y1
//1- )
// x1, y1
//2- ()
Edit1: Tedit; // x1[1]
Edit10: TEdit; // y2[2]
Edit11: TEdit; // x2[3]

.., .., .. Free Pascal Lazarus

Edit12: TEdit; // y2[3]


Edit2: TEdit; // y1[1]
Edit3: TEdit; // x2[2]
Edit4: TEdit; // y1[2]
Edit5: TEdit; // x1[3]
Edit6: TEdit; // y1[3]
Edit7: TEdit; // x2[1]
Edit8: TEdit; // y2[1]
Edit9: TEdit; // x2[2]
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
type
TTriangle=class
Private
//,
// .
x, y:array[0..2] of real;

440

.., .., .. Free Pascal Lazarus

Public
constructor Create; //
// .
procedure Set_Tr(a,b:array of real);
// .
function a():real;
function b():real;
function c():real;
//
//,
// .
function Proverka():boolean;
virtual;
// .
function Perimetr():real;
// .
function Square():real;
//
// .
function Show():string;
virtual;
end;
//
// .
type
R_TTriangle=class(TTriangle)
public
// ,
// ,
// .
function Proverka():boolean; override;
function Show():string;
override;
end;
var
Form1: TForm1;
//
// .
Figura1: Ttriangle;
//
// .

441

.., .., .. Free Pascal Lazarus

442

Figura2: R_TTriangle;
implementation
//,
// .
constructor TTriangle.Create;
var i:integer;
begin
for i:=0 to 2 do
begin
x[i]:=0; y[i]:=0;
end;
end;
// .
procedure TTriangle.Set_Tr(a,b:array of real);
var i:integer;
begin
for i:=0 to 2 do
begin
x[i]:=a[i]; y[i]:=b[i];
end;
end;
// a, b, c
function TTriangle.a():real;
begin
a:=sqrt(sqr(x[1]-x[0])+sqr(y[1]-y[0]));
end;
function TTriangle.b():real;
begin
b:=sqrt(sqr(x[2]-x[1])+sqr(y[2]-y[1]));
end;
function TTriangle.c():real;
begin
c:=sqrt(sqr(x[0]-x[2])+sqr(y[0]-y[2]));
end;
// .
function TTriangle.Perimetr():real;
begin
Perimetr:=a()+b()+c();

.., .., .. Free Pascal Lazarus

443

end;
// .
function TTriangle.Square():real;
var p:real;
begin
p:=Perimetr()/2; //
Squire:=sqrt((p-a())*(p-b())*(p-c()));
end;
// :
// ,
// , 3-
// , ,
//
// .
function TTriangle.Proverka():boolean;
begin
if (x[0]-x[1])/(x[0]-x[2])=
(y[0]-y[1])/(y[0]-y[2]) then
Proverka:=false
else Proverka:=true
end;
//
// .
function TTriangle.Show():string;
begin
// ,
// .
if Proverka() then
Show:='Tr'+chr(13)+'a='+
FloatToStrF(a(),ffFixed,5,2)+
chr(13)+'b='+FloatToStrF(b(),ffFixed,5,2)+
chr(13)+'c='+FloatToStrF(c(),ffFixed,5,2)+
chr(13)+'P='+FloatToStrF(Perimetr(),ffFixed,5,2)+
chr(13)+'S='+FloatToStrF(Square(),ffFixed,5,2)
else
Show:='Not Triangle';
end;

.., .., .. Free Pascal Lazarus

444

//
// .
function R_TTriangle.Proverka():boolean;
begin
if (a()=b()) and(b()=c()) then
Proverka:=true
else
Proverka:=false
end;
//
// .
function R_TTriangle.Show():string;
begin
// ,
// .
if Proverka()=true then
Show:='Tr'+chr(13)+'a='+
FloatToStrF(a(),ffFixed,5,2)+
chr(13)+'P='+
FloatToStrF(Perimetr(),ffFixed,5,2)+chr(13)
+'S='+FloatToStrF(Square(),ffFixed,5,2)
else
Show:='Not R_Triangle';
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: Tobject);
// x1, y1 .
// x2, y2
//
var x1, y1, x2, y2 :array[1..3] of real;
s:string;
begin
//
// .
x1[1]:=StrToFloat(Edit1.Text);
y1[1]:=StrToFloat(Edit2.Text);
x1[2]:=StrToFloat(Edit3.Text);
y1[2]:=StrToFloat(Edit4.Text);

.., .., .. Free Pascal Lazarus

445

x1[3]:=StrToFloat(Edit5.Text);
y1[3]:=StrToFloat(Edit6.Text);
x2[1]:=StrToFloat(Edit7.Text);
y2[1]:=StrToFloat(Edit8.Text);
x2[2]:=StrToFloat(Edit9.Text);
y2[2]:=StrToFloat(Edit10.Text);
x2[3]:=StrToFloat(Edit11.Text);
y2[3]:=StrToFloat(Edit12.Text);
// .
Figura1:=TTriangle.Create;
//
// .
Figura2:=R_TTriangle.Create;
Figura1.Set_Tr(x1,y1);
Figura2.Set_Tr(x2,y2);
//
// .
s:=Figura1.Show();
Label15.Caption:= S;
s:=Figura2.Show();
Label16.Caption:= S;
//
Figura1.Free;
Figura2.Free;
end;
initialization
{$I unit1.lrs}
end.
. 9.3.
,
, .
, -. , .
abstract virtual dynamic, :
1;
virtual;
abstract;

.., .., .. Free Pascal Lazarus

446

9.3:
.
TFigure ().
(, ..). -
TCircle () TRectangle ().
. 2
,
: ( ), , Label1 label2. .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;

.., .., .. Free Pascal Lazarus

447

Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
type
TFigure=class
private
n:integer; // .
p:array of real; // .
public
//
//
//.
constructor Create;
virtual; abstract;
//
function Perimetr():real;
// ,
//
// .
function Square():real;virtual; abstract;
//
//
//
// .
function Show():string;virtual; abstract;
end;
// .
type
TCircle=class(TFigure)
public
constructor Create;
override;
function Perimetr():real;
function Square():real;
override;

.., .., .. Free Pascal Lazarus

function Show():string;
override;
end;
//
// .
type
TRectangle=class(TFigure)
public
constructor Create;
override;
function Square():real;
override;
function Show():string;
override;
end;
var
Form1: Tform1;
// .
Figura1: Tcircle;
// .
Figura2:TRectangle;
implementation
//
// .
function TFigure.Perimetr():real;
var
i:integer;
s:real;
begin
s:=0;
for i:=0 to n-1 do
s:=s+p[i];
Perimetr:=s;
end;
//
//
// .
constructor TCircle.Create;
begin
// 1.
n:=1;
// 1 .
SetLength(p,n);

448

.., .., .. Free Pascal Lazarus

449

p[0]:=5;
// - .
end;
// .
function TCircle.Perimetr():real;
begin
// .
Perimetr:=2*Pi*p[0];
end;
//
function TCircle.Square():real;
begin
Square:=Pi*sqr(p[0]);
end;
//
// .
//
// .
function TCircle.Show():string;
begin
Show:='Circle'+chr(13)+'r='+
FloatToStr(p[0])+chr(13)+'P='+
FloatToStr(Perimetr())+
chr(13)+'S='+FloatToStr(Square());
end;
// .
//
// .
constructor TRectangle.Create;
begin
n:=2; // .
// .
SetLength(p,n);
p[0]:=4; p[1]:=2; // .
End;
//
// ,
// .

.., .., .. Free Pascal Lazarus

450

function TRectangle.Square():real;
begin
Square:=p[0]*p[1];
end;
//
// .
//
// .
function TRectangle.Show():string;
begin
Show:='Rectangle'+chr(13)+'a='+
FloatToStr(p[0])+' b='+
FloatToStr(p[1])+
chr(13)+'P='+FloatToStr(Perimetr())+
chr(13)+'S='+FloatToStr(Square());
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
// .
Figura1:=TCircle.Create;
// .
Figura2:=TRectangle.Create;
//
// .
s:=Figura1.Show() ;
label1.Caption:= s ;
s:=Figura2.Show() ;
label2.Caption:= s ;
Figura1.Free;
Figura2.Free;
end;
initialization
{$I unit1.lrs}
end.

.., .., .. Free Pascal Lazarus

451

9.4
Free Pascal , , , , * ,
.

.
:
operator symbols(:)_:;
operator ;
symbols ;
, ;
, ,
implemention ,
.
.
9.1. , .
TEdit
. TMemo .
. .
,
.
, . 9.4 .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: Tbutton;

.., .., .. Free Pascal Lazarus

452

// .
Edit1: Tedit;
// .
Edit2: TEdit;
// .
Edit3: TEdit;
// .
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Memo1: Tmemo; // .
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
type
TComplex = class
private
x: real;
// .
y: real;
// .
public
constructor Create;
//.
// .
function Modul():real;
//
// ;
function Argument():real;
//,
// .
function ComplexToStr(): String;
end;

.., .., .. Free Pascal Lazarus

453

// +
// .
operator +(const a, b: TComplex)r: TComplex;
// -
// .
operator -(const a, b: TComplex)r: TComplex;
var
Form1: TForm1;
// .
chislo1: Tcomplex;
chislo2: TComplex;
chislo3: TComplex;
chislo4: TComplex;
implementation
// .
constructor TComplex.Create;
begin
x:=0; y:=0;
inherited Create;
end;
function TComplex.Modul(): real;
begin
modul:=sqrt(x*x+y*y);
end;
function TComplex.Argument(): real;
begin
argument:=arctan(y/x)*180/pi;
end;
// +.
// a b ,
// ,
//r
operator +(const a, b: TComplex)r: TComplex;
begin
r:=TComplex.Create; // .
//
//
//

.., .., .. Free Pascal Lazarus

454

//.
//
// .
// -
//, .
r.x:=a.x+b.x;
r.y:=a.y+b.y;
end;
// -.
operator -(const a, b: TComplex)r: TComplex;
begin
r:=TComplex.Create; // .
//
//
// .
//
//
//. -
// , .
r.x:=a.x-b.x;
r.y:=a.y-b.y;
end;
function TComplex.ComplexToStr(): String;
begin
if y>=0 then
ComplexToStr:=FloatToStrF(x,ffFixed,5,2)+'+'+
FloatTostrF(y,ffFixed,5,2)+ 'i'
else
ComplexToStr:=FloatTostrF(x,ffFixed,5,2)+
FloatTostrF(y,ffFixed,5,2)+ 'i'
end;
procedure TForm1.Button1Click(Sender: TObject);
Var Str1 : String;
begin
// .
//chislo1, chislo2
//, .
//chislo3 ,

.., .., .. Free Pascal Lazarus

455

// .
//chislo4 ,
// .
chislo1:=TComplex.Create;
chislo2:=TComplex.Create;
chislo3:=TComplex.Create;
chislo4:=TComplex.Create;
//
//
// .
chislo1.x:=StrToFloat(Edit1.Text);
chislo1.y:=StrToFloat(Edit2.Text);
chislo2.x:=StrToFloat(Edit3.Text);
chislo3.y:=StrToFloat(Edit4.Text);
//
// +,
// .
chislo3:=chislo1+chislo2;
//
// -,
// .
chislo4:=chislo1-chislo2;
//
// Memo1.
Str1:='chislo1+chislo2 '+
chislo3.ComplexToStr() ;
Memo1.Lines.Add(Str1) ;
//
// Memo1.
Str1:='Modul chisla '+
FloatToStrF(chislo3.Modul(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1);
//
// Memo1.
Str1:='Argument chisla '+
FloatToStrF(chislo3.Argument(), ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
//

.., .., .. Free Pascal Lazarus

456

// Memo1.
Str1:='chislo1-chislo2 '+
chislo4.ComplexToStr() ;
Memo1.Lines.Add(Str1) ;
Str1:='Modul chisla '+
FloatToStrF(chislo4.Modul(),ffFixed, 5, 2);
Memo1.Lines.Add(Str1) ;
Str1:='Argument chisla '+
FloatToStrF(chislo4.Argument(), ffFixed,5,2);
Memo1.Lines.Add(Str1) ;
end;
initialization
{$I unit1.lrs}end.

9.4:
9.1
9.2. , . , .

.
,
.
8 TLabel
. 6
, . .

.., .., .. Free Pascal Lazarus

457

.
10,
5. , . .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
type
TMatrix = class
private
//
x: array [0..5,0..5]of real;
public
constructor Create;
//.
// ,
// .

.., .., .. Free Pascal Lazarus

458

function MatrixToStr(): String;


// ,
// .
function Pr_Edin(): boolean;
end;
// + // .
operator +(const a, b: TMatrix)r: Tmatrix;
// + // .
operator+(const a:TMatrix;b:real)r:TMatrix;
// * // .
operator *(const a, b: TMatrix)r: Tmatrix;
// * // .
operator *(const a:TMatrix;b:real)r: TMatrix;
var
Form1: TForm1;
matr1: TMatrix;
matr2: TMatrix;
matr3: TMatrix;
matr4: TMatrix;
matr5: TMatrix;
matr6: TMatrix;
implementation
// ,
// .
constructor TMatrix.Create;
var i, j : integer;
begin
for i:=0 to 4 do
for j:=0 to 4 do
x[i,j]:=Random(10);
inherited Create;
end;
//, ,
// .

.., .., .. Free Pascal Lazarus

function TMatrix.Pr_Edin():boolean;
var i, j : integer;
begin
//, .
Result:=true;
for i:=0 to 4 do
for j:=0 to 4 do
// 1
// 0,
if ((i=j)and(x[i,j]<>1))or((i<>j)and(x[i,j]<>0))
then
begin
// .
Result:=false;
break; //
end;
end;
// + //
operator +(const a, b: TMatrix)r: TMatrix;
var i, j: integer;
begin
r:=TMatrix.Create;
for i:=0 to 4 do
for j:=0 to 4 do
r.x[i,j]:=a.x[i,i]+b.x[i,j];
end;
// * // .
operator *(const a, b: TMatrix)r: TMatrix;
var i, j, k: integer;
s: real;
begin
r:=TMatrix.Create;
for i:=0 to 4 do
for j:=0 to 4 do
begin
r.x[i,j]:=0;

459

.., .., .. Free Pascal Lazarus

for k:=0 to 4 do
r.x[i,j]:=
r.x[i,j]+a.x[i,k]*b.x[k,j];
end;

460

end;
// + // .
operator +(const a: TMatrix;b:real)r: TMatrix;
var i, j: integer;
begin
r:=TMatrix.Create;
for i:=0 to 4 do
for j:=0 to 4 do
r.x[i,j]:=a.x[i,j]+b;
end;
// * //
operator *(const a: TMatrix;b:real)r: TMatrix;
var i, j: integer;
begin
r:=TMatrix.Create;
for i:=0 to 4 do
for j:=0 to 4 do
r.x[i,j]:=a.x[i,j]*b;
end;
//
// .
function TMatrix.MatrixToStr(): String;
var s:string;
i, j :integer;
begin
s:='';//
for i:=0 to 4 do
begin
for j:=0 to 4 do
// s ,
// .
s:=s+FloatTostrF(x[i,j],ffFixed,5,2)+' ';

.., .., .. Free Pascal Lazarus

461

// .
s:=s+chr(13);
end;
MatrixToStr:=s;
end;
// :
// ,
//
//, ,
//
procedure TForm1.Button1Click(Sender: TObject);
Var Str1 : String;
begin
// :
//matr1, matr2 ,
// ;
//matr3 ,
// ;
//matr4 ,
// ;
//matr5 ,
// 10;
//matr6 ,
// 5.
matr1:=TMatrix.Create;
matr2:=TMatrix.Create;
matr3:=TMatrix.Create;
matr4:=TMatrix.Create;
matr5:=TMatrix.Create;
matr6:=TMatrix.Create;
// matr3, matr4, matr5, matr6
// .
matr3:=matr1+matr2;
matr4:=matr1*matr2;
matr5:=matr1+10;
matr6:=matr1*5;
//
// Label1 matr1.

.., .., .. Free Pascal Lazarus

462

Str1:='Matrix1 '+chr(13)+matr1.MatrixToStr() ;
Label1.Caption:= Str1;
//, matr1
//, .
if matr1.Pr_Edin()=true then
Str1:='Matrix1 edinichnaya'
else
Str1:='Matrix1 ne edinichnaya';
Label5.Caption:= Str1 ;
//, matr2
//, .
if matr2.Pr_Edin()=true then
Str1:='Matrix2 edinichnaya'
else
Str1:='Matrix2 ne edinichnaya';
Label6.Caption:= Str1 ;
Str1:='Matrix2 '+chr(13)+matr2.MatrixToStr() ;
Label2.Caption:= Str1 ;
// matr3=matr1+matr2.
Str1:='Matrix1+Matrix2 '+
chr(13)+matr3.MatrixToStr() ;
Label3.Caption:= Str1 ;
// matr4=matr1*matr2.
Str1:='Matrix1*Matrix2 '+
chr(13)+matr4.MatrixToStr() ;
Label4.Caption:= Str1 ;
// matr5=matr1+10.
Str1:='Matrix1+10 '+
chr(13)+matr5.MatrixToStr() ;
Label7.Caption:= Str1 ;
// matr5=matr1*5.
Str1:='Matrix1*5 '+chr(13)+
matr6.MatrixToStr() ;
Label8.Caption:= Str1 ;
end;
initialization
{$I unit1.lrs}
end.

.., .., .. Free Pascal Lazarus

463

. 9.5 .

9.5: 9.2
9.3. ,
< >.
TEdit Memo1
. , , Memo1. , . 9.6 .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: Tbutton;

.., .., .. Free Pascal Lazarus

464

// .
Edit1: Tedit;
// .
Edit2: Tedit;
// .
Edit3: Tedit;
// .
Edit4: Tedit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Memo1: Tmemo; // .
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
// .
type
TOb_Drob = class
private
Ch: integer;
//.
Zn: integer;
//.
public
//.
constructor Create(a, b:integer);
// .
function DrobToStr(): String;
end;
// <.
operator <(const a, b: TOb_Drob)r: boolean;
// >.
operator >(const a, b: TOb_Drob)r: boolean;
var
Form1: Tform1;
//

.., .., .. Free Pascal Lazarus

// .
d1, d2: TOb_Drob;
implementation
//.
constructor TOb_drob.Create(a, b:integer);
begin
Ch:=a; Zn:=b;
inherited Create;
end;
// < // .
operator <(const a, b: TOb_Drob)r: boolean;
begin
if a.Ch*b.Zn <b.Ch * a.Zn then
r:=true
else r:=false ;
end;
// > // .
operator >(const a, b: TOb_Drob)r: boolean;
begin
if a.Ch*b.Zn > b.Ch * a.Zn then
r:=true
else r:=false ;
end;
//
// .
function TOb_Drob.DrobToStr(): String;
begin
if Zn<>0 then
if Ch*Zn>0 then
DrobToStr:=IntToStr(Ch)+'/'+
IntToStr(Zn)
else
DrobToStr:='-'+IntToStr(abs(Ch))+'/'+
IntTostr(abs(Zn))
else
DrobToStr:='Dividing by a zero'

465

.., .., .. Free Pascal Lazarus

466

end;
procedure TForm1.Button1Click(Sender: TObject);
Var Str1 : String;
a, b: integer;
begin
// :
a:=StrToInt(Edit1.Text); //,
b:=StrToInt(Edit2.Text); //.
// .
d1:=TOb_Drob.Create(a,b);
// .
a:=StrToInt(Edit3.Text);
b:=StrToInt(Edit4.Text);
// .
d2:=TOb_Drob.Create(a,b);
//
// Memo1.
// d1.
Str1:='Drob 1 '+d1.DrobToStr() ;
Memo1.Lines.Add(Str1) ;
// d2.
Str1:='Drob2 '+d2.DrobToStr() ;
Memo1.Lines.Add(Str1) ;
//
// < > .
if d1<d2
then
Str1:='Drob1 < Drob2'
else
if d1>d2
then
Str1:='Drob1 > Drob2'
else
Str1:='Drob1 = Drob2';
Memo1.Lines.Add(Str1) ;
end;
initialization
{$I unit1.lrs}
end.

.., .., .. Free Pascal Lazarus

467

9.6:
9.3
9.5
1. z=x+
y i , (x) (y) .
: ,
. : , , .
2. ,
. : . : , , , ,
( AA1=E ).
3. ,
. : , . : , .
4. ,
. : , . : , ,

.., .., .. Free Pascal Lazarus

468

.
5. , .
, , . , , .
6. ,
. : , .
: , , ,
.
7. ,
(x1, y1) (x2, y2). :
y= ax + b. :
, .
8.
a=cos i sin , () () .
: , . : , ,
.
9. ,
. : , . : , .
10. ,
. : ,
. : , , .
11. , . : ,
, .
: , , , .
12. , 3- .
-

.., .., .. Free Pascal Lazarus

469

, , , , . , ,
.
13.
i
a= e , () () .
: , . : , ,
.
14. ,
y= ax + b. : ,
. : , .
15. , . : ,
, . : , , , .
16. , 3- . , ,
, , . , , .
17.
a =cos i sin , () () .
: ,
. : , ,
.
18. ,
. : , . : ,
, .
19. , 3- .

.., .., .. Free Pascal Lazarus

470

, , , , . , .
20.
z=x+ y i, (x) (y)
. :
, .
: , , .
21. , R.
, .
h,
, .
22. ,
. : , . : , , .
23. , . : ,
( A= AT ), . : , , , .
24. ,
. : . : , , , .
25. , - .
, , . H,
,
.

.., .., .. Free Pascal Lazarus

471

10 Free Pascal
Free Pascal.
.
.
10.1 Lazarus
Lazarus , . () Canvas, Pen,
Brush.
Canvas :
( Tform);
( TSringGrid);
( Timage);
( TPrinter).
, Canvas,
,
, .
(X) (Y) . (0,0). , . Height,
Weight. .
Pixels[X,Y]:TColor.


X(integer), Y(integer).

.Canvas. Pixels[X,Y]:=Color;
Color Tcolor. (. 10.1):

.., .., .. Free Pascal Lazarus

472

10.1. Color

clBlack
clSilve

clMaroon
clRed

clGreen
clLime

clOlive
clBlue

clNavy
clFuchsia
-
-
clPurple
clAqua

clTeal
clWhite

clGray


:
Color:=.Canvas. Pixels[X,Y];
Color Tcolor.
Tcolor
longint. .

(B), (G) (R)
: $00BBGGRR.
Tanvas, (, ..)
, , :
TFont ();
TPen (, );
TBrush ().
TFONT
Canvas.TFont:
Name ( string) .
Size ( integer) (points).
, 0,353 , 1/72
.
Style ,
, (fsBold), (fsItalic), -

.., .., .. Free Pascal Lazarus

473

(fsUnderline) (fsStrikeOut).
, ,
, :
.Canvas. Font. Style:=[fsItalic,fsBold]
Color ( Tcolor) .
Charset ( 0..255) .
, ,
. . 10.2
Charset.
10.2. Charset

ANSI_CHARSET
0
ANSI
DEFAULT_CHARSET
1

.

Name
Size.
,

SYMBOL_CHARSET
2

MAC_CHARSET
77
Macintosh
GREEK_CHARSET
161

RUSSIAN_CHARSET
204

EASTEUROPE_CHARSET 238

(,

)
TPEN
() , , .
Canvas.TPen:
Color ( Tcolor) ;
Width ( Integer) ;

.., .., .. Free Pascal Lazarus

474

Style .
, 10.3.
10.3.

psSolid

psDash

psDot

psDashDot
-
psDashDodDot
,
psClear

Mode ,
. , Mode .
10.4. , Pen.Color,
.
, ,
.
10.4. Mode


pmBlack
Black

pmWhite
White

pmNop

pmNot
Not Screen

pmCopy
Pen
,

Color
Pen (
)
pmNotCopy
Not Pen

.., .., .. Free Pascal Lazarus

475

pmMergePenNot Pen or Not Pen

pmMaskPenNot Pen

pmMergeNotPen Not

PmMaskNotPen Not

pmMerge

Pen

pmNotMerge

Not

pmMask

Pen

pmNotMask

Not

pmXor

Pen

pmNotXor

Not





and Not Screen



Pen or Screen



Pen and Screen



or Screen


(Pen or Screen)
pmMerge
and Screen


(Pen and Screen)
pmMask
xor Screen
xor

(Pen xor Screen)
pmXor

TBRUSH
(Canvas.Brush) , .
:
Color ( Tcolor) ;
Style .
TCANVAS
-

.., .., .. Free Pascal Lazarus

476

. .
Procedure MoveTo(X, Y : Integer);
MoveTo , (X, Y).
PenPos Tpoint. TPoint :
type TPoint =record
X: Longint;
Y: Longint;
end;

PenPos :
X:=PenPos.X;
Y:=PenPos.Y;
Procedure LineTo(X, Y :Integer);
LineTo
(X, Y).
(X, Y).
.

TForm1.Button1Click, :
Procedure TfForm1.Button1Click(Sender: TObject)
begin
Form1.Canvas.LineTo(30,50);
end;
, (0,0)
(30,50).
:
Procedure TForm1.Button1Click(Sender: TObject)
begin
Form1.Canvas.LineTo(Canvas.PenPos.x+30,
Canvas.PenPos.y+50);
end;
.
, (0,0) (30,50). , , -

.., .., .. Free Pascal Lazarus

477

X 30, Y 50. ..
(30,50) (60,100). (60,100)
(90,150) ..
Procedure PolyLine(const Points array of TPoint);
PolyLine ,
Points.
.
:
procedure TForm1.Button1Click(Sender: TObject);
var temp :array [1..25] of TPoint;
i : byte;
j: integer;
begin
j:=1;
for i:=1 to 25 do
begin
//
temp[i].x:=25+(i-1)*10;
temp[i].y:=150-j*(i-1)*5;
j:=-j;
end;
Form1.Canvas.Polyline (temp);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Close;
end;

, 10.1.
Procedure Ellipse (X1, Y1, X2, Y2 :Integer);
Ellipse .
X1, Y1, X2, Y2 , . ,
.

.., .., .. Free Pascal Lazarus

478

10.1:
PolyLine

Procedure Arc (X1,Y1,X2,Y2,X3,Y3,X4,Y4:Integer);


. X1, Y1, X2, Y2 ,
, . X3, Y3
, , X4, Y4 , .
.

Procedure Rectangle (X1, Y1, X2, Y2 :Integer);


. X1, Y1, X2, Y2
.

Procedure RoundRect (X1,Y1,X2,Y2,X3,Y3:Integer);


. X1, Y1, X2,
Y2 , X3, Y3 , .

.., .., .. Free Pascal Lazarus

479

Procedure PolyGon(const Points array of TPoint);


() , Points. . PolyGon
Poliline, .
Pen,
Brush.

Procedure Pie (X1,Y1,X2,Y2,X3,Y3,X4,Y4 :Integer);


Pen, Brush. (X1, Y1) (X2, Y2)
, . ,
(X3, Y3). , (X4,
Y4). . ,
(X3, Y3) (X4, Y4).
, Heigth 500, Width
500. , Caption
.
(. . 10.2). ,
. . 10.2.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: Tbutton;

.., .., .. Free Pascal Lazarus

480

10.2:

procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var t: array [1..5] of TPoint;
begin
Form1.Canvas.LineTo(500,500);//
// .
Form1.Canvas.Pen.Color:= clMaroon;
Form1.Canvas.Pen.Width:= 5;
// .
Form1.Canvas.Rectangle(50,50,200,200);
Form1.Canvas.Pen.Color:= clolive;

.., .., .. Free Pascal Lazarus

481

// .
Form1.Canvas.Ellipse(50,50,100,200);
// .
Form1.Canvas.RoundRect(250,250,400,400,30,30);
// .
Form1.Canvas.Pie(300,300,400,400,350,350,500,500);
// .
t[1].x:=250; t[1].y:=10;
t[2].x:=350; t[2].y:=15;
t[3].x:=400; t[3].y:=50;
t[4].x:=300; t[4].y:=150;
t[5].x:=250; t[5].y:=100;
Form1.Canvas.Polygon (t) ;
Form1.Canvas.TextOut(10,10,' ');
end;
initialization
{$I unit1.lrs}
end.

procedure TextOut(X,Y:Integer;const Text:String);


Text, (X,
Y). PenPos Pen . Font, . ,
TextExtent, TextHeight TextWidth.
.

function TextExtent (const Text : String): Tsize;


Tsize,
Text, .
type Tsize = record
cx:Longint; cy:Longint;
end;

.., .., .. Free Pascal Lazarus

482

function TextHeight(const Text:String):Integer;


Text,
.

function TextWidth(const Text:String):Integer;


Text,
.
.
, , , .
.
, ,
, , . . .FormPaint
.FormResize.
.FormPaint
.
.FormResize
.
, , .FormPaint .FormResize.
10.2
y=f(x)
[a;b] : (xi,
f(xi)) . :
hx=(b-a)/N,

N [a;b].
xi=a+(i-1)hx;
yi=f(xi), i =0,N
,
.

.., .., .. Free Pascal Lazarus

483


Lazarus ( X
, 0
Width; OY ,
0 Height). X Y .
(X b, Y ) 79 (
U, 0 U
Wigth, V, 0 V Height).
X U cX+d, (a;b)
(X0,Width-Xk)80. a
X0 , b
Width-Xk,
c d :
ad = X0
cbd =Width Xk
, c, d:
d =X0ca
Width Xk X0
c=
ba
Y V V=gY+h. min Height-YK , max
Y0. g h :
gminh=HeigntYk
gmaxh=Y0
g h
h=Y0gmax
HeigthYkY0
g=
minmax

{
{

79 , Tform, Timage, Tprinter ..


80 X0, XK, Y0, YK , , .

.., .., .. Free Pascal Lazarus

484

c, d, g h. ,
Width ,
Height , ,
. , . ClientWidth (
)
ClientHeight (
) . c, d, g h :
d =X0ca
ClientWidth Xk X0
(10.1)
c=
ba
h=Y0gmax
ClientHeigthYk Y0
(10.2)
c=
minmax
:
1. N, X.
2. X, Y, (max)
(min) Y.
3. c, d, g h (10.1), (10.2).
4. Ui=cXi+d, Vi=gYi+h.
5. LineTo.
6. , .

Y V
kn, k .
(Y)
(V) .
- .10.3.
- k . 10.4.

{
{

.., .., .. Free Pascal Lazarus

485

10.3: -

.., .., .. Free Pascal Lazarus

486

-.
. 10.3 2 3.
4 13. 14. 15 16 U V ( 4).
17 19 . 20
.
. 10.4 4 15. 16 c, d, g
h. 17 20 . 21
24 , 25
.
10.1. f(x)
[a, b]. :
x
sin , x0
2
f x=
1x
, x0
3
,
, . ,
: Width 800, Height 700.
TImage.
TImage1 ,
Button1. .
Caption
. ,
.
BorderStyle
. BorderStyle bsSingle, .
,

BolderIcons.BiMaximize

BolderIcons.BiMinimize False.

.., .., .. Free Pascal Lazarus

487

10.4: -

.., .., .. Free Pascal Lazarus

488

Caption .

.10.5.

10.5:
a b ( FormCreate).
:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
LResources,
Forms,
Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
//, .
function f(x:real):real;
//, .
procedure Graphika(a, b: real);
type
{ TForm1 }
TForm1 = class(TForm)

.., .., .. Free Pascal Lazarus

Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var

Form1: TForm1;
// :
//x0, xk, y0, yk -
// , , ;
//x, y - ,
// ""
// ;
//u, v - ,
// ""
// ;
//N - .
x0, y0, xk, yk, a, b :real;
x, y : array [0..1000] of real;
u, v : array [0..1000] of integer;
N : integer;
implementation
// ,
// Image1
function f (x : real) : real;
begin
if x<=0 then Result:=sin(x/2)
else Result:=sqrt((1+x)/3);
end;
//,
// Image1.
procedure Graphika(a, b: real);
//Kx+1 - ,
// .

489

.., .., .. Free Pascal Lazarus

//Ky+1 - ,
// Y.
const Kx=5;Ky=5;
var dx, dy, c, d, g, h, max, min :real;
i, tempx, tempy :integer; s : string;
begin
// .
h:=(b-a)/(N-1);
// x y.
x[0]:=a;
y[0]:=f(x[0]);
for i:=1 to N do
begin
x[i]:=x[i-1]+h;
y[i]:=f(x[i]);
end;
//
// Y.
max:=y[0]; min:=y[0];
for i:=1 to N do
begin
if y[i]>max then max:=y[i];
if y[i]<min then min:=y[i];
end;
//
// "" ""
// .
c:=(Form1.Image1.ClientWidth-x0-xk)/(b-a);
d:=x0-c*x[0];
g:=(Form1.Image1.ClientHeight-y0-yk)/
(min-max);
h:=yk-g*max;
//
// .
for i:=0 to N do
begin
u[i]:=trunc(c*x[i]+d);
v[i]:=trunc(g*y[i]+h);

490

.., .., .. Free Pascal Lazarus

491

end;
Form1.Image1.Canvas.Color:= clGray;
Form1.Image1.Canvas .Pen .Mode:= pmNot;
// Image1.
Form1.Image1.Canvas.MoveTo(u[0],v[0]);
Form1.Image1.Canvas.Pen.Width:= 2;
Form1.Image1.Canvas.Pen.Color:= clGreen;
for i:=1 to N do
Form1.Image1.Canvas.LineTo(u[i],v[i]);
Form1.Image1.Canvas.Pen.Width:= 1 ;
Form1.Image1.Canvas.Pen.Color:= clBlack;
// ,
// .
Form1.Image1.Canvas.MoveTo(trunc(x0),trunc(h));
if (trunc(h)>yk) and
(trunc(h)<trunc(Form1.Image1.ClientHeight-y0))
then
Form1.Image1.Canvas.LineTo(trunc
(Form1.Image1.ClientWidth -xk),trunc(h));
Form1.Image1.Canvas.MoveTo(trunc(d),trunc(yk));
if (trunc(d)>x0) and
(trunc(d)<trunc(Form1.Image1.ClientWidth-xk))
then
Form1.Image1.Canvas.LineTo(trunc(d),
trunc(Form1.Image1.ClientHeight -y0));
// ,
//
//"" ,
//
dx:=(Form1.Image1.ClientWidth -x0-xk)/KX;
// ,
for i:=0 to KX do
begin
//
// ,
if (i=0) or (i=KX) then
Form1.Image1.Canvas.Pen.Style:=psSolid
// - .

.., .., .. Free Pascal Lazarus

492

else
Form1.Image1.Canvas.Pen.Style:=psDash;
// , .
Form1.Image1.Canvas.MoveTo(trunc(x0+i*dx),
trunc(yk));
Form1.Image1.Canvas.LineTo(trunc(x0+i*dx),
trunc(Form1.Image1.ClientHeight -y0));
end;
// ,
// Y,
// "" .
dy:=(Form1.Image1.ClientHeight -y0-yk)/KY;
for i:=0 to KY do
begin
//
// ,
if (i=0) or (i=KY) then
Form1.Image1.Canvas.Pen.Style:=psSolid
// - .
else
Form1.Image1.Canvas.Pen.Style:=psDash;
// , Y.
Form1.Image1.Canvas.MoveTo(trunc(x0),
trunc(yk+i*dy));
Form1.Image1.Canvas.LineTo(trunc
(Form1.Image1.ClientWidth-xk),trunc(yk+i*dy));
end;
Form1.Image1.Canvas.Pen.Style:=psSolid;
// ,
// dx -
// .
dx:=(b-a)/KX;
tempy:=
trunc(Form1.Image1.ClientHeight -y0+10);
for i:=0 to KX do
begin
// .
Str(a+i*dx:5:2,s);

.., .., .. Free Pascal Lazarus

493

// -
// "" .
tempx:=trunc(x0+i*(Form1.Image1.ClientWidth x0-xk)/KX)-10;
//
Form1.Image1.Canvas.TextOut(tempx,tempy,s);
end;
if (trunc(d)>x0) and
(trunc(d)<Form1.Image1.ClientWidth-xk) then
Form1.Image1.Canvas.TextOut(trunc(d)-5,tempy,'0');
// dy -
// Y .
dy:=(max-min)/KY;
tempx:=5;
for i:=0 to KY do
begin
// .
Str(max-i*dy:5:2,s);
// y- Y
// "" .
tempy:=trunc(yk-5+
i*(Form1.Image1.ClientHeight- y0-yk)/KY);
// Y.
Form1.Image1.Canvas.TextOut(tempx,tempy,s);
end;
if (trunc(h)>yk) and (trunc(h)<
Form1.Image1.ClientHeight-y0) then
Form1.Image1.Canvas.TextOut(tempx+10,
runc(h)-5,'0');
tempx:=trunc(x0+i*(Form1.Image1.ClientWidth x0-xk)/2);
Form1.Image1.Canvas.TextOut(tempx,10,
' ');
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var s : string; kod : integer;

.., .., .. Free Pascal Lazarus

494

begin
N:=100;
x0:=40;
xk:=40;
y0:=40;
yk:=40;
repeat
s:=InputBox(' ',
' ','-10');
Val(s,a,kod);
until kod=0;
repeat
s:=InputBox(' ',
' ','10');
Val(s,b,kod);
until kod=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Graphika(a, b);
end;
initialization
{$I unit1.lrs}
end.
(. 10.6)
(. 10.7) . . (. 10.8).

10.6:

10.7:

.., .., .. Free Pascal Lazarus

495

10.8:
10.3
f(x) [a;b]. . 10.5.
10.5.
f(x)
f(x)

x 32
sin
, x5
3
5
1 x , x5
3

tan x , x1
3 ex1 , x1

x 2 x2
, x1
x3

10

e
x 2 , x1
2

x3,6
, x0
x3
3 1 x , x0
sin

.., .., .. Free Pascal Lazarus

f(x)

1x
, x2
3
3 1 x3 , x2
log

2 cos x23 , x2

3,5
sin x22 , x2

x6
, x5
x3
1 x4 , x5
cos

f(x)

x 33x 2
, x2
3
3 log 1,5 x2 , x2

11

12

13

x 22
cos
, x3
x
12x 2 , x3

x 3sin x , x3,5
5 x
, x3,5
2

x
4

e , x 2,5
5 x 2 , x2,5

x2
, x4
x3
3 e x x 2 , x4
cos

x 3x , x1
3 ln 10,5 x , x1

496

x x2 , x1
5 e x7 , x1

14

1x 3
log
, x2,5
2
3 12x2 x 3 , x2,5

15

x 3 x2 , x3
5 sin 10,5x2 , x3

16

f1(x), f2(x), f2(x)


[a;b]. . 10.6.
10.6.

f1(x)
x6
2
x 3

f2(x)

f3(x)

x 3sin x

5x3 sin x 2

17

cos

18

12x 2 x 3

e 7

19

3 1 x 3

142x 23x 3

cos sin x

72x 4

3 35x 2x 32

20

sin


x
x
e
3

x
2

sin

x
3

.., .., .. Free Pascal Lazarus

f1(x)

21

5 7 x 3

22

3 ln 12x 2

23

cos

24

3 1 x 2 x32

25

x
sin 2x
2

x2

f2(x)
cos
e

cos sin x 2

cos

4 1 x62x 2
2sin

f3(x)

x
5

1 x x 342

497

3x 45x 27x2
5x 23x3
x
7

e 4

.., .., .. Free Pascal Lazarus

498


. ? , Free Pascal . - , ,
.
, , ,
.

.

.., .., .. Free Pascal Lazarus

499


....................................................................................................96
-.................................................................................................96
......................................................................................61
...................................................................................62
...................................................................................64
.................................................................................................76
......................................................................................28, 30
...............................................................................86
.........................................................................................................74
.....................................................................................................68
..........................................................................................68
............................................................................30, 43
.........................................................................................67
.......................................................................................31, 67
..........................................................................................57, 64
..................................................................................................43
...........................................................................59
...................................................................................................68
....................................................................................97
................................................................................................72, 213
-.......................................................................217
................................................................241
..............................230
.............................................................230
................231
................................................................................
...............................................................................235
............................................................................232
..............................................................237
......................................................................................249
................................................................................................75
.......................................................................................31
...............................................................................................147
..........................................................................................44
.........................................................................................28, 30
.........................................................................................................
...............................................................................................117

.., .., .. Free Pascal Lazarus

500

..........................................................................132
.........................................................................................97
...............................................................................................98
................................................................................................98
........................................................................126
............................................129
........................................................................127
........................................................................................................
....................................................................................78
.............................................................................................80
..............................................................................................80
..................................................................................81
.........................................................................................81
..........................................................................28, 32
...........................................................................34, 43
................................................................................................68
..........................................................................................164
......................................................................................65
...............................................................................64
..................................................................................................30, 64
................................................................................................166
......................................................................................30
.......................................................................97
..........................................................................30
...............................................................................................121
..............................................................................81
.........................................................................................................73
...............................................................................................125
................................................................................................68
........................................................................................70
, .............................................................................................70
........................................................................................72
.............................................................................................71
......................................................................................................71
.......................................................................................71
...........................................................................................69
..............................................................................72
......................................................................................69

.., .., .. Free Pascal Lazarus

501

.................................................................................................12
............................................................................................76, 246
...........................................................................................................75
.........................................................................63
...................................................................................................171
.........................................................................................198
..........................................................................................................125
...............................................................................................125
...............................................................................................125
........................................................................................................125
...............................................................................97
Free Pascal..................................................................................................11

.., .., .. Free Pascal Lazarus

502

1. .., .. 7.0. - .:
, 2006. - 320 .:. - ( ).
2. .. Microsoft Visual
C++ Turbo C++ Explorer (
..)/ .. - .: , 2007. - 352 .:. - ().
3. .. Delphi.
: . - .:, 2005.-640 .:.
4. .. Delphi 2007. . Delphi 2007/ .. . .
..- .: , 2008. - 368 .:.
5. .., ..
.- .:, 1981. - 720 .
6. GNU Pascal . URL: .http://ru.wikipedia.
org/wiki/GNU_Pascal ( 03.08.2009).
7. Free Pascal - Advanced open source Pascal compiler for Pascal
and Object Pascal - Home Page. URL: http://www.freepascal.org (
03.08.2009).
8. GNU Pascal. URL: http://www.gnu-pascal.de/gpc/h-index.html
( 03.08.2009).
9. Main
Page/ru

Free
Pascal
wiki.
URL:
http://wiki.freepascal.org/Main_Page/ru ( 03.11.2009).
10. Free Pascal.ru -
Free Pascal & Lazarus & MSE. URL http://www.freepascal.ru (
: 03.11.2009).
11. Lazarus News. URL: http://www.lazarus.freepascal.org (
03.11.2009).
12. Lazarus . URL: http://ru.wikipedia.org/wiki/Lazarus
( 03.11.2009).

ISBN 978-966-8248-26-9

47

.., .., ..
Free Pascal Lazarus. - .: , , 2009. 503 .

ISBN 978-966-8248-26-9

.., .., .., 2009


:
,
: 1017 21.08.2002.
83000, . , . , 58, .1.311
. : (062) 304 90 19

: ..
: .C.
: ..
8.12.2009 .
6090 1/16
... 36.04
.

200 .

-.
: 83000, . , . , 58.
.: (062) 335 64 55.