program matrik

17
PROGRAM MATRIK oleh Nama : Aris Hidayat NIM : 11650014 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;

Upload: arez-hidayat

Post on 11-Nov-2014

68 views

Category:

Documents


2 download

DESCRIPTION

source program menghitung matrik dengan delphi (visual programing)

TRANSCRIPT

Page 1: Program Matrik

PROGRAM MATRIK oleh

Nama : Aris HidayatNIM : 11650014

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;

Page 2: Program Matrik

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);beginLabel8.Visible:=False;StringGrid3.Visible:=False;

Page 3: Program Matrik

StringGrid1.Cells[1, 1] := '0'; StringGrid1.Cells[1, 2] := '0';StringGrid1.Cells[1, 3] := '0'; StringGrid1.Cells[1, 4] := '0';StringGrid1.Cells[1, 5] := '0'; StringGrid1.Cells[1, 6] := '0';StringGrid1.Cells[1, 7] := '0'; StringGrid1.Cells[1, 8] := '0';StringGrid1.Cells[1, 9] := '0'; StringGrid1.Cells[1, 10] := '0';

StringGrid1.Cells[2, 1] := '0'; StringGrid1.Cells[2, 2] := '0';StringGrid1.Cells[2, 3] := '0'; StringGrid1.Cells[2, 4] := '0';StringGrid1.Cells[2, 5] := '0'; StringGrid1.Cells[2, 6] := '0';StringGrid1.Cells[2, 7] := '0'; StringGrid1.Cells[2, 8] := '0';StringGrid1.Cells[2, 9] := '0'; StringGrid1.Cells[2, 10] := '0';

StringGrid1.Cells[3, 1] := '0'; StringGrid1.Cells[3, 2] := '0';StringGrid1.Cells[3, 3] := '0'; StringGrid1.Cells[3, 4] := '0';StringGrid1.Cells[3, 5] := '0'; StringGrid1.Cells[3, 6] := '0';StringGrid1.Cells[3, 7] := '0'; StringGrid1.Cells[3, 8] := '0';StringGrid1.Cells[3, 9] := '0'; StringGrid1.Cells[3, 10] := '0';

StringGrid1.Cells[4, 1] := '0'; StringGrid1.Cells[4, 2] := '0';StringGrid1.Cells[4, 3] := '0'; StringGrid1.Cells[4, 4] := '0';StringGrid1.Cells[4, 5] := '0'; StringGrid1.Cells[4, 6] := '0';StringGrid1.Cells[4, 7] := '0'; StringGrid1.Cells[4, 8] := '0';StringGrid1.Cells[4, 9] := '0'; StringGrid1.Cells[4, 10] := '0';

StringGrid1.Cells[5, 1] := '0'; StringGrid1.Cells[5, 2] := '0';StringGrid1.Cells[5, 3] := '0'; StringGrid1.Cells[5, 4] := '0';StringGrid1.Cells[5, 5] := '0'; StringGrid1.Cells[5, 6] := '0';StringGrid1.Cells[5, 7] := '0'; StringGrid1.Cells[5, 8] := '0';StringGrid1.Cells[5, 9] := '0'; StringGrid1.Cells[5, 10] := '0';

StringGrid1.Cells[6, 1] := '0'; StringGrid1.Cells[6, 2] := '0';StringGrid1.Cells[6, 3] := '0'; StringGrid1.Cells[6, 4] := '0';StringGrid1.Cells[6, 5] := '0'; StringGrid1.Cells[6, 6] := '0';StringGrid1.Cells[6, 7] := '0'; StringGrid1.Cells[6, 8] := '0';StringGrid1.Cells[6, 9] := '0'; StringGrid1.Cells[6, 10] := '0';

StringGrid1.Cells[7, 1] := '0'; StringGrid1.Cells[7, 2] := '0';StringGrid1.Cells[7, 3] := '0'; StringGrid1.Cells[7, 4] := '0';StringGrid1.Cells[7, 5] := '0'; StringGrid1.Cells[7, 6] := '0';StringGrid1.Cells[7, 7] := '0'; StringGrid1.Cells[7, 8] := '0';StringGrid1.Cells[7, 9] := '0'; StringGrid1.Cells[7, 10] :='0';

