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

1.

2. -11-08
3. 3
4. 2
5. - , ,
- -. -
.
6. 2
.
1) -
X Y,
( ).
2) ( )
(, ..):
-
,
(. )
- , ,
( ), (.
)
3), ,
,
.
4)
0.001, .. "a = b"

"abs(a-b) < 0.001".
5) -
, ,
, .
6)
-
( A,B,C), ( ),.
- (, , ,
..)
-
- ,
(, ..)

- ,
(.,
, ..),
.
7)
Menu, Memo.
8) :
;

( OpenDialog SaveDialog)
( Edit, StringGrid ..)

-
;
- OpenDialog

SaveDialog ( );
;
( )
9) .
10) ,
PaintBox. .
X Y,
.
11) :
1 - ,
;
1 - ,
.
12) 3- :
1 ( 1 , , ),
2.
2 ( /, ..)
3
7.

8. :

Form2
Form4

OnClose
OnClick

9. , :

procedure
TForm1.Button1Click
procedure
TForm2.FormClose
procedure
TForm2.N1Click
procedure
TForm2.N6Click
procedure
TForm2.N2Click
procedure
TForm2.N5Click
procedure
TForm2.N3Click
procedure
TForm2.N4Click
function Kam


, 1-
, .

function G
procedure
TForm4.Button1Click
procedure
TForm4.FormClick

Form4

10.

/
/
- /
- /
- /
/

()

Tochka

. .

Integer

Integer

()

k1o,
k2o

wopt

()

i
Tchk

F
k1,k2
,t1,t2
w
Flag
x
n
r
O
y,x,x1
,x2,y
1,y2

Integer

Integer
Tochka

Tochka

Integer

Integer

integer

. .

Tochka

Integer

Real

Cen

Integer

11. ,

12.

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

Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
form2.show;
for i:=1 to 7 do
form2.stringgrid1.cells[0,i]:=' '+floattostr(i);
form2.stringgrid1.cells[1,0]:='X';
form2.stringgrid1.cells[2,0]:='Y';
form2.memo1.text:=' ';
hide;
end;
end.

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Grids, StdCtrls, ExtCtrls, Unit3;
type
TForm2 = class(TForm)
LabeledEdit1: TLabeledEdit;
Memo1: TMemo;
StringGrid1: TStringGrid;
MainMenu1: TMainMenu;
nm1: TMenuItem;
N1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
procedure N1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure N6Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
k1o,k2o:integer;
implementation
uses Unit1, Unit4;
var t:array[1..7] of tochka;
f:file of tochka; tchk:tochka;
{$R *.dfm}
procedure TForm2.N1Click(Sender: TObject);
var i,k1,k2,w,wopt,flag,n:integer;
begin
n:=strtoint(labeledEdit1.Text);
wopt:=0;
for i:=1 to n do
begin
t[i].x:=strtoint(StringGrid1.Cells[1,i]);
t[i].y:=strtoint(StringGrid1.Cells[2,i]);
end;
flag:=0;
for k1:=1 to (n-1) do
for k2:=k1+1 to n do
if (t[k1].x<>t[k2].x)and(t[k1].y<>t[k2].y)then
begin

w:=Kam(t[k1],t[k2],t,n);
if flag=0 then
begin
flag:=1;
wopt:=w;
k1o:=k1; k2o:=k2;
end
else
if w>wopt then
begin
wopt:=w;
k1o:=k1; k2o:=k2;
end;
end;
if flag=1 then
memo1.Text:=' '+floattostr(wopt)+' , '+floattostr(sqrt(sqr(t[k1o].x-t[k2o].x)
+sqr(t[k1o].y-t[k2o].y))/2)
else
memo1.Text:=' ';
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.close;
end;
procedure TForm2.N6Click(Sender: TObject);
var i:integer;
begin
for i:=1 to strtoint(labelededit1.text) do
begin
stringgrid1.Cells[1,i]:=floattostr(random(13)-4);
stringgrid1.Cells[2,i]:=floattostr(random(13)-4);
end;
end;
procedure TForm2.N5Click(Sender: TObject);
begin
form2.Close;
end;
procedure TForm2.N2Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
begin
AssignFile(f,SaveDialog1.Filename);
Rewrite(f);
for i:=1 to strtoint(labelededit1.text) do
begin
tchk.x:=StrToint(StringGrid1.Cells[1,i]);
tchk.y:=StrToint(StringGrid1.Cells[2,i]);
write(f,tchk);
end;
if FileExists(SaveDialog1.Filename) then
Memo1.text:= ' '
else
Memo1.text:= ' ';
CloseFile(f);
end
else
Memo1.text:=' SaveDialog1';
end;

