Vous êtes sur la page 1sur 5

1.

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

8. :

Form1

OnCreate

9. , :

procedure
TForm2.N2Click
procedure
TForm2.N3Click
procedure
TForm2.N4Click
procedure
TForm2.N5Click
procedure
TForm2.N6Click

function prov

10.

/
/
- /
- /
- /
/

()

()

Integer

real

Integer

()

Integer
romb

romb

romb

sum
kol

Fr
Frt

11. ,

12.

13. ( .dpr)
14. (.pas)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
SaveDialog1: TSaveDialog;
StringGrid1: TStringGrid;
LabeledEdit1: TLabeledEdit;
Label1: TLabel;

OpenDialog1: TOpenDialog;
N5: TMenuItem;
N6: TMenuItem;
procedure N6Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type romb=record x1,y1,x2,y2,x3,y3,x4,y4:integer; end;
var fr:file of romb; frt:textfile;
r:romb;
{$R *.dfm}
function prov(rom:romb):boolean;
var r1,r2,r3,r4,d1,d2:real;
begin
prov:=false;
r1:=sqrt(sqr(r.x1-r.x2)+sqr(r.y1-r.y2));
r2:=sqrt(sqr(r.x2-r.x3)+sqr(r.y2-r.y3));
r3:=sqrt(sqr(r.x3-r.x4)+sqr(r.y3-r.y4));
r4:=sqrt(sqr(r.x4-r.x1)+sqr(r.y4-r.y1));
d1:=sqrt(sqr(r.x1-r.x3)+sqr(r.y1-r.y3));
d2:=sqrt(sqr(r.x2-r.x4)+sqr(r.y2-r.y4));
if (r1=r2)and(r2=r3)and(r3=r4)and(d1<>d2) then
prov:=true;
end;
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';
stringgrid1.Cells[5,0]:='X3';
stringgrid1.Cells[6,0]:='Y3';
stringgrid1.Cells[7,0]:='X4';
stringgrid1.Cells[8,0]:='Y4';
end;
procedure TForm1.N2Click(Sender: TObject);
begin
if savedialog1.execute then assignfile(fr,savedialog1.filename);
rewrite(fr);
closefile(fr);
end;
procedure TForm1.N3Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
begin
AssignFile(fr,SaveDialog1.FileName);
Rewrite(fr);
for i:=1 to strtoint(labelededit1.Text) do
begin
r.x1:=strtoint(stringgrid1.Cells[1,i]);
r.y1:=strtoint(stringgrid1.Cells[2,i]);
r.x2:=strtoint(stringgrid1.Cells[3,i]);
r.y2:=strtoint(stringgrid1.Cells[4,i]);
r.x3:=strtoint(stringgrid1.Cells[5,i]);
r.y3:=strtoint(stringgrid1.Cells[6,i]);
r.x4:=strtoint(stringgrid1.Cells[7,i]);
r.y4:=strtoint(stringgrid1.Cells[8,i]);
write(fr,r);
end;
Closefile(fr);
end;
end;
procedure TForm1.N4Click(Sender: TObject);
var i,n,kol:integer; sum:real;

begin
kol:=0; sum:=0;
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
AssignFile(fr,OpenDialog1.FileName);
Reset(fr);
n:=filesize(fr);
labelededit1.Text:=floattostr(n);
for i:=1 to n do
begin
read(fr,r);
stringgrid1.Cells[1,i]:=floattostr(r.x1);
stringgrid1.Cells[2,i]:=floattostr(r.y1);
stringgrid1.Cells[3,i]:=floattostr(r.x2);
stringgrid1.Cells[4,i]:=floattostr(r.y2);
stringgrid1.Cells[5,i]:=floattostr(r.x3);
stringgrid1.Cells[6,i]:=floattostr(r.y3);
stringgrid1.Cells[7,i]:=floattostr(r.x4);
stringgrid1.Cells[8,i]:=floattostr(r.y4);
if prov(r) then
if (r.y1<0)and(r.y2<0)and(r.y3<0)and(r.y4<0) then
begin
kol:=kol+1;
sum:=sum+sqrt(sqr(15-((r.x2+r.x4)/2))+sqr(15-((r.y2+r.y4)/2)));
end;
end;
label1.Caption:='- '+floattostr(kol)+' (15,15)
'+floattostr(sum/kol);
end;
end;
Closefile(fr);
end;
procedure TForm1.N5Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
begin
AssignFile(frt,SaveDialog1.FileName);
Rewrite(frt);
for i:=1 to strtoint(labelededit1.Text) do
begin
r.x1:=strtoint(stringgrid1.Cells[1,i]);
write(frt, r.x1, ' ');
r.y1:=strtoint(stringgrid1.Cells[2,i]);
write(frt,r.y1, ' ');
r.x2:=strtoint(stringgrid1.Cells[3,i]);
write(frt,r.x2, ' ');
r.y2:=strtoint(stringgrid1.Cells[4,i]);
write(frt,r.y2, ' ');
r.x3:=strtoint(stringgrid1.Cells[5,i]);
write(frt,r.x3, ' ');
r.y3:=strtoint(stringgrid1.Cells[6,i]);
write(frt,r.y3, ' ');
r.x4:=strtoint(stringgrid1.Cells[7,i]);
write(frt,r.x4, ' ');
r.y4:=strtoint(stringgrid1.Cells[8,i]);
writeln(frt,r.y4, ' ');
end;
Closefile(frt);
end;
end;
procedure TForm1.N6Click(Sender: TObject);
var i,kol,n:integer; sum:real;
begin
kol:=0; sum:=0; n:=0;
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
AssignFile(frt,OpenDialog1.FileName);
Reset(frt);
while not EOF(frt) do begin readln(frt); n:=n+1; end;
Closefile(frt); Reset(frt);
for i:=1 to n do
begin
readln(frt, r.x1, r.y1, r.x2, r.y2, r.x3, r.y3, r.x4, r.y4);
stringgrid1.Cells[1,i]:=floattostr(r.x1);
stringgrid1.Cells[2,i]:=floattostr(r.y1);
stringgrid1.Cells[3,i]:=floattostr(r.x2);
stringgrid1.Cells[4,i]:=floattostr(r.y2);
stringgrid1.Cells[5,i]:=floattostr(r.x3);
stringgrid1.Cells[6,i]:=floattostr(r.y3);

stringgrid1.Cells[7,i]:=floattostr(r.x4);
stringgrid1.Cells[8,i]:=floattostr(r.y4);
if IOResult=0 then begin
if prov(r) then
if (r.y1<0)and(r.y2<0)and(r.y3<0)and(r.y4<0) then
begin
kol:=kol+1;
sum:=sum+sqrt(sqr(15-((r.x2+r.x4)/2))+sqr(15-((r.y2+r.y4)/2)));
end;
end
else break;
end;
labelededit1.Text:=floattostr(n);
if kol<>0 then
label1.Caption:='- '+floattostr(kol)+' (15,15)
'+floattostr(sum/kol)
else
label1.caption:=' ';
end;
end;
Closefile(frt);
end;
end.

Vous aimerez peut-être aussi