unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ExtCtrls, About, StdCtrls, Unit3;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Mass: TMenuItem;
    Work: TMenuItem;
    About: TMenuItem;
    Create: TMenuItem;
    Open: TMenuItem;
    Save: TMenuItem;
    N1: TMenuItem;
    Exit: TMenuItem;
    Search: TMenuItem;
    FindMax: TMenuItem;
    Convert: TMenuItem;
    Sort: TMenuItem;
    OpenDialog: TOpenDialog;
    SaveDialog: TSaveDialog;
    Memo1: TMemo;
    MaxVal: TEdit;
    MinVal: TEdit;
    LabelMax: TLabel;
    LabelMin: TLabel;
    Label1: TLabel;
    FindMin: TMenuItem;
    Memo2: TMemo;
    Label2: TLabel;
    Memo3: TMemo;
    Label3: TLabel;
    Label4: TLabel;
    procedure ExitClick(Sender: TObject);
    procedure OpenClick(Sender: TObject);
    procedure SaveClick(Sender: TObject);
    procedure AboutClick(Sender: TObject);
    procedure CreateClick(Sender: TObject);
    procedure FindMinClick(Sender: TObject);
    procedure FindMaxClick(Sender: TObject);
    procedure SortClick(Sender: TObject);
    procedure ConvertClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  AboutBox:TAboutBox;
procedure Init;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.ExitClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.OpenClick(Sender: TObject);
var f:File of integer;
    s1,s2:string;
begin
     count:=0;
     If OpenDialog.Execute then
     begin AssignFile(f,OpenDialog.FileName);
       try Reset(f);Init();
         try
           Memo3.Clear;Label3.Visible:=true;
           Memo3.Visible:=True;
           while not eof(f) do
           begin
            Count:=Count+1;
            Read(f,mas[Count,1],mas[Count,2]);
            str(mas[Count,1],s1);
            str(mas[Count,2],s2);
            Memo3.Text:=Memo3.Text+'('+s1+', '+s2+')';
           end;
         finally
            CloseFile(f);
         end;
       except
        on EInOutError do
           MessageDlg('Îøèáêà îòêðûòèÿ ôàéëà',mtError,[mbOk],0);
        end;
     end;
end;

procedure TForm1.SaveClick(Sender: TObject);
var f:File of Integer;
    i:integer;
begin
     SaveDialog.Execute;
     AssignFile(f,SaveDialog.FileName);
     try
        Rewrite(f);
        try
           For i:=1 to Count do Write(f,mas[i,1],mas[i,2]);
        finally
               CloseFile(f);
        end;
        except
        on EInOutError do
           MessageDlg('Îøèáêà çàïèñè ôàéëà',mtError,[mbOk],0);
        end;

end;

procedure TForm1.AboutClick(Sender: TObject);
begin
     ShowAboutBox;
end;

procedure TForm1.CreateClick(Sender: TObject);
begin
     Form2.visible:=true;
     Init();
end;
procedure Init;
var i:Integer;
begin
     For i:=1 to 100 do
     begin Mas[i,1]:=0; Mas[i,2]:=0;
           Way[i]:=0
     end;
     Count:=0;
end;
procedure TForm1.FindMinClick(Sender: TObject);
var i:integer;
    temp:real;
    s:string;
begin
     temp:=way[1];
     For i:=2 to Count do
         if temp>way[i] then temp:=way[i];
     str(temp:2:2,s);
     MinVal.Text:=S;
     MinVal.Visible:=true;
     LabelMin.Visible:=true;
end;

procedure TForm1.FindMaxClick(Sender: TObject);
var i:integer;
    temp:real;
    s:string;
begin
     temp:=way[1];
     For i:=2 to Count do
         if temp<way[i] then temp:=way[i];
     str(temp:2:2,s);
     MaxVal.Text:=S;
     MaxVal.Visible:=true;
     LabelMax.Visible:=true;
end;

procedure TForm1.SortClick(Sender: TObject);
var i,j:integer;
    temp:real;
    s:string;
begin
     Form3.ProgressBar.Step:=round(100/Count);
     for j:=1 to Count do
     begin
         for i:=1 to Count-1 do
            if way[i]>way[i+1] then
            begin temp:=way[i]; way[i]:=way[i+1]; way[i+1]:=temp end;
         Form3.Visible:=true;
         Form3.ProgressBar.StepIt;
     end;
     Form3.visible:=false;
     Memo2.Clear;
     Memo2.visible:=True;
     Label2.visible:=true;
     for i:=1 to Count do
     begin
         str(Way[i]:2:2,s);
         Memo2.Text:=Memo2.Text+s+', ';
     end;

end;

procedure TForm1.ConvertClick(Sender: TObject);
var i:integer;
    s:string;
begin
     Memo1.Clear;
     Memo1.Visible:=true;
     Label1.Visible:=true;
     for i:=1 to Count do
     begin
          Way[i]:=Sqrt(Sqr(mas[i,1])+Sqr(mas[i,2]));
          str(Way[i]:2:2,s);
          Memo1.Text:=Memo1.Text+s+', ';
     end;

end;

end.
