Program Matrix
CONST N<-- 100 ;
( ------------- DEFINISI MATRIKS--------------- )
TYPE Matrix : < array [ 1 ..N ] [ 1 ..N ] of integer>
{ ------------- DEFINISI METHOD--------------------- )
#Operasi Relasional
Function isSejenis( Input a, b : Matrix) --> boolean
{ Apakah 2 matrix tersebut sejenis, digunakan dalam penjumlahan dan pengurangan matrix}
Function isDikali( input a, b : Matrix) --> boolean
{ Apakah 2 matrix tersebut sudah sesuai pada aturan perkalian}
#Operasi Aritmatika
Procedure penjumlahan( Input a, b : Matrix, Output c: Matrix)
{ menjumlahkan 2 buah matrix, dan mengembalikan 1 variabel yang telah dijumlahkan }
Procedure pengurangan( Input a, b : Matrix, Output c: Matrix)
{ menjumlahkan 2 buah matrix, dan mengembalikan 1 variabel yang telah dikurangi }
Procedure perkalian( Input a, b : Matrix, Output c : Matrix)
{ Mengalikan 2 buah matrix yang diinput, dan mengembalikan hasilnya}
#Operasi Lain terhadap Type
Function lengthKolom( Input a, b : Matrix) --> integer, integer;
{ menghitung panjang kolom dari sebuah array matriks}
Function lengthBaris( Input a, b : Matrix) --> integer, integer;
{ menghitung panjang baris dari sebuah array matriks}
Procedure search( Input a : integer, Output i: integer)
{ mencari suatu bilangan dalam matriks bilangan, dan mengembalikan hasilnya dalam bentuk indeks array matriks}
#Operasi I/O
Procedure init( Input/ Output a, b : Matrix)
{ menginisialisasi baris, kolom sebuah matriks)
Kamus
a, b : Matrix;
i, j, Pil : integer;
Algoritma
output( "Selamat datang di program ADT Kami " ) ;
output( "1.Penjumlahan Matriks" ) ;
output( "2.Perkalian Matriks" ) ;
output( "3.Refleksi Matriks" ) ;
output( "4.Pengurangan Matriks" ) ;
output( "5.Exit" ) ;
output( "Silahkan memasukkan Pilihan : " ) ; input( Pil) ;
case pil of
1 : init( a, b) ;
penjumlahan( a, b) ;
2 : init( a, b) ;
perkalian( a, b) ;
3 : init( a, b) ;
penjumlahan( a, b) ;
4 : init( a, b) ;
pengurangan( a, b) ;
5 : output( "Terimakasih" ) ;
End.
Procedure init ( Input/ Output a, b : Matrix)
Kamus
i, j, b, k : integer;
Algoritma
Begin
for i<-- 1 to N do
for j<-- 1 to N do
begin
a[ i] [ j] <-- 0 ; b[ i] [ j] <-- 0 ;
end
//replacing zero value
input( b) ; input( k) ;
for i<-- 1 to baris do
for j<-- 1 to kolom do
{
input( a[ i] [ j] ) ;
}
input( b) ; input( k) ;
for i<-- 1 to baris do
for j<-- 1 to kolom do
{
input( b[ i] [ j] ) ;
}
End
Function lengthKolom( Input a : Matrix) --> integer
Kamus
i, j : integer;
Algoritma
Begin
while ( ( ( a[ i] [ j] ) or ( b[ i] [ j] ) ) <> 0 ) //asumsi array matriks tidak ada input bilangan 0
begin
lengthKolom <-- lengthKolom+ 1 ;
i<-- i+ 1 ;
j<-- j+ 1 ;
end
return lengthKolom;
End
Function lengthBaris( Input a : Matrix) --> integer
Kamus
i, j : integer;
Algoritma
while ( ( ( a[ i] [ j] ) or ( b[ i] [ j] ) ) <> 0 ) //asumsi array matriks tidak ada input bilangan 0
begin
lengthBaris <-- lengthBaris+ 1 ;
i<-- i+ 1 ;
j<-- j+ 1 ;
end
return lengthKolom;
End
Procedure penjumlahan ( Input a : Matrix, Output c : Matrix)
Kamus
i, j : integer;
Algoritma
if isSejenis then
begin
for i<-- 1 to lengthBaris( a) do
for j<-- 1 to lengthKolom( a) do
begin
c[ i] [ j] <-- a[ i] [ j] + b[ i] [ j] ;
end
end
else
output( "Matriks tidak sejenis" ) ;
End
Procedure pengurangan ( Input a : Matrix, Output c : Matrix)
Kamus
i, j : integer;
Algoritma
if isSejenis then
begin
for i<-- 1 to lengthBaris( a) do
for j<-- 1 to lengthKolom( a) do
begin
c[ i] [ j] <-- a[ i] [ j] - b[ i] [ j] ;
end
end
else
output( "Matriks tidak sejenis" ) ;
End
Procedure search( Input a : integer, m: Matrix, Output b : integer)
Kamus
i, j : integer;
flag : boolean;
Algoritma
flag <-- false ;
for i:<-- 1 to lengthBaris( m) do
for j:<-- 1 to length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