IDENTIFICATION DIVISION.
PROGRAM-ID. TAPE-READER.
AUTHOR. Kevin Roper.
INSTALLATION. KEYHOLE HQ.
DATE-WRITTEN. 05/25/2020.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT CALCULATOR-TAPE ASSIGN TO "CALCULATOR-TAPE.DAT"
		ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD CALCULATOR-TAPE.
01 CALCULATION-RECORD.
   88 END-OF-CALC-FILE     VALUE HIGH-VALUES.
   02 F-OPERAND-A            PIC 9(8).
   02 F-OPERAND-B            PIC 9(8).
   02 F-OPERATOR             PIC A.
   02 F-ANSWER               PIC 9(16).
   02 F-ERROR-MESSAGE        PIC X(30).
   02 F-META-DATA.
       05 DATE-OF-CALCULATION.
           10 CALCULATION-YEAR     PIC 9(2).
           10 CALCULATION-MONTH    PIC 9(2).
           10 CALCULATION-DAY      PIC 9(2).

WORKING-STORAGE SECTION.
01 OPERATOR        PIC X VALUE IS "@".
01 COUNTER         PIC 999 VALUE IS 000.

PROCEDURE DIVISION.
DISPLAY "CALCULATOR TAPE"
OPEN INPUT CALCULATOR-TAPE.
    READ CALCULATOR-TAPE
         AT END SET END-OF-CALC-FILE TO TRUE
    END-READ
    PERFORM UNTIL END-OF-CALC-FILE      
       PERFORM GET-OPERATOR
       DISPLAY COUNTER SPACE "-" CALCULATION-DAY "/" CALCULATION-MONTH "/" CALCULATION-YEAR
       DISPLAY SPACE F-OPERAND-A SPACE OPERATOR SPACE F-OPERAND-B SPACE "=" SPACE F-ANSWER SPACE F-ERROR-MESSAGE
       READ CALCULATOR-TAPE
            AT END SET END-OF-CALC-FILE TO TRUE
       END-READ
       SET COUNTER UP BY 1
    END-PERFORM
    CLOSE CALCULATOR-TAPE
STOP RUN.

GET-OPERATOR.
IF F-OPERATOR="A" THEN MOVE "+" TO OPERATOR.
IF F-OPERATOR="S" THEN MOVE "-" TO OPERATOR.
IF F-OPERATOR="M" THEN MOVE "*" TO OPERATOR.
IF F-OPERATOR="D" THEN MOVE "/" TO OPERATOR.
