unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, Grids, StdCtrls, jpeg;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button2: TButton;
Button3: TButton;
BitBtn2: TBitBtn;
Label4: TLabel;
Label5: TLabel;
Button4: TButton;
Label6: TLabel;
Label7: TLabel;
Image1: TImage;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
ms1=array[1..50,1..50] of real;
var
Form1: TForm1;
m,n:integer;
a,b:ms1;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit1.SetFocus;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
StringGrid1.ColCount:=n+1; //задание кол-ва столбцов и строк
StringGrid1.RowCount:=m+1;
StringGrid2.ColCount:=n+1;
StringGrid2.RowCount:=m+1;
for i:=1 to n do
begin
for j:=1 to m do
begin
StringGrid1.Cells[j,i]:=''; //очистка таблиц
StringGrid2.Cells[j,i]:='';
StringGrid1.Cells[0,i]:=IntToStr(i);
StringGrid1.Cells[j,0]:=IntToStr(j);
StringGrid2.Cells[0,i]:=IntToStr(i);
StringGrid2.Cells[j,0]:=IntToStr(j);
end;
end;
StringGrid1.SetFocus;
Label6.Caption:=('Размерность массива ' +IntToStr(m) +'*' +IntToStr(n)) //вывод в метку заданной размерности
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
for i:=1 to n do
begin
for j:=1 to m do
a[i,j]:=StrToFloat(StringGrid1.Cells[i,j]); //формирование матрицы A
end;
end;
procedure TForm1.Button4Click(Sender: TObject); //приведение формы в начальное состояние
var i,j:integer;
begin
for i:=1 to n do
for j:=1 to m do
begin
StringGrid1.Cells[i,j]:='';
StringGrid2.Cells[i,j]:='';
edit1.Text:='';
edit2.Text:='';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
amin,buf:real;
begin
amin:=a[1,1]; //изначально считаем минимальным элемент a[1,1]
for i:=1 to n do
begin
for j:=1 to m do
begin
a[i,j]:=StrToFloat(StringGrid1.Cells[i,j]);
if a[i,j]>a[i,j+1] then
begin //вычисляем минимальный элемент
buf:=a[i,j];
a[i,j]:=a[i,j+1];
a[i,j+1]:=buf; //производим обмен методом пузырька
StringGrid2.Cells[i,j]:=FloatToStr(a[i,j]); //вывод матрицы B
end;
end;
end;
end;
end.