procedure TForm2.N3Click(Sender: TObject);


var i:integer;
begin
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
memo1.text:=' ';
AssignFile(f,OpenDialog1.FileName);
Reset(f);
labelededit1.Text:=floattostr(Filesize(f));
for i:=1 to Filesize(f) do
begin
Read(f,tchk);
StringGrid1.Cells[1,i]:= FloatToStr(tchk.x);
StringGrid1.Cells[2,i]:= FloatToStr(tchk.y);
end;
CloseFile(f);
end
else
memo1.text:=' ';

end
else
memo1.text:=' OpenDialog1';
end;
procedure TForm2.N4Click(Sender: TObject);
begin
form4.show;
hide;
end;
end.

unit Unit3;
interface
type tochka=record x,y:integer; end; cen=record x,y:real; end;
function Kam(t1:tochka; t2:tochka; x:array of tochka; n:integer):integer;
function G(t1:tochka; o:cen; r:real):boolean;
implementation
function Kam(t1:tochka; t2:tochka; x:array of tochka; n:integer):integer;
var r:real; o:cen; i:integer;
begin
result:=0;
r:=sqrt(sqr(t1.x-t2.x)+sqr(t1.y-t2.y))/2;
o.x:=(t1.x+t2.x)/2;
o.y:=(t1.y+t2.y)/2;
for i:=0 to n-1 do
if G(x[i],o,r) then
result:=result+1;
end;
function G(t1:tochka; o:cen; r:real):boolean;
begin
result:=false;
if abs(sqrt(sqr(t1.x-o.x)+sqr(t1.y-o.y))-r)<0.001 then
result:=true;
end;
end.

unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Unit2;
type
TForm4 = class(TForm)
Button1: TButton;
PaintBox1: TPaintBox;
procedure Button1Click(Sender: TObject);
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.Button1Click(Sender: TObject);
begin
form2.show;
form4.Close;
end;
procedure TForm4.FormClick(Sender: TObject);
var i,x,y,x1,x2,y1,y2:integer; r:real;
begin
with paintbox1.canvas do
begin
pen.color:=clred;
pen.width:=2;

moveto(250,0);
lineto(250,500);
moveto(0,250);
lineto(500,250);
pen.color:=clGreen;
pen.width:=1;
r:=sqrt(sqr(strtoint(form2.StringGrid1.cells[1,k1o])-strtoint(form2.StringGrid1.cells[1,k2o]))+sqr(strtoint(form2.StringGrid1.cells[2,k1o])strtoint(form2.StringGrid1.cells[2,k2o])))/2;
x:=Trunc((strtoint(form2.StringGrid1.cells[1,k1o])+strtoint(form2.StringGrid1.cells[1,k2o]))/2);
y:=Trunc((strtoint(form2.StringGrid1.cells[2,k1o])+strtoint(form2.StringGrid1.cells[2,k2o]))/2);
brush.style:=bsClear;
ellipse(250+x*27-trunc(r)*27,250-y*27-trunc(r)*27,250+x*27+trunc(r)*27,250-y*27+trunc(r)*27);
for i:=1 to strtoint(form2.LabeledEdit1.text) do
begin
x1:=250+strtoint(form2.StringGrid1.Cells[1,i])*27-3;
x2:=250+strtoint(form2.StringGrid1.Cells[1,i])*27+3;
y1:=250-strtoint(form2.StringGrid1.Cells[2,i])*27-3;
y2:=250-strtoint(form2.StringGrid1.Cells[2,i])*27+3;
brush.color:=clBlue;
brush.style:=bsSolid;
ellipse(x1,y1,x2,y2);
end;
end
end;
end.