StringGrid1.Cells[8, 1] := '0'; StringGrid1.Cells[8, 2] := '0';StringGrid1.Cells[8, 3] := '0'; StringGrid1.Cells[8, 4] := '0';StringGrid1.Cells[8, 5] := '0'; StringGrid1.Cells[8, 6] := '0';

Page 4: Program Matrik

StringGrid1.Cells[8, 7] := '0'; StringGrid1.Cells[8, 8] := '0';StringGrid1.Cells[8, 9] := '0'; StringGrid1.Cells[8, 10] := '0';

StringGrid1.Cells[9, 1] := '0'; StringGrid1.Cells[9, 2] := '0';StringGrid1.Cells[9, 3] := '0'; StringGrid1.Cells[9, 4] := '0';StringGrid1.Cells[9, 5] := '0'; StringGrid1.Cells[9, 6] := '0';StringGrid1.Cells[9, 7] := '0'; StringGrid1.Cells[9, 8] := '0';StringGrid1.Cells[9, 9] := '0'; StringGrid1.Cells[9, 10] := '0';

StringGrid1.Cells[10, 1] := '0'; StringGrid1.Cells[10, 2] := '0';StringGrid1.Cells[10, 3] := '0'; StringGrid1.Cells[10, 4] := '0';StringGrid1.Cells[10, 5] := '0'; StringGrid1.Cells[10, 6] := '0';StringGrid1.Cells[10, 7] := '0'; StringGrid1.Cells[10, 8] := '0';StringGrid1.Cells[10, 9] := '0'; StringGrid1.Cells[10, 10] := '0';

StringGrid1.Cells[11, 1] := '0'; StringGrid1.Cells[11, 2] := '0';StringGrid1.Cells[11, 3] := '0'; StringGrid1.Cells[11, 4] := '0';StringGrid1.Cells[11, 5] := '0'; StringGrid1.Cells[11, 6] := '0';StringGrid1.Cells[11, 8] := '0'; StringGrid1.Cells[11, 7] := '0';StringGrid1.Cells[11, 8] := '0'; StringGrid1.Cells[11, 9] := '0';StringGrid1.Cells[11, 10] := '0';

StringGrid1.Cells[12, 1] := '0'; StringGrid1.Cells[12, 2] := '0';StringGrid1.Cells[12, 3] := '0'; StringGrid1.Cells[12, 4] := '0';StringGrid1.Cells[12, 5] := '0'; StringGrid1.Cells[12, 6] := '0';StringGrid1.Cells[12, 7] := '0'; StringGrid1.Cells[12, 8] := '0';StringGrid1.Cells[12, 9] := '0'; StringGrid1.Cells[12, 10] := '0';

StringGrid1.Cells[13, 1] := '0'; StringGrid1.Cells[13, 2] := '0';StringGrid1.Cells[13, 3] := '0'; StringGrid1.Cells[13, 4] := '0';StringGrid1.Cells[13, 5] := '0'; StringGrid1.Cells[13, 6] := '0';StringGrid1.Cells[13, 7] := '0'; StringGrid1.Cells[13, 8] := '0';StringGrid1.Cells[13, 9] := '0'; StringGrid1.Cells[13, 10] := '0';

StringGrid1.Cells[14, 1] := '0'; StringGrid1.Cells[14, 2] := '0';StringGrid1.Cells[14, 3] := '0'; StringGrid1.Cells[14, 4] := '0';StringGrid1.Cells[14, 5] := '0'; StringGrid1.Cells[14, 6] := '0';StringGrid1.Cells[14, 7] := '0'; StringGrid1.Cells[14, 8] := '0';StringGrid1.Cells[14, 9] := '0'; StringGrid1.Cells[14, 10] := '0';

StringGrid1.Cells[15, 1] := '0'; StringGrid1.Cells[15, 2] := '0';StringGrid1.Cells[15, 3] := '0'; StringGrid1.Cells[15, 4] := '0';StringGrid1.Cells[15, 5] := '0'; StringGrid1.Cells[15, 6] := '0';StringGrid1.Cells[15, 7] := '0'; StringGrid1.Cells[15, 8] := '0';StringGrid1.Cells[15, 9] := '0'; StringGrid1.Cells[15, 10] := '0';

Page 5: Program Matrik

StringGrid2.Cells[1, 1] := '0'; StringGrid2.Cells[1, 2] := '0';StringGrid2.Cells[1, 3] := '0'; StringGrid2.Cells[1, 4] := '0';StringGrid2.Cells[1, 5] := '0'; StringGrid2.Cells[1, 6] := '0';StringGrid2.Cells[1, 7] := '0'; StringGrid2.Cells[1, 8] := '0';StringGrid2.Cells[1, 9] := '0'; StringGrid2.Cells[1, 10] := '0';

StringGrid2.Cells[2, 1] := '0'; StringGrid2.Cells[2, 2] := '0';StringGrid2.Cells[2, 3] := '0'; StringGrid2.Cells[2, 4] := '0';StringGrid2.Cells[2, 5] := '0'; StringGrid2.Cells[2, 6] := '0';StringGrid2.Cells[2, 7] := '0'; StringGrid2.Cells[2, 8] := '0';StringGrid2.Cells[2, 9] := '0'; StringGrid2.Cells[2, 10] := '0';

StringGrid2.Cells[3, 1] := '0'; StringGrid2.Cells[3, 2] := '0';StringGrid2.Cells[3, 3] := '0'; StringGrid2.Cells[3, 4] := '0';StringGrid2.Cells[3, 5] := '0'; StringGrid2.Cells[3, 6] := '0';StringGrid2.Cells[3, 7] := '0'; StringGrid2.Cells[3, 8] := '0';StringGrid2.Cells[3, 9] := '0'; StringGrid2.Cells[3, 10] := '0';

StringGrid2.Cells[4, 1] := '0'; StringGrid2.Cells[4, 2] := '0';StringGrid2.Cells[4, 3] := '0'; StringGrid2.Cells[4, 4] := '0';StringGrid2.Cells[4, 5] := '0'; StringGrid2.Cells[4, 6] := '0';StringGrid2.Cells[4, 7] := '0'; StringGrid2.Cells[4, 8] := '0';StringGrid2.Cells[4, 9] := '0'; StringGrid2.Cells[4, 10] := '0';

StringGrid2.Cells[5, 1] := '0'; StringGrid2.Cells[5, 2] := '0';StringGrid2.Cells[5, 3] := '0'; StringGrid2.Cells[5, 4] := '0';StringGrid2.Cells[5, 5] := '0'; StringGrid2.Cells[5, 6] := '0';StringGrid2.Cells[5, 7] := '0'; StringGrid2.Cells[5, 8] := '0';StringGrid2.Cells[5, 9] := '0'; StringGrid2.Cells[5, 10] := '0';

StringGrid2.Cells[6, 1] := '0'; StringGrid2.Cells[6, 2] := '0';StringGrid2.Cells[6, 3] := '0'; StringGrid2.Cells[6, 4] := '0';StringGrid2.Cells[6, 5] := '0'; StringGrid2.Cells[6, 6] := '0';StringGrid2.Cells[6, 7] := '0'; StringGrid2.Cells[6, 8] := '0';StringGrid2.Cells[6, 9] := '0'; StringGrid2.Cells[6, 10] := '0';

StringGrid2.Cells[7, 1] := '0'; StringGrid2.Cells[7, 2] := '0';StringGrid2.Cells[7, 3] := '0'; StringGrid2.Cells[7, 4] := '0';StringGrid2.Cells[7, 5] := '0'; StringGrid2.Cells[7, 6] := '0';StringGrid2.Cells[7, 7] := '0'; StringGrid2.Cells[7, 8] := '0';StringGrid2.Cells[7, 9] := '0'; StringGrid2.Cells[7, 10] :='0';

StringGrid2.Cells[8, 1] := '0'; StringGrid2.Cells[8, 2] := '0';StringGrid2.Cells[8, 3] := '0'; StringGrid2.Cells[8, 4] := '0';StringGrid2.Cells[8, 5] := '0'; StringGrid2.Cells[8, 6] := '0';

Page 6: Program Matrik

StringGrid2.Cells[8, 7] := '0'; StringGrid2.Cells[8, 8] := '0';StringGrid2.Cells[8, 9] := '0'; StringGrid2.Cells[8, 10] := '0';

StringGrid2.Cells[9, 1] := '0'; StringGrid2.Cells[9, 2] := '0';StringGrid2.Cells[9, 3] := '0'; StringGrid2.Cells[9, 4] := '0';StringGrid2.Cells[9, 5] := '0'; StringGrid2.Cells[9, 6] := '0';StringGrid2.Cells[9, 7] := '0'; StringGrid2.Cells[9, 8] := '0';StringGrid2.Cells[9, 9] := '0'; StringGrid2.Cells[9, 10] := '0';

StringGrid2.Cells[10, 1] := '0'; StringGrid2.Cells[10, 2] := '0';StringGrid2.Cells[10, 3] := '0'; StringGrid2.Cells[10, 4] := '0';StringGrid2.Cells[10, 5] := '0'; StringGrid2.Cells[10, 6] := '0';StringGrid2.Cells[10, 7] := '0'; StringGrid2.Cells[10, 8] := '0';StringGrid2.Cells[10, 9] := '0'; StringGrid2.Cells[10, 10] := '0';

StringGrid2.Cells[11, 1] := '0'; StringGrid2.Cells[11, 2] := '0';StringGrid2.Cells[11, 3] := '0'; StringGrid2.Cells[11, 4] := '0';StringGrid2.Cells[11, 5] := '0'; StringGrid2.Cells[11, 6] := '0';StringGrid2.Cells[11, 8] := '0'; StringGrid2.Cells[11, 7] := '0';StringGrid2.Cells[11, 8] := '0'; StringGrid2.Cells[11, 9] := '0';StringGrid2.Cells[11, 10] := '0';

StringGrid2.Cells[12, 1] := '0'; StringGrid2.Cells[12, 2] := '0';StringGrid2.Cells[12, 3] := '0'; StringGrid2.Cells[12, 4] := '0';StringGrid2.Cells[12, 5] := '0'; StringGrid2.Cells[12, 6] := '0';StringGrid2.Cells[12, 7] := '0'; StringGrid2.Cells[12, 8] := '0';StringGrid2.Cells[12, 9] := '0'; StringGrid2.Cells[12, 10] := '0';

StringGrid2.Cells[13, 1] := '0'; StringGrid2.Cells[13, 2] := '0';StringGrid2.Cells[13, 3] := '0'; StringGrid2.Cells[13, 4] := '0';StringGrid2.Cells[13, 5] := '0'; StringGrid2.Cells[13, 6] := '0';StringGrid2.Cells[13, 7] := '0'; StringGrid2.Cells[13, 8] := '0';StringGrid2.Cells[13, 9] := '0'; StringGrid2.Cells[13, 10] := '0';

StringGrid2.Cells[14, 1] := '0'; StringGrid2.Cells[14, 2] := '0';StringGrid2.Cells[14, 3] := '0'; StringGrid2.Cells[14, 4] := '0';StringGrid2.Cells[14, 5] := '0'; StringGrid2.Cells[14, 6] := '0';StringGrid2.Cells[14, 7] := '0'; StringGrid2.Cells[14, 8] := '0';StringGrid2.Cells[14, 9] := '0'; StringGrid2.Cells[14, 10] := '0';

