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

1.

2. -15-08
3. 9
4. 4
5. - .
, .
.
6. 3
.
7.

8. :

Form1

OnCreate

9. , :

procedure
TForm1.Button1Click
procedure
TForm2.Button1Click
procedure
TForm3.Button1Click
function prin

function suma
procedure sd

10.

/
/
- /
- /
- /
/

()

Otr

Real

suma

()

Dlina

nomer

()

i
k

r
o
R1 r2

x
dl

nm

nx

Real

Integer

Integer

Integer

Real

Tochka
real

Otr

Real

Integer

Integer

11. ,

12.

13. ( .dpr)
14. (.pas)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Grids, Unit4;
type
TForm1 = class(TForm)

StringGrid1: TStringGrid;
Edit1: TEdit;
Edit2: TEdit;
StaticText1: TStaticText;
LabeledEdit1: TLabeledEdit;
Button1: TButton;
LabeledEdit2: TLabeledEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
var nomer:integer; dlina:real;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);


var i:integer;
begin
for i:=1 to 7 do
stringgrid1.Cells[0,i]:='' + floattostr(i);
stringgrid1.Cells[1,0]:='X1';
stringgrid1.Cells[2,0]:='Y1';
stringgrid1.Cells[3,0]:='X2';
stringgrid1.Cells[4,0]:='Y2';
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,k:integer; r:real; t:array[1..7] of otr; o:tochka;
begin
k:=0;
nomer:=0;
dlina:=0;
r:=strtofloat(labelededit1.Text);
o.x:=strtofloat(edit1.Text); o.y:=strtofloat(edit1.Text);
for i:=1 to strtoint(labelededit2.Text) do
begin
t[i].x1:=strtofloat(stringgrid1.cells[1,i]);
t[i].y1:=strtofloat(stringgrid1.cells[2,i]);
t[i].x2:=strtofloat(stringgrid1.cells[3,i]);
t[i].y2:=strtofloat(stringgrid1.cells[4,i]);
end;
for i:=1 to strtoint(labelededit2.Text) do
if prin(t[i],r,o) then
k:=k+1;
if k=strtoint(labelededit2.Text) then begin
form2.show;
form2.Label1.Caption:=' '+floattostr(suma(t,strtoint(labelededit2.text)));
end
else
begin
sd(t,strtoint(labelededit2.text),dlina,nomer);
form3.show;
form3.Label1.Caption:=' '+floattostr(nomer)+' '+floattostr(dlina);
end;
end;
end.

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit1;
type
TForm2 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form2.Close;
end;
end.

unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit1;
type
TForm3 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation

{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
form3.close;
end;
end.

unit Unit4;
interface
type otr=record x1,y1,x2,y2:real; end; tochka=record x,y:real; end;
function prin(x:otr; r:real; o:tochka):boolean;
function suma(x:array of otr; nx:integer):real;
procedure sd(x:array of otr; nx:integer; var dl:real; var nm:integer);
implementation
function prin(x:otr; r:real; o:tochka):boolean;
var r1,r2:real;
begin
prin:=false;
r1:=sqrt(sqr(o.x-x.x1)+sqr(o.y-x.y1));
r2:=sqrt(sqr(o.x-x.x2)+sqr(o.y-x.y2));
if (r1<=r)and(r2<=r) then prin:=true;
end;
function suma(x:array of otr; nx:integer):real;
var i:integer;
begin
result:=0;
for i:=0 to nx-1 do
result:=result+sqrt(sqr(x[i].x1-x[i].x2)+sqr(x[i].y1-x[i].y2));
end;
procedure sd(x:array of otr; nx:integer; var dl:real; var nm:integer);
var i:integer;
begin
dl:=sqrt(sqr(x[0].x1-x[0].x2)+sqr(x[0].y1-x[0].y2));
nm:=0;
for i:=0 to nx-1 do

if sqrt(sqr(x[i].x1-x[i].x2)+sqr(x[i].y1-x[i].y2))>dl then begin


dl:=sqrt(sqr(x[i].x1-x[i].x2)+sqr(x[i].y1-x[i].y2));
nm:=i;
end;
nm:=nm+1;
end;
end.