       IDENTIFICATION DIVISION.
      *=======================*
       PROGRAM-ID.   CGPRG005.
       AUTHOR.       CELSO GALLAO.
       INSTALLATION. FATEC SAO CAETANO.
       DATE-WRITTEN. 09/04/2021.
       DATE-COMPILED. 09/04/2021.
       SECURITY      NIVEL BASICO.
      *--------------------------------------------------------------*
      * DISCIPLINA PROGRAMACAO MAINFRAME
      *--------------------------------------------------------------*
      * OBJETIVO: RECEBER DADOS DA SYSIN(ACCEPT)
      *           CALCULAR A MEDIA ARITMETICA BIMESTRAL
      *--------------------------------------------------------------*
      *------------------> HISTORICO - MANUTENCAO <------------------*
      * VERSAO  MES/ANO  NR.DOC  IDENT.  DESCRICAO
      * ------  -------  ------  ------  -------------------------   *
      *  V01    FEV/2013 010001  SISTEMA MOSTRA SYSOUT
      *--------------------------------------------------------------*
       ENVIRONMENT DIVISION.
      *====================*
       CONFIGURATION SECTION.
      *---------------------*
       SPECIAL-NAMES.
           DECIMAL-POINT IS COMMA
           CURRENCY SIGN IS "R$ " WITH PICTURE SYMBOL "$"
           .
       INPUT-OUTPUT SECTION.
      *---------------------*
       DATA DIVISION.
      *=============*
       FILE SECTION.
      *------------*
       WORKING-STORAGE SECTION.
      *-----------------------*
       01  FILLER                 PIC X(35)        VALUE
           '**** INICIO DA WORKING-STORAGE ****'.

      *-----> VARIAVEIS AUXILIARES UTILIZADA NO PROCESSAMENTO
       01  WS-AREA-AUX.
           05  WS-FIM                 PIC X(01).
           05  WS-CTLIDO              PIC 9(02).
           05  WS-MEDIA               PIC 9(02)V99.
           05  WS-FEM                 PIC 9(02).
           05  WS-MASC                PIC 9(02).
           05  WS-TOT                 PIC 9(02)V99.
           05  WS-GEN                 PIC Z9,99.
           05  WS-NB                  PIC 9(02).
           05  WS-PCT                 PIC Z9,99.
           05  WS-PCT-NB              PIC Z9,99.
      *-----> ENTRADA - DADOS VIA SYSIN (NO JCL DE EXECUCAO)
       01  WS-REG-SYSIN.
           05 WS-NUMERO-IN        PIC 9(04).
           05 WS-NOME-IN          PIC X(20).
           05 WS-SEXO-IN          PIC X(01).
           05 WS-IDADE-IN         PIC 9(02).
           05 WS-CURSO-IN         PIC X(12).
           05 WS-NOTA1-IN         PIC 9(02)V99.
           05 WS-NOTA2-IN         PIC 9(02)V99.

       01  WS-REG-SYSOUT
           05 WS-NUM              PIC 9(04).
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-NOM              PIC X(20).
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-SEX              PIC X(01).
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-IDA              PIC Z9.
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-CUR              PIC X(12).
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-NT1              PIC Z9,99.
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-NT2              PIC Z9,99.
           05 FILLER              PIC X(01)        VALUE SPACES.
           05 WS-MED              PIC Z9,99.
       01  FILLER                 PIC X(35)        VALUE
           '****** FIM DA WORKING-STORAGE *****'.
      *
       PROCEDURE DIVISION.
      *==================*
      *--------------------------------------------------------------*
      *    PROCESSO PRINCIPAL
      *--------------------------------------------------------------*
       000-CGPRG005.

           PERFORM 010-INICIAR
           PERFORM 030-PROCESSAR UNTIL WS-FIM = 'S'
           PERFORM 090-TERMINAR
           STOP RUN
           .
      *--------------------------------------------------------------*
      *    PROCEDIMENTOS INICIAIS
      *--------------------------------------------------------------*
       010-INICIAR.

           DISPLAY "ATIVIDADE 5"
           DISPLAY "ANA CAROLINA GOMES DA SILVA"

           PERFORM 025-LER-SYSIN
           .
      *--------------------------------------------------------------*
      *    LEITURA DADOS DA SYSIN
      *--------------------------------------------------------------*
       025-LER-SYSIN.

           ACCEPT WS-REG-SYSIN  FROM SYSIN

           IF WS-REG-SYSIN = ALL '9'
              COMPUTE WS-GEN = WS-TOT /WS-CTLIDO
              MOVE WS-GEN TO WS-MED
              COMPUTE WS-PCT-NB = WS-NB/WS-CTLIDO*100
              MOVE WS-PCT-NB TO WS-PCT
              MOVE   'S'     TO  WS-FIM
           ELSE
              ADD 1  TO WS-CTLIDO
           END-IF
           .
      *--------------------------------------------------------------*
      *    PROCESSAR DADOS RECEBIDOS DA SYSIN ATE FIM DOS REGISTROS
      *--------------------------------------------------------------*
       030-PROCESSAR.

           COMPUTE WS-MEDIA = (WS-NOTA1-IN + WS-NOTA2-IN) / 2
           MOVE    WS-NUMERO-IN          TO  WS-NUM
           MOVE    WS-NOME-IN            TO  WS-NOM
           MOVE    WS-SEXO-IN            TO  WS-SEX
           MOVE    WS-IDADE-IN           TO  WS-IDA
           MOVE    WS-CURSO-IN           TO  WS-CUR
           MOVE    WS-NOTA1-IN           TO  WS-NT1
           MOVE    WS-NOTA2-IN           TO  WS-NT2
           MOVE    WS-MEDIA              TO  WS-MED
           DISPLAY WS-REG-SYSOUT
                IF WS-SEX = "F" THEN
                    ADD 1 TO WS-FEM
                ELSE
                    ADD 1 TO WS-MASC
                END-IF
                IF WS-MEDIA < 6 THEN
                    ADD 1 TO WS-NB
                END-IF
           PERFORM 025-LER-SYSIN
           .
      *--------------------------------------------------------------*
      *    PROCEDIMENTOS FINAIS
      *--------------------------------------------------------------*
       090-TERMINAR.

           DISPLAY ' *========================================*'
           DISPLAY ' *   TOTAIS DE CONTROLE - CGPRG005        *'
           DISPLAY ' *----------------------------------------*'
           DISPLAY ' * REGISTROS LIDOS    - SYSIN  = 'WS-CTLIDO
           DISPLAY ' * TOTAL DE MULHERES...:'WS-FEM
           DISPLAY ' * TOTAL DE HOMENS...:'WS-MASC
           DISPLAY ' * MEDIA GERAL DOS ALUNOS...:'WS-GEN
           DISPLAY ' * TOTAL DE ALUNOS COM MEDIA < 6,00...:'WS-NB
           DISPLAY ' * % DE ALUNOS COM MEDIA < 6,00...:'WS-PCT-NB
           DISPLAY ' *========================================*'
           DISPLAY ' *----------------------------------------*'
           DISPLAY ' *      TERMINO NORMAL DO CGPRG005        *'
           DISPLAY ' *----------------------------------------*'
           .
      *---------------> FIM DO PROGRAMA CGPRG005 <-------------------*
