Snippet

Program COBOL | Array - Matriks

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIKS.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 I PIC 9.
       77 J PIC 9.
       01 CETAK.
           02 M1 PIC Z9.
           02 M2 PIC Z9.
           02 T PIC ZZ9.
       01 PILIH.
           02 PIL PIC 9.
       01 TOTAL.
           02 TOTAL-BARIS OCCURS 2 TIMES.
           03 TM OCCURS 2 TIMES PIC 999.
       01 MAT1.
           02 BARIS1 OCCURS 2 TIMES.
           03 MATRIK1 OCCURS 2 TIMES PIC 99.
       01 MAT2.
           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.
           02 BLANK SCREEN.
       01 TANDA.
           02 LINE 3 COLUMN 16 VALUE '+' HIGHLIGHT.
           02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
       01 TANDA1.
           02 LINE 3 COLUMN 16 VALUE '-' HIGHLIGHT.
           02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
       01 TANDA2.
           02 LINE 3 COLUMN 16 VALUE '*' HIGHLIGHT.
           02 LINE 3 COLUMN 31 VALUE '=' HIGHLIGHT.
       01 MENU.
           02 LINE 2 COLUMN 30 VALUE "M A T R I K S".
           02 LINE 4 COLUMN 27 VALUE "1. INPUT.".
           02 LINE 5 COLUMN 27 VALUE "2. TAMBAH.".
           02 LINE 6 COLUMN 27 VALUE "3. KURANG.".
           02 LINE 7 COLUMN 27 VALUE "4. KALI.".
           02 LINE 8 COLUMN 27 VALUE "5. KELUAR.".
           02 LINE 10 COLUMN 27 VALUE "PILIH [1..5] : [ ]".
           02 LINE 10 COLUMN 43 PIC 9 TO PIL.

       PROCEDURE DIVISION.
       MULAI.
           DISPLAY HAPUS.
           DISPLAY MENU.
           ACCEPT MENU.
           IF PIL = 1
           PERFORM INPUT-DATA
           GO TO MULAI.
           IF PIL = 2
           PERFORM TAMBAH
           GO TO TANYA.
           IF PIL = 3
           PERFORM KURANG
           GO TO TANYA.
           IF PIL = 4
           PERFORM KALI
           GO TO TANYA.
           IF PIL = 5
           GO TO SELESAI
           ELSE
           GO TO MULAI.
       SELESAI.
           STOP RUN.

       INPUT-DATA.
           MOVE 3 TO LIN.
           DISPLAY HAPUS.
           PERFORM ISI1
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2
           COMPUTE LIN = 10.
           PERFORM ISI2
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2
           GO TO MULAI.

       ISI1.
           DISPLAY (3, 2) 'MATRIK A'.
           COMPUTE LIN = LIN + 1.
           DISPLAY (LIN, 2) '[', I, ',', J, '] = '.
           ACCEPT MATRIK1 (I, J).

       ISI2.
           DISPLAY (10, 2) 'MATRIK B'.
           COMPUTE LIN = LIN + 1.
           DISPLAY (LIN, 2) '[', I, ',', J, '] = '.
           ACCEPT MATRIK2 (I, J).

       PROSES.
           COMPUTE TM (I, J) = MATRIK1 (I, J) + MATRIK2 (I, J).

       PROSES1.
           COMPUTE TM (I, J) = MATRIK1 (I, J) - MATRIK2 (I, J).
       PROSES2.
           COMPUTE TM (I, J) = MATRIK1 (I, J) * MATRIK2 (I, J).
       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.

       TANYA.
           COMPUTE LIN = LIN + 2.
           DISPLAY(10, 5) 'ADA DATA LAGI [Y/T] ? '
           ACCEPT( , ) ISI-LAGI.
           IF LAGI GO TO MULAI.

       TAMBAH.
           DISPLAY HAPUS.
           PERFORM PROSES
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2
           DISPLAY TANDA.
           PERFORM HASIL
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2.

       KURANG.
           DISPLAY HAPUS.
           PERFORM PROSES1
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2
           DISPLAY TANDA1.
           PERFORM HASIL
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2.

       KALI.
           DISPLAY HAPUS.
           PERFORM PROSES2
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2
           DISPLAY TANDA2.
           PERFORM HASIL
           VARYING I FROM 1 BY 1 UNTIL I > 2
           AFTER J FROM 1 BY 1 UNTIL J > 2