Mid Semester Take Home Exam
CIS12 - Introduction to COBOL Programming
Due November 13, 2001

This is an open notes, open book, take-home exam - if you have any problems see me - YOU MAY NOT DISCUSS THE EXAM QUESTIONS WITH ANYONE BUT ME! Note this exam was posted on November 5th! It is due November 13th! I take off 5 points per class day for late exams!
(For the flowcharting segments you may draw the portion by hand or if you are in the Web class and sending it by e-mail, you can use the drawing in Word or another package - it can be pretty rough - or send a scanned image - otherwise you can send it by mail - postmark must be on or before November 13th)
Note: I am not trying to trick you - typos are probably just that, typos! Please ask questions and correct any you find.
If you got programs to me by this weekend, you can excuse yourself from the midsemester - you had to complete the set that were programming assignment #1 and you had to have made a good start (about 50%) on programming assignment #2. (Note, I sent notes to those who are excused - if you have a question, email me). If you excuse yourself, then the 10% of your grade that was for the midsemester becomes part of the general grade for homework and programs. If you were excused, you can opt to take the exam or you can opt to take the exam for extra credit!
  1. Draw the flowchart segment for the following logical problem:

    If CODE-IN is equal to F and AMT is greater than 200 OR CODE-IN is equal to G and AMT is greater than 500 you want to add 1 to CT-WS.

  2. Write the COBOL IF statement for problem #1.

  3. Draw the flowchart segment for the following logical problem.

    If ANS-WS is greater than 2000 you want to perform B-300-ROUT-ONE, if ANS-WS is greater than 1000 and less than or equal to 2000 you want to perform B-310-ROUT-TWO, if ANS-WS is less than or equal to 1000 you want to perform B-320-ROUT-THREE.

  4. Write the IF statement for problem #3.

  5. Draw the flowchart segment for the following logical problem:

    If STATUS-IN is equal to S and STATE-IN is either MA or RI move the word ELIGIBLE to MSG-PR.

  6. Write the IF statement for problem #5.

  7. The PIC clause and the VALUE clause are incompatible in the following. Fix the PIC so it is consistent with the VALUE.
    05  NUM1-WS    PIC 9999         VALUE 45.12.
    05  NUM2-WS    PIC XXX          VALUE 43.2.
    05  NUM3-WS    PIC 999V99       VALUE .52458.
    05  NUM4-WS    PIC 999V999      VALUE 112834.
    05  NUM5-WS    PIC 99V9         VALUE 123.45
    05  NUM6-WS    PIC 99999        VALUE 427.12.
    
    
    
  8. The INPUT record has the following data:
    54321BLOUSE   296061200780001120004452
    
    The Data Division and the Procedure Division are shown below:
    DATA DIVISION.
    FILE SECTION.
    FD  INPUT-FILE
        DATA RECORD IS INPUT-REC.
    01  INPUT-REC.
        05  ITEM-NO       PIC X(5).
        05  ITEM-NAME     PIC X(10).
        05  AMT1          PIC 9(3).
        05  AMT2          PIC 99V99.
        05  AMT3          PIC 99V999.
        05  AMT4          PIC 999V99.
        05  AMT5          PIC 9(5)V99.
    FD  PRINT-FILE
        DATA RECORD IS PRINTZ.
    01  PRINTZ.
        05  FILLER        PIC X.
        05  ITEM-NO-PR    PIC X(5).
        05  FILLER        PIC XX.
        05  ITEM-NAME-PR  PIC X(10).
        05  FILLER        PIC XX.
        05  AMT1-PR       PIC ZZ9.
        05  FILLER        PIC XX.
        05  AMT2-PR       PIC Z9.99.
        05  FILLER        PIC XX.
        05  AMT3-PR       PIC Z9.99.
        05  FILLER        PIC XX.
        05  AMT4-PR       PIC $***.99.
        05  FILLER        PIC XX.
        05  AMT5-PR       PIC $$$,$$$.99.
        05  FILLER        PIC XX.
        05  ANS1-PR       PIC ZZ9.99.
        05  FILLER        PIC XX.
        05  ANS2-PR       PIC $***,***.99.
        05  FILLER        PIC X.
    WORKING-STORAGE SECTION.
    01  INDICATORZ.
        05  EOF-IND       PIC XXX           VALUE "NO ".
    01  WORK-AREAS.
        05  ANS1-WS       PIC 999V99        VALUE 0.
        05  ANS2-WS       PIC 9(5)V99       VALUE 0.
    PROCEDURE DIVISION.
    MAINLINE.
        PERFORM A-100-STARTUP.
        PERFORM B-100-PROCESS.
        PERFORM C-100-WRAPUP.
        STOP RUN.
    A-100-STARTUP.
        OPEN INPUT INPUT-FILE
             OUTPUT PRINT-FILE.
    B-100-PROCESS.
        READ INPUT-FILE
            AT END
                MOVE "YES" TO EOF-IND.
        PERFORM B-200-LOOP
            UNTIL EOF-IND = "YES".
    B-200-LOOP.
        MOVE SPACES TO PRINTZ.
        MOVE ITEM-NO TO ITEM-NO-PR.
        MOVE ITEM-NAME TO ITEM-NAME-PR.
        MOVE AMT1 TO AMT1-PR.
        MOVE AMT2 TO AMT2-PR.
        MOVE AMT3 TO AMT3-PR.
        MOVE AMT4 TO AMT4-PR.
        MOVE AMT5 TO AMT5-PR.
        SUBTRACT AMT3 FROM AMT4
            GIVING ANS1-WS.
        ADD AMT2 TO ANS1-WS.
        MOVE ANS1-WS TO ANS1-PR.
        ADD AMT5 TO ANS1-WS
            GIVING ANS2-WS.
        MOVE ANS2-WS TO ANS2-PR.
        WRITE PRINTZ 
            AFTER ADVANCING 1 LINES.
        READ INPUT-FILE
            AT END
               MOVE "YES" TO EOF-IND.
    C-100-WRAPUP.
        CLOSE INPUT-FILE
              PRINT-FILE.
    
    Show the output line that would result from processing the record shown at the beginning of the problem. Be very precise in showing each character on the print line (this includes accounting for spaces etc.)

  9. You want to move the message INVALID TRANSACTION to a field on the print line called MSG-PR. Write the statement to accomplish this.

  10. The program below does not have total lines. Modify the program so that you count the number of records and accumulate the total ON-HAND and print that information on a total line. You need to add all the necessary elements to the program to make this work.
    IDENTIFICATION DIVISION.
    PROGRAM-ID. NEEDTOT.
    AUTHOR. GROCER.
    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
        SELECT INVEN-FILE
            ASSIGN TO "A:\INVEN.DAT".
        SELECT PRINT-FILE
            ASSIGN TO PRINTER.
    DATA DIVISION.
    FILE SECTION.
    FD  INVEN-FILE
        DATA RECORD IS INVEN-REC.
    01  INVEN-REC.
        05  ITEM-NO      PIC XXX.
        05  ITEM-NAME    PIC X(20).
        05  ON-HAND      PIC 9(5).
        05  COST         PIC 999V99.
    FD  PRINT-FILE
        DATA RECORD IS PRINTZ.
    01  PRINTZ.
        05  FILLER       PIC X.
        05  ITEM-NO-PR   PIC XXX.
        05  FILLER       PIC X(10).
        05  ITEM-NAME-PR PIC X(20).
        05  FILLER       PIC X(10).
        05  ON-HAND-PR   PIC ZZ,ZZ9.
        05  FILLER       PIC X(10).
        05  COST-PR      PIC $ZZ9.99.
        05  FILLER       PIC X(13). 
    WORKING-STORAGE SECTION.
    01  INDZ.
        05  MORE-RECS    PIC XXX         VALUE "YES".
    01  PAGE-CONTROL.
        05  LINE-CT      PIC 99          VALUE 0.
    01  PAGE-HDR.
        05  FILLER       PIC X(32)       VALUE SPACES.
        05  FILLER       PIC X(16)
                         VALUE "INVENTORY REPORT".
        05  FILLER       PIC X(32)       VALUE SPACES.
    01  COL-HDR.
        05  FILLER       PIC X(14)  VALUE " ITEM #       ".
        05  FILLER       PIC XXXX   VALUE "NAME".
        05  FILLER       PIC X(25)  VALUE SPACES.
        05  FILLER       PIC X(7)   VALUE "ON HAND".
        05  FILLER       PIC X(10)  VALUE SPACES.
        05  FILLER       PIC X(7)   VALUE " COST  ".
        05  FILLER       PIC X(13)  VALUE SPACES.
    PROCEDURE DIVISION.
    MAINLINE.
        PERFORM A-100-STARTUP.
        PERFORM B-100-PROCESS.
        PERFORM C-100-WRAPUP.
        STOP RUN.
    A-100-STARTUP.
        OPEN INPUT INVEN-FILE
             OUTPUT PRINT-FILE.
    B-100-PROCESS.
        READ INVEN-FILE
            AT END
                MOVE "NO " TO MORE-RECS.
        PERFORM B-200-LOOP
            UNTIL MORE-RECS = "NO ".
    B-200-LOOP.
        IF LINE-CT = 0 OR LINE-CT > 55
            PERFORM B-300-HDR-ROUT.
        MOVE SPACES TO PRINTZ.
        MOVE ITEM-NO TO ITEM-NO-PR.
        MOVE ITEM-NAME TO ITEM-NAME-PR.
        MOVE ON-HAND TO ON-HAND-PR.
        MOVE COST TO COST-PR.
        WRITE PRINTZ
            AFTER ADVANCING 1 LINES.
        READ INVEN-FILE
            AT END
                MOVE "NO " TO MORE-RECS.
    B-300-HDR-ROUT.
        WRITE PRINTZ FROM PAGE-HDR
            AFTER ADVANCING PAGE.
        WRITE PRINTZ FROM COL-HDR 
            AFTER ADVANCING 2 LINES.
        MOVE SPACES TO PRINTZ.
        WRITE PRINTZ 
            AFTER ADVANCING 1 LINES.
        MOVE 4 TO LINE-CT.
    C-100-WRAPUP.
        CLOSE INVEN-FILE
              PRINT-FILE.
    

    EXTRA CREDIT

    For extra credit, include the code to figure out the average cost of your merchandise and print that average cost on a second total line.

    For extra credit explain the code that will cause the header routine to be performed.