Senin, 15 November 2010

PROGRAM PASCAL MENU

Bahasa Pascal Program Menu untuk Penambahan,Pengurangan,Perkalian dan Transpose Matriks

program matriks;
uses wincrt;
var
a : array [0..100,0..100] of integer;
b : array [0..100,0..100] of integer;
c : array [0..10,0..10] of integer;
p,f,g,ba,ka,bb,kb,i,h,j,k,r,x,y: integer;
procedure tambah;
begin
writeln ('matriks A+B');
if (ka=kb)and(ba=bb) then
begin j:=1;
for h:=1 to ba do
begin k:=1;
for i:=1 to ka do
begin
write (' ',(a[h,i]+b[j,k]),' ');k:=k+1;
end;
writeln; j:=j+1;
end;
end; if ka<>kb then writeln('maaf.. jumlah kolom kedua matriks berbeda');
if ba<>bb then writeln('maaf.. jumlah baris kedua matriks berbeda');
end;
procedure kurang;
begin
writeln ('matriks A-B');
if (ka=kb)and(ba=bb) then
begin j:=1;
for h:=1 to ba do
begin k:=1;
for i:=1 to ka do
begin
write (' ',(a[h,i]-b[j,k]),' ');k:=k+1;
end;
writeln; j:=j+1;
end;
end; if ka<>kb then writeln('maaf.. jumlah kolom kedua matriks berbeda');
if ba<>bb then writeln('maaf.. jumlah baris kedua matriks berbeda');
end;
procedure kali;
begin
writeln ('Matriks A*B');
if ka=bb then begin
for h:=1 to ba do begin
for k:=1 to kb do begin
r:=0;
j:=1;
for i:=1 to ka do
begin
r:= r+ a[h,i]*b[j,k];
j:= j+1
end;
write (r,' ');
end;writeln;
end;
end
else begin
writeln;writeln('Maaf.. Jumlah KOLOM matriks A tidak sama dengan BARIS matriks B');end;
end;
procedure transpose;
begin
writeln ('Transpose matriks a');
for i:=1 to ka do
begin
for h:=1 to ba do
write (' ',a[h,i],' ');
writeln;
end;
writeln;
gotoxy(27,y+1);writeln ('Transpose matriks b');
y:=y+2;
for k:=1 to kb do
begin
x:=27;
for j:=1 to bb do begin
gotoxy(x,y);write (' ',b[j,k],' ');x:=x+3; end;y:=y+1;
writeln;
end;writeln;
end;
Procedure cetak;
begin
clrscr; writeln ('>>>>>>>>>> OPERASI ARITMATIKA 2 BUAH MATRIKS<<<<<<<<<< ') ; writeln;
writeln ('Data yang anda masukan adalah :');writeln;
writeln ('Matriks a');
for h:=1 to ba do
begin
for i:=1 to ka do
write (' ',a[h,i],' ');
writeln;
end;
writeln;
gotoxy (27,5);writeln ('Matriks b');
y:=6;
for j:=1 to bb do
begin
x:=27;
for k:=1 to kb do begin
gotoxy(x,y);write (' ',b[j,k],' '); x:=x+3;end; y:=y+1;
end;writeln;
end;
procedure input;
begin
writeln (' -= OPERASI ARITMATIKA 2 BUAH MATRIKS =- ') ; writeln;
write ('Masukan jumlah baris matriks A: '); readln (ba);
write ('Masukan jumlah kolom matriks A: '); readln (ka);writeln;
write ('Masukan jumlah baris matriks B: '); readln (bb);
write ('Masukan jumlah kolom matriks B: '); readln (kb);
writeln;
writeln ('Masukan komponen data Matriks A');
for h:=1 to ba do
begin
for i:=1 to ka do
begin
write ('Data ke-(',h,',',i,')= ');
readln (a[h,i]);
end;
end;
writeln;
writeln ('Masukan komponen data matriks B');
for j:=1 to bb do
begin
for k:=1 to kb do
begin
write ('Data ke-(',j,',',k,')= ');
readln (b[j,k]);
end;
end;
end;
procedure keluar;
begin
gotoxy(0,10);
writeln(' Terima kasih telah menggunakan program ini'); writeln;writeln;
write(' (^v^)The end(^v^)'); exit;
end;
procedure garis;
begin
writeln ('-------------------------------------------------------------------------------');
writeln ('===============================================================================');
end;
procedure menu;
begin
writeln;
writeln ('Menu Operasi');
writeln ('1. Penambahan Matriks');
writeln ('2. Pengurangan Matriks');
writeln ('3. Perkalian Matriks');
writeln ('4. Transpose Matriks');
writeln ('5. Input matriks yang baru');
writeln ('6. Keluar');writeln;
write ('Masukan nomor pilihan anda : '); readln (p);
if p= 1 then begin cetak; garis; tambah; garis; menu; end;
if p= 2 then begin cetak; garis; kurang; garis; menu; end;
if p= 3 then begin cetak; garis; kali; garis; menu; end;
if p= 4 then begin cetak; garis; transpose; garis; menu; end;
if p= 5 then begin clrscr; input ; cetak; garis; writeln; writeln; garis; menu; end;
if p= 6 then begin clrscr; keluar; end else begin
cetak; writeln('Maaf.. angka yang anda masukan tidak sesuai perintah');menu; end;
end;
{program Utama}
begin
input;
cetak;
garis;
writeln;writeln;
writeln;
garis;
menu;
end.

Tidak ada komentar:

Posting Komentar