Нужно проверить и исправить.
Дана вещественная матрица
размером NxM. Упорядочить её
строки по неубыванию суммы их
элемент.
unit Zadanie4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons;
type
TFmZadanie4 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button1: TButton;
CheckBox1: TCheckBox;
BitBtn2: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FmZadanie4: TFmZadanie4;
implementation
uses PostZad;
{$R *.dfm}
var m,n:integer;
procedure TFmZadanie4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.MainForm.ActiveMDIChild.Free;
end;
procedure TFmZadanie4.Edit1Change(Sender: TObject);
begin
if edit1.Text='' then n:=1
else n:=strToint(Edit1.Text);
StringGrid1.RowCount:=n+1;
StringGrid2.RowCount:=n+1;
end;
procedure TFmZadanie4.Edit2Change(Sender: TObject);
begin
if edit2.Text='' then n:=1
else n:=strToint(Edit2.Text);
StringGrid1.ColCount:=n+1;
StringGrid2.ColCount:=n+1;
end;
procedure TFmZadanie4.Button1Click(Sender: TObject);
var x:array [1..100, 1..100] of integer;
s:array [1..100, 1..2] of integer;
i,j,buf,min,max,a:integer;
begin
For i:=1 to n do
For j:=1 to m do
If CheckBox1.Checked=True
then
begin
x[i,j]:=StrToInt(stringgrid1.Cells[j,i]);
StringGrid1.Enabled:=true;
end
else
begin
x[i,j]:=random (11);
stringgrid1.Cells [j,i]:=FloatToStr (x[i,j]);
end;
For j:=1 to m do
begin
s[j,1]:=0; {храница сумма строк}
s[j,2]:=j; {номер строки из массива x}
for i:=1 to n do s[j,1]:=s[j,1]+x[i,j];
end;
If s[j,1]<s[min,1] then
begin
min:=s[j,2];
s[j,2]:=s[min,1];
s[min,1]:=min;
end;
For i:=1 to n do
for j:=1 to m do stringgrid2.cells[i,j]:=FloattoStr(x[j,s[i,2]]);
end;
procedure TFmZadanie4.BitBtn2Click(Sender: TObject);
begin
fmpostzad.showmodal;
FmPostZad.TabSheet4.TabVisible := true;
end;
end.
Дана вещественная матрица
размером NxM. Упорядочить её
строки по неубыванию суммы их
элемент.
unit Zadanie4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons;
type
TFmZadanie4 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button1: TButton;
CheckBox1: TCheckBox;
BitBtn2: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FmZadanie4: TFmZadanie4;
implementation
uses PostZad;
{$R *.dfm}
var m,n:integer;
procedure TFmZadanie4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.MainForm.ActiveMDIChild.Free;
end;
procedure TFmZadanie4.Edit1Change(Sender: TObject);
begin
if edit1.Text='' then n:=1
else n:=strToint(Edit1.Text);
StringGrid1.RowCount:=n+1;
StringGrid2.RowCount:=n+1;
end;
procedure TFmZadanie4.Edit2Change(Sender: TObject);
begin
if edit2.Text='' then n:=1
else n:=strToint(Edit2.Text);
StringGrid1.ColCount:=n+1;
StringGrid2.ColCount:=n+1;
end;
procedure TFmZadanie4.Button1Click(Sender: TObject);
var x:array [1..100, 1..100] of integer;
s:array [1..100, 1..2] of integer;
i,j,buf,min,max,a:integer;
begin
For i:=1 to n do
For j:=1 to m do
If CheckBox1.Checked=True
then
begin
x[i,j]:=StrToInt(stringgrid1.Cells[j,i]);
StringGrid1.Enabled:=true;
end
else
begin
x[i,j]:=random (11);
stringgrid1.Cells [j,i]:=FloatToStr (x[i,j]);
end;
For j:=1 to m do
begin
s[j,1]:=0; {храница сумма строк}
s[j,2]:=j; {номер строки из массива x}
for i:=1 to n do s[j,1]:=s[j,1]+x[i,j];
end;
If s[j,1]<s[min,1] then
begin
min:=s[j,2];
s[j,2]:=s[min,1];
s[min,1]:=min;
end;
For i:=1 to n do
for j:=1 to m do stringgrid2.cells[i,j]:=FloattoStr(x[j,s[i,2]]);
end;
procedure TFmZadanie4.BitBtn2Click(Sender: TObject);
begin
fmpostzad.showmodal;
FmPostZad.TabSheet4.TabVisible := true;
end;
end.