StringGrid2.Cells[15, 1] := '0'; StringGrid2.Cells[15, 2] := '0';StringGrid2.Cells[15, 3] := '0'; StringGrid2.Cells[15, 4] := '0';StringGrid2.Cells[15, 5] := '0'; StringGrid2.Cells[15, 6] := '0';StringGrid2.Cells[15, 7] := '0'; StringGrid2.Cells[15, 8] := '0';StringGrid2.Cells[15, 9] := '0'; StringGrid2.Cells[15, 10] := '0';end;

Page 7: Program Matrik

//Batasan jumlah Baris-Kolom Matrik//procedure TForm1.Edit2Change(Sender: TObject);beginstringGrid1.ColCount := strtoint(edit2.Text)+1;if (strtoint(edit2.Text)) > 6 thenbeginStringGrid1.DefaultColWidth := 30;StringGrid3.DefaultColWidth := 30;end;end;

procedure TForm1.Edit1Change(Sender: TObject);beginstringGrid1.RowCount := strtoint(edit1.Text)+1;if (strtoint(edit1.Text)) > 6 thenbeginStringGrid1.DefaultRowHeight := 15;StringGrid3.DefaultRowHeight := 15;end;end;

procedure TForm1.Edit3Change(Sender: TObject);beginstringGrid2.RowCount := strtoint(edit3.Text)+1;if (strtoint(edit3.Text)) > 6 thenBeginStringGrid2.DefaultRowHeight := 15;StringGrid3.DefaultRowHeight := 15;end;end;

procedure TForm1.Edit4Change(Sender: TObject);beginstringGrid2.ColCount := strtoint(edit4.Text)+1;if (strtoint(edit4.Text)) > 6 thenbeginStringGrid2.DefaultColWidth := 30;StringGrid3.DefaultColWidth := 30;end;end;

//source untuk penjumlahan matrik//procedure TForm1.Button1Click(Sender: TObject);

Page 8: Program Matrik

beginif (edit1.Text = edit3.Text) and (edit2.Text = edit4.Text) thenbeginfor i := 1 to strtoint(edit1.Text) dobeginLabel8.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) dobeginStringGrid1.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;endelseshowmessage('Ukuran Matriks Tidak sama');edit1.SetFocus;end;

//source untuk perkalian matrik//procedure TForm1.Button7Click(Sender: TObject);beginif ((edit2.Text) = (edit3.Text)) thenbeginLabel8.Visible:=True;StringGrid3.Visible:=True;Label8.Caption := 'Hasil Perkalian Matrik A dan B ';for i := 1 to StrtoInt(Edit1.Text) dofor j:= 1 to StrtoInt(Edit4.Text) dobeginHasil[i,j] := 0;for k:= 1 to StrtoInt(Edit2.Text) dobegin

Page 9: Program Matrik

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);beginLabel8.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) dobeginfor j:= 1 to strtoint(edit1.Text) doStringGrid3.Cells[j,i] := StringGrid1.Cells[i,j];end;end;

procedure TForm1.Button6Click(Sender: TObject);beginLabel8.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) dobeginfor j:= 1 to strtoint(edit3.Text) doStringGrid3.Cells[j,i] := StringGrid2.Cells[i,j];end;end;

//source untuk pengurangan matrik//procedure TForm1.Button4Click(Sender: TObject);beginif (edit1.Text = edit3.Text) and (edit2.Text = edit4.Text) then

Page 10: Program Matrik

beginfor i := 1 to strtoint(edit1.Text) dobeginLabel8.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) dobeginStringGrid1.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;endelseshowmessage('Ukuran Matriks Tidak sama');edit1.SetFocus;end;

end.

Page 11: Program Matrik

Running

Matrik A(3x3) ; B(3x3)

Page 12: Program Matrik

Penjumlahan(A+B)

Penguranagn(A-B)

Page 13: Program Matrik

Perkalian(AxB)

TransposeA

Page 14: Program Matrik

TransposeB

Matrik A(2x3) ; B(3x3)Penjumlahan(A+B)

Penguranagn (A-B)

Page 15: Program Matrik

Perkalian(AxB)