Program Matrik dengan Delphi

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, Grids, XPMan, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    BitBtn1: TBitBtn;
    XPManifest1: TXPManifest;
    BitBtn3: TBitBtn;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    StringGrid2: TStringGrid;
    StringGrid3: TStringGrid;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure LabeledEdit1Change(Sender: TObject);
    procedure LabeledEdit2Change(Sender: TObject);
    procedure LabeledEdit3Change(Sender: TObject);
    procedure LabeledEdit4Change(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  matrik1: array [0..100,0..100] of integer;
  matrik2: array [0..100,0..100] of integer;
  Hasil: array [0..100,0..100] of integer;
  x,y,z:integer;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
for y:=0 to StrToInt(LabeledEdit1.Text)-1 do
  begin
    for x:=0 to StrToInt(LabeledEdit2.Text)-1 do
    begin
      StringGrid1.Cells[x,y]:=InputBox('Masukkan Nilai Baris '+IntToStr(y+1)+' Dan Kolom '+IntToStr(x+1),'Nilai :','0');
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
for y:=0 to StrToInt(LabeledEdit3.Text)-1 do
  begin
    for x:=0 to StrToInt(LabeledEdit4.Text)-1 do
    begin
      StringGrid2.Cells[x,y]:=InputBox('Masukkan Nilai Baris '+IntToStr(y+1)+' Dan Kolom '+IntToStr(x+1),'Nilai :','0');
    end;
  end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if (LabeledEdit1.Text=LabeledEdit3.Text) and (LabeledEdit2.Text=LabeledEdit4.Text) then
  begin
    for x:=0 to StrToInt(LabeledEdit1.Text)-1 do
      begin
        for y:=0 to StrToInt(LabeledEdit2.Text)-1 do
          begin
            matrik1[x,y]:=StrtoInt(StringGrid1.Cells[x,y]);
            matrik2[x,y]:=StrtoInt(StringGrid2.Cells[x,y]);
            Hasil[x,y]:=matrik1[x,y]+matrik2[x,y];
            StringGrid3.Cells[x,y]:=inttostr(Hasil[x,y]);
          end;
      end;
  end
  else
    begin
      ShowMessage('Ordo Matrik Tidak Sama.!');
    end;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  if (LabeledEdit2.Text=LabeledEdit3.Text) then
    begin
      for x:=0 to StrToInt(LabeledEdit1.Text)-1 do
        begin
          for y:=0 to StrToInt(LabeledEdit4.Text)-1 do
            begin
              for z:=0 to StrToInt(LabeledEdit4.Text)-1 do
                begin
                  matrik1[x,z]:=StrtoInt(StringGrid1.Cells[z,x]);
                  matrik2[z,y]:=StrtoInt(StringGrid2.Cells[y,z]);
                  Hasil[x,y]:=Hasil[x,y]+matrik1[x,z]*matrik2[z,y];
                end;
              StringGrid3.Cells[y,x]:=inttostr(Hasil[x,y]);
            end;
        end;
    end
  else
    begin
      ShowMessage('Baris Matrik 1 Dan Matrik 2 Tidak Sama.!');
    end;
end;
procedure TForm1.LabeledEdit1Change(Sender: TObject);
begin
  StringGrid1.RowCount:=StrToInt(LabeledEdit1.Text);
end;

procedure TForm1.LabeledEdit2Change(Sender: TObject);
begin
  StringGrid1.ColCount:=StrToInt(LabeledEdit2.Text);
end;

procedure TForm1.LabeledEdit3Change(Sender: TObject);
begin
  StringGrid2.RowCount:=StrToInt(LabeledEdit3.Text);
  StringGrid3.RowCount:=StrToInt(LabeledEdit3.Text);
end;

procedure TForm1.LabeledEdit4Change(Sender: TObject);
begin
  StringGrid2.ColCount:=StrToInt(LabeledEdit4.Text);
  StringGrid3.ColCount:=StrToInt(LabeledEdit4.Text);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

end.

Komentar

  1. Thanks banget gan sangat membantu tugas saya:D
    farhan2995.blogspot.com

    BalasHapus

Posting Komentar

Postingan Populer