Professional Documents
Culture Documents
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, XPMan, StdCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
GroupBox2: TGroupBox;
Button1: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
XPManifest1: TXPManifest;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
Label1: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
procedure Edit2Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
//variable-variable program//
i,j,k : integer;
data1 : array [1..10, 1..10] of integer;
data2 : array [1..10, 1..10] of integer;
hasil : array [1..10, 1..10] of integer;
implementation
{$R *.dfm}
//set pada string kolom-baris nilai default = 0//
procedure TForm1.FormCreate(Sender: TObject);
begin
Label8.Visible:=False;
StringGrid3.Visible:=False;
StringGrid2.Cells[1, 1] := '0';
StringGrid2.Cells[1, 3] := '0';
StringGrid2.Cells[1, 5] := '0';
StringGrid2.Cells[1, 7] := '0';
StringGrid2.Cells[1, 9] := '0';
StringGrid2.Cells[1, 2] := '0';
StringGrid2.Cells[1, 4] := '0';
StringGrid2.Cells[1, 6] := '0';
StringGrid2.Cells[1, 8] := '0';
StringGrid2.Cells[1, 10] := '0';
StringGrid2.Cells[2, 1] := '0';
StringGrid2.Cells[2, 3] := '0';
StringGrid2.Cells[2, 5] := '0';
StringGrid2.Cells[2, 7] := '0';
StringGrid2.Cells[2, 9] := '0';
StringGrid2.Cells[2, 2] := '0';
StringGrid2.Cells[2, 4] := '0';
StringGrid2.Cells[2, 6] := '0';
StringGrid2.Cells[2, 8] := '0';
StringGrid2.Cells[2, 10] := '0';
StringGrid2.Cells[3, 1] := '0';
StringGrid2.Cells[3, 3] := '0';
StringGrid2.Cells[3, 5] := '0';
StringGrid2.Cells[3, 7] := '0';
StringGrid2.Cells[3, 9] := '0';
StringGrid2.Cells[3, 2] := '0';
StringGrid2.Cells[3, 4] := '0';
StringGrid2.Cells[3, 6] := '0';
StringGrid2.Cells[3, 8] := '0';
StringGrid2.Cells[3, 10] := '0';
StringGrid2.Cells[4, 1] := '0';
StringGrid2.Cells[4, 3] := '0';
StringGrid2.Cells[4, 5] := '0';
StringGrid2.Cells[4, 7] := '0';
StringGrid2.Cells[4, 9] := '0';
StringGrid2.Cells[4, 2] := '0';
StringGrid2.Cells[4, 4] := '0';
StringGrid2.Cells[4, 6] := '0';
StringGrid2.Cells[4, 8] := '0';
StringGrid2.Cells[4, 10] := '0';
StringGrid2.Cells[5, 1] := '0';
StringGrid2.Cells[5, 3] := '0';
StringGrid2.Cells[5, 5] := '0';
StringGrid2.Cells[5, 7] := '0';
StringGrid2.Cells[5, 9] := '0';
StringGrid2.Cells[5, 2] := '0';
StringGrid2.Cells[5, 4] := '0';
StringGrid2.Cells[5, 6] := '0';
StringGrid2.Cells[5, 8] := '0';
StringGrid2.Cells[5, 10] := '0';
StringGrid2.Cells[6, 1] := '0';
StringGrid2.Cells[6, 3] := '0';
StringGrid2.Cells[6, 5] := '0';
StringGrid2.Cells[6, 7] := '0';
StringGrid2.Cells[6, 9] := '0';
StringGrid2.Cells[6, 2] := '0';
StringGrid2.Cells[6, 4] := '0';
StringGrid2.Cells[6, 6] := '0';
StringGrid2.Cells[6, 8] := '0';
StringGrid2.Cells[6, 10] := '0';
StringGrid2.Cells[7, 1] := '0';
StringGrid2.Cells[7, 3] := '0';
StringGrid2.Cells[7, 5] := '0';
StringGrid2.Cells[7, 7] := '0';
StringGrid2.Cells[7, 9] := '0';
StringGrid2.Cells[7, 2] := '0';
StringGrid2.Cells[7, 4] := '0';
StringGrid2.Cells[7, 6] := '0';
StringGrid2.Cells[7, 8] := '0';
StringGrid2.Cells[7, 10] :='0';
StringGrid2.Cells[9, 2] := '0';
StringGrid2.Cells[9, 4] := '0';
StringGrid2.Cells[9, 6] := '0';
StringGrid2.Cells[9, 8] := '0';
StringGrid2.Cells[9, 10] := '0';
begin
if (edit1.Text = edit3.Text) and (edit2.Text = edit4.Text) then
begin
for i := 1 to strtoint(edit1.Text) do
begin
Label8.Visible:=True;
StringGrid3.Visible:=True;
Label8.Caption := 'Hasil Penjumlahan Matrik A dan B ';
StringGrid1.Cells[0,i] := 'B' + InttoStr(i);
StringGrid2.Cells[0,i] := 'B' + InttoStr(i);
StringGrid3.Cells[0,i] := 'B' + InttoStr(i);
for j:= 1 to strtoint(edit2.Text) do
begin
StringGrid1.Cells[i,0] := 'K' + InttoStr(i);
StringGrid2.Cells[i,0] := 'K' + InttoStr(i);
StringGrid3.Cells[i,0] := 'K' + InttoStr(i);
StringGrid3.Cells[i,j] := '';
data1[i,j] := StrtoInt(StringGrid1.Cells[i,j]);
data2[i,j] := StrtoInt(StringGrid2.Cells[i,j]);
Hasil[i,j] := data1[i,j] + data2[i,j];
stringGrid3.RowCount := strtoint(edit1.Text)+1;
stringGrid3.ColCount := strtoint(edit2.Text)+1;
StringGrid3.Cells[i,j] := inttostr(Hasil[i,j]);
end;
end;
end
else
showmessage('Ukuran Matriks Tidak sama');
edit1.SetFocus;
end;
//source untuk perkalian matrik//
procedure TForm1.Button7Click(Sender: TObject);
begin
if ((edit2.Text) = (edit3.Text)) then
begin
Label8.Visible:=True;
StringGrid3.Visible:=True;
Label8.Caption := 'Hasil Perkalian Matrik A dan B ';
for i := 1 to StrtoInt(Edit1.Text) do
for j:= 1 to StrtoInt(Edit4.Text) do
begin
Hasil[i,j] := 0;
for k:= 1 to StrtoInt(Edit2.Text) do
begin
data1[i,k] := StrtoInt(StringGrid1.Cells[k,i]);
data2[k,j] := StrtoInt(StringGrid2.Cells[j,k]);
Hasil [i,j] := Hasil[i,j] + data1[i,k] * data2[k,j];
StringGrid3.RowCount := StrtoInt(edit1.Text) + 1;
StringGrid3.ColCount := StrtoInt(edit4.Text) + 1;
end;
StringGrid3.Cells[j,i] := inttostr(Hasil[i,j]);
end;
end;
end;
//source untuk Transpose matrik//
procedure TForm1.Button5Click(Sender: TObject);
begin
Label8.Visible:=True;
StringGrid3.Visible:=True;
Label8.Caption := 'Hasil Transpose Matrik A ';
stringGrid3.RowCount := strtoint(edit2.Text)+1;
stringGrid3.ColCount := strtoint(edit1.Text)+1;
for i := 1 to strtoint(edit2.Text) do
begin
for j:= 1 to strtoint(edit1.Text) do
StringGrid3.Cells[j,i] := StringGrid1.Cells[i,j];
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
Label8.Visible:=True;
StringGrid3.Visible:=True;
Label8.Caption := 'Hasil Transpose Matrik B ';
stringGrid3.RowCount := strtoint(edit4.Text)+1;
stringGrid3.ColCount := strtoint(edit3.Text)+1;
for i := 1 to strtoint(edit4.Text) do
begin
for j:= 1 to strtoint(edit3.Text) do
StringGrid3.Cells[j,i] := StringGrid2.Cells[i,j];
end;
end;
//source untuk pengurangan matrik//
procedure TForm1.Button4Click(Sender: TObject);
begin
if (edit1.Text = edit3.Text) and (edit2.Text = edit4.Text) then
begin
for i := 1 to strtoint(edit1.Text) do
begin
Label8.Visible:=True;
StringGrid3.Visible:=True;
Label8.Caption := 'Hasil Pengurangan Matrik A dan B ';
StringGrid1.Cells[0,i] := 'B' + InttoStr(i);
StringGrid2.Cells[0,i] := 'B' + InttoStr(i);
StringGrid3.Cells[0,i] := 'B' + InttoStr(i);
for j:= 1 to strtoint(edit2.Text) do
begin
StringGrid1.Cells[i,0] := 'K' + InttoStr(i);
StringGrid2.Cells[i,0] := 'K' + InttoStr(i);
StringGrid3.Cells[i,0] := 'K' + InttoStr(i);
StringGrid3.Cells[i,j] := '';
data1[i,j] := StrtoInt(StringGrid1.Cells[i,j]);
data2[i,j] := StrtoInt(StringGrid2.Cells[i,j]);
Hasil[i,j] := data1[i,j] - data2[i,j];
stringGrid3.RowCount := strtoint(edit1.Text)+1;
stringGrid3.ColCount := strtoint(edit2.Text)+1;
StringGrid3.Cells[i,j] := inttostr(Hasil[i,j]);
end;
end;
end
else
showmessage('Ukuran Matriks Tidak sama');
edit1.SetFocus;
end;
end.
Running
Penjumlahan(A+B)
Penguranagn(A-B)
Perkalian(AxB)
TransposeA
TransposeB
Penguranagn (A-B)
Perkalian(AxB)