Всем привет! Помогите решить задание.
Цитата:
Дана целочисленная матрица {Aij} i=1....n , j=1....m (n,m принадлежат (6....8))
В правом дополнительном столбце выводится произведение каждого столбца.
|
Взял у друга задачу где нужно найти сумму всех отрицательных чисел матрицы, она в принцепе похожа на мою, только смысл немного другой,
вот код
Код:
unit Kurs;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TMatrix = Array of array of integer;
TMinusCount = Array of integer;
TMainForm = class(TForm)
sgMatrix: TStringGrid;
gbMSettings: TGroupBox;
Label1: TLabel;
Label2: TLabel;
eRowCount: TEdit;
eColCount: TEdit;
btnGenerate: TButton;
procedure btnGenerateClick(Sender: TObject);
private
{ Private declarations }
Matrix: TMatrix;
MinusCount: TMinusCount;
ColCount: integer;
RowCount: integer;
function CheckMatrixRange(): bool;
procedure CreateMatrix();
procedure FillMatrix();
procedure VisualMatrix();
function CreateElement(): integer;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
function TMainForm.CreateElement(): integer;
var minus: integer;
res: integer;
begin
Randomize();
minus := Random(2);
Randomize();
res := Random(100);
if (minus = 1) then
begin
res := res * (-1);
end;
result := res;
end;
procedure TMainForm.CreateMatrix();
begin
SetLength(Matrix, ColCount, RowCount);
SetLength(MinusCount, RowCount);
sgMatrix.ColCount := ColCount + 2;
sgMatrix.RowCount := RowCount;
end;
procedure TMainForm.FillMatrix();
var i: integer;
j: integer;
element: integer;
minus: integer;
begin
minus := 0;
for j := 0 to RowCount - 1 do
begin
for i := 0 to ColCount - 1 do
begin
element := CreateElement();
Matrix[i,j] := element;
if element < 0 then inc(minus);
end;
MinusCount[j]:= minus;
minus := 0;
end;
end;
procedure TMainForm.VisualMatrix();
var i: integer;
j: integer;
s: string;
begin
s := '';
for j := 0 to RowCount - 1 do
begin
for i := 0 to ColCount - 1 do
begin
sgMatrix.Cells[i,j] := intToStr(Matrix[i,j]);
end;
sgMatrix.Cells[i,j] := '||';
sgMatrix.Cells[i+1,j] := intToStr(MinusCount[j]);
end;
end;
function TMainForm.CheckMatrixRange(): bool;
var good: bool;
begin
good := true;
try
ColCount := StrToInt(eColCount.Text);
RowCount := StrToInt(eRowCount.Text);
except
good := false;
end;
if ((ColCount < 5) or (RowCount < 5) or (ColCount > 8) or (RowCount > 8)) then
good := false;
result := good;
end;
procedure TMainForm.btnGenerateClick(Sender: TObject);
var good: bool;
begin
good := CheckMatrixRange;
if (good) then
begin
CreateMatrix();
FillMatrix();
VisualMatrix();
end
else
begin
MessageDlg('Не верно заданы размеры матрицы', mtError, [mbOk],0);
end;
end;
end.
Помогите решить задание или изменить под мою задачу приведенную выше. За ранее спасибо.