Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лк9 .doc
Скачиваний:
1
Добавлен:
17.07.2019
Размер:
75.78 Кб
Скачать

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;

Button9: TButton;

Button10: TButton;

Button11: TButton;

Button12: TButton;

Label11: TLabel;

Label12: 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 ShowPointInd(C : integer); // Об'ява

procedure ShowPoint(); // Об'ява

procedure Button6Click(Sender: TObject);

procedure Button7Click(Sender: TObject);

procedure Button8Click(Sender: TObject);

procedure Button9Click(Sender: TObject);

procedure Button10Click(Sender: TObject);

procedure Button11Click(Sender: TObject);

procedure Button12Click(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;

Current : integer=1;

Ind :array [1..200] of integer;

Ind_1 :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.ShowPointInd(C : integer); // Опис

begin

Label7.Caption:=FloatToStr(A[x][Ind[C]]);

Label8.Caption:=FloatToStr(A[y][Ind[C]]);

Label6.Caption:=IntToStr(C);

Label10.Caption:=FloatToStr(LVidr(A[x][Ind[C]],A[y][Ind[C]],0,0));

Label12.Caption:=IntToStr(Curr);

//Current:=Ind[C];

Button11.Enabled:=true;

Button12.Enabled:=true;

Button7.Enabled:=true;

Button8.Enabled:=true;

if C>=n then Button7.Enabled:=false;

if C<=1 then Button8.Enabled:=false;

if Current>=n then Button11.Enabled:=false;

if Current<=1 then Button12.Enabled:=false;

end;

}

procedure TForm1.ShowPoint(); // Опис

begin

Label7.Caption:=FloatToStr(A[x][Current]);

Label8.Caption:=FloatToStr(A[y][Current]);

Label6.Caption:=IntToStr(Current);

Label10.Caption:=FloatToStr(LVidr(A[x][Current],A[y][Current],0,0));

Label12.Caption:=IntToStr(Curr);

Button7.Enabled:=true;

Button8.Enabled:=true;

Button11.Enabled:=true;

Button12.Enabled:=true;

// Curr:=Ind_1[Current];

if Current>=n then Button11.Enabled:=false;

if Current<=1 then Button12.Enabled:=false;

if Curr>=n then Button7.Enabled:=false;

if Curr<=1 then Button8.Enabled:=false;

end;

procedure TForm1.Button10Click(Sender: TObject);

begin

Current:=n;

// ShowPoint(Curr);

Curr:=Ind_1[Current];

ShowPoint({Current});

end;

procedure TForm1.Button11Click(Sender: TObject);

begin

Current:=Current+1;

// ShowPoint(Curr);

Curr:=Ind_1[Current];

ShowPoint({Current});

end;

procedure TForm1.Button12Click(Sender: TObject);

begin

Current:=Current-1;

// ShowPoint(Curr);

Curr:=Ind_1[Current];

ShowPoint({Current});

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

Close;

end;

procedure TForm1.Button2Click(Sender: TObject);

Var i: integer;

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);

for i := 1 to n do

begin

Ind[i]:= i; {Початкове визначення Ind}

Ind_1[i]:= i; {Початкове визначення Ind_1}

end;

if n>1 then Button4.Enabled:=true;

Button5.Enabled:=false;

Button6.Enabled:=false;

Button7.Enabled:=false;

Button8.Enabled:=false;

Button9.Enabled:=true;

Button10.Enabled:=true;

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 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

Ind_1[i]:=Ind_1[i]+1; Ind_1[i+1]:=Ind_1[i+1]-1;

end;

Button5.Enabled:=true;

Button6.Enabled:=true;

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

Curr:=1;

// ShowPoint(Curr);

Current:=Ind[Curr];

ShowPoint({Current});

end;

procedure TForm1.Button6Click(Sender: TObject);

begin

Curr:=n;

// ShowPoint(Curr);

Current:=Ind[Curr];

ShowPoint({Current});

end;

procedure TForm1.Button7Click(Sender: TObject);

begin

Curr:=Curr+1;

// ShowPoint(Curr);

Current:=Ind[Curr];

ShowPoint({Current});

end;

procedure TForm1.Button8Click(Sender: TObject);

begin

Curr:=Curr-1;

// ShowPoint(Curr);

Current:=Ind[Curr];

ShowPoint({Current});

end;

procedure TForm1.Button9Click(Sender: TObject);

begin

Current:=1;

// ShowPoint(Curr);

Curr:=Ind_1[Current];

ShowPoint({Current});

// ShowMessage(IntToStr(Current)+IntToStr(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.