Sabtu, 01 Desember 2012
CONTOH PROGRAM MATRIKS PADA COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. MATRIKS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC 9.
77 I PIC 99.
77 J PIC 99.
01 CETAK.
02 M1 PIC Z9.
02 M2 PIC Z9.
02 T PIC Z9.
01 TOTAL.
02 TOTAL-BARIS OCCURS 2 TIMES.
03 TM OCCURS 2 TIMES PIC 999.
01 DATA1.
02 BARIS1 OCCURS 2 TIMES.
03 MATRIK1 OCCURS 2 TIMES PIC 99.
01 DATA2.
02 BARIS2 OCCURS 2 TIMES.
03 MATRIK2 OCCURS 2 TIMES PIC 99.
01 ISI-LAGI PIC X.
88 LAGI VALUE 'Y' , 'y'.
88 TIDAK VALUE 'T' , 't'.
SCREEN SECTION.
01 HAPUS-LAYAR.
02 BLANK SCREEN.
01 TAMBAH.
02 LINE 3 COLUMN 16 VALUE '+' HIGHLIGHT.
02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
01 KURANG.
02 LINE 3 COLUMN 16 VALUE '-' HIGHLIGHT.
02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
01 KALI.
02 LINE 3 COLUMN 16 VALUE '*' HIGHLIGHT.
02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
PROCEDURE DIVISION.
MULAI.
DISPLAY HAPUS-LAYAR.
DISPLAY '=====MENU MATRIKS====='.
DISPLAY '1.PERTAMBAHAN'.
DISPLAY '2.PENGURANGAN'.
DISPLAY '3.PERKALIAN'.
DISPLAY '4.EXIT'.
DISPLAY 'MASUKKAN ANGKA [1-4] :'.
ACCEPT A.
IF A = 4 GO TO SELESAI.
REDI.
MOVE 3 TO LIN.
DISPLAY HAPUS-LAYAR.
PERFORM CARA1
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
COMPUTE LIN = 10.
PERFORM CARA2
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
IF A = 1 GO TO ASU.
IF A = 2 GO TO MINUS.
IF A = 3 GO TO BINTANG.
ASU.
PERFORM PROSESPLUS
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY HAPUS-LAYAR.
DISPLAY TAMBAH.
PERFORM HASIL
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY ' '.
DISPLAY 'TAMBAH LAGI [Y/T] :'.
ACCEPT ISI-LAGI.
IF LAGI GO TO MULAI.
IF TIDAK GO TO SELESAI.
MINUS.
PERFORM PROSESMINUS
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY HAPUS-LAYAR.
DISPLAY KURANG.
PERFORM HASIL
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY ' '.
DISPLAY 'KURANG LAGI [Y/T] :'.
ACCEPT ISI-LAGI.
IF LAGI GO TO MULAI.
IF TIDAK GO TO SELESAI.
BINTANG.
PERFORM PROSESKA
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY HAPUS-LAYAR.
DISPLAY KALI.
PERFORM HASIL
VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2
DISPLAY ' '.
DISPLAY 'KALI LAGI [Y/T] :'.
ACCEPT ISI-LAGI.
IF LAGI GO TO MULAI.
IF TIDAK GO TO SELESAI.
CARA1.
DISPLAY (3, 2) 'MATRIK 1'.
COMPUTE LIN = LIN + 1.
DISPLAY (LIN, 2) 'ELEMEN [', I, ', ', J, '] = '.
ACCEPT MATRIK1 (I, J).
CARA2.
DISPLAY (10, 2) 'MATRIK 2'.
COMPUTE LIN = LIN + 1.
DISPLAY (LIN, 2) 'ELEMEN [', I, ', ', J, '] = '.
ACCEPT MATRIK2 (I, J).
PROSESPLUS.
COMPUTE TM (I, J) = MATRIK1 (I, J) + MATRIK2 (I, J).
PROSESMINUS.
COMPUTE TM (I, J) = MATRIK1 (I, J) - MATRIK2 (I, J).
PROSESKA.
COMPUTE TM ( 1 , 1 ) = MATRIK1 ( 1 , 1 ) * MATRIK2 ( 1 , 1 )
+ MATRIK1 ( 1 , 2 ) * MATRIK2 ( 2 , 1 ).
COMPUTE TM ( 1 , 2 ) = MATRIK1 ( 1 , 1 ) * MATRIK2 ( 1 , 2 )
+ MATRIK1 ( 1 , 2 ) * MATRIK2 ( 2 , 2 ).
COMPUTE TM ( 2 , 1 ) = MATRIK1 ( 2 , 1 ) * MATRIK2 ( 1 , 1 )
+ MATRIK1 ( 2 , 2 ) * MATRIK2 ( 2 , 1 ).
COMPUTE TM ( 2 , 2 ) = MATRIK1 ( 2 , 1 ) * MATRIK2 ( 1 , 2 )
+ MATRIK1 ( 2 , 2 ) * MATRIK2 ( 2 , 2 ).
HASIL.
MOVE I TO LIN.
MOVE J TO COL.
MOVE MATRIK1 (I, J) TO M1.
MOVE MATRIK2 (I, J) TO M2.
MOVE TM (I, J) TO T.
COMPUTE LIN = LIN * 2.
COMPUTE COL = COL * 4.
DISPLAY (LIN, COL + 1) M1.
DISPLAY (LIN, COL + 16) M2.
DISPLAY (LIN, COL + 31) T.
SELESAI.
DISPLAY 'MAACIH KAKAK..'.
STOP RUN.
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar