Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Button2: TButton;
Label1: TLabel;
Button3: TButton;
Label2: TLabel;
Button4: TButton;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure LabeledEdit4Change(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure ShowPoint(C : integer); // Об'ява
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
A:array [1..10,1..200] of double;
// VA:array [1..10,1..200] of double;
x : integer=1;
y : integer=2;
n : integer=0;
Curr : integer=1;
Ind :array [1..200] of integer;
Implementation
{$R *.dfm}
function LVidr(x1, y1, x2, y2:double): double;
begin
LVidr:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
end;
procedure TForm1.ShowPoint(C : integer); // Опис
begin
Label7.Caption:=FloatToStr(A[x][Ind[C]]);
Label8.Caption:=FloatToStr(A[y][Ind[C]]);
Label6.Caption:=IntToStr(Ind[C]);
Label10.Caption:=FloatToStr(LVidr(A[x][Ind[C]],A[y][Ind[C]],0,0));
Button7.Enabled:=true;
Button8.Enabled:=true;
if C>=n then Button7.Enabled:=false;
if C<=1 then Button8.Enabled:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
n:=n+1;
LabeledEdit1.EditLabel.Caption:='Ax[' + inttostr(n+1) + ']';
LabeledEdit2.EditLabel.Caption:='Ay[' + inttostr(n+1) + ']';
LabeledEdit4.Text:=inttostr(n-1);
A[x][n]:=StrToFloat(LabeledEdit1.Text);
A[y][n]:=StrToFloat(LabeledEdit2.Text);
if n>1 then Button4.Enabled:=true;
Button5.Enabled:=false;
Button6.Enabled:=false;
Button7.Enabled:=false;
Button8.Enabled:=false;
LabeledEdit1.Text:=FloatToStr(A[y][n]/5-n/(n*n) - random(120) );
LabeledEdit2.Text:=FloatToStr(-A[x][n]/5-n/(n*n) +1000 - random(2000) );
end;
procedure TForm1.Button3Click(Sender: TObject);
var L:double;
i, n1, nn: Integer;
begin
n1:=StrToInt(LabeledEdit3.Text);
nn:=StrToInt(LabeledEdit4.Text);
L:=0;
for i := n1 to nn do
L:=L+LVidr(A[x][i],A[y][i],A[x][i+1],A[y][i+1]);
Label2.Caption:=FloatToStr(L);
end;
procedure TForm1.Button4Click(Sender: TObject);
var i, j, ik: Integer;
k: double;
begin
//VA=A;
// for i := 1 to n do
// for j := 1 to 2 do
// VA[j][i]:= A[j][i]; {Створення копії ламаної}
for i := 1 to n do
Ind[i]:= i; {Початкове визначення Ind}
{Бульбашка}
for j := 1 to n-1 do
for i := 1 to n-j do
if LVidr(A[x][Ind[i]], A[y][Ind[i]], 0, 0)>LVidr(A[x][Ind[i+1]], A[y][Ind[i+1]], 0, 0)
then begin
{VA[x][i]<=>VA[x][i+1]}
// k:=VA[x][i];VA[x][i]:=VA[x][i+1];VA[x][i+1]:=k; // замінв x
// k:=VA[y][i];VA[y][i]:=VA[y][i+1];VA[y][i+1]:=k; // замінв y
ik:=Ind[i];Ind[i]:=Ind[i+1];Ind[i+1]:=ik; // замінв Ind
end;
Button5.Enabled:=true;
Button6.Enabled:=true;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Curr:=1;
ShowPoint(Curr);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
Curr:=n;
ShowPoint(Curr);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
Curr:=Curr+1;
ShowPoint(Curr);
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
Curr:=Curr-1;
ShowPoint(Curr);
end;
procedure TForm1.LabeledEdit4Change(Sender: TObject);
begin
if ((LabeledEdit4.Text='') or (LabeledEdit4.Text='-') or (LabeledEdit4.Text='0')) then LabeledEdit4.Text:='0'
else if StrToInt(LabeledEdit4.Text)>n-1 then LabeledEdit4.Text:=IntToStr(0);
end;
end.
№ 3
unit Unit1;