CTP 108 - Computer Programming For Business

17th Jan, 1997

Q1. Write the COBOL PROCEDURE DIVISION statement (or set of statements) to calculate following expressions :

a)(5 pts) Given the total amount (cost+VAT); calculate the 15% VAT and net amount for a commodity.

b)(5 pts) R = i*(i-1)*(i-2)*....*2*1 (that is r=i!) R = 1. PERFORM CALC-FACTORIAL VARYING J FROM 2 BY 1 UNTIL J > I. .... CALC-FACTORIAL. COMPUTE R = R * J.

Q2.(5 pts)Trace the following COBOL code and determine what values will be displayed for WA and WB. (20 pts)
     0        1         2         3         4         5         6         7         8
            77 WA    PIC 999   VALUE 1. 
            77 WB    PIC 999   VALUE 2.
            77 WSUM  PIC 9999  VALUE ZERO.
            77 I     PIC 99    VALUE 3.
                DISPLAY WA, WB.
                STOP RUN.
                DIVIDE WA BY I GIVING WB.
                ADD WB TO WSUM.

    When I = 1 ;
        WB = WA/1 = 1/1
    When I = 2 ;
        WB = WA/2 = 1/2 = 0  because WB is declared 
                             to be an integer.
    When I = 3 ;
        WB = WA/3 = 1/3 = 0  
    Answer is WA=1; WB=0 when the code is executed.

Q3.(20 pts) Indicate whether the following statements are TRUE or FALSE. For the FALSE ones,
please explain why.
   You will not receive any grades for just a "False" mark or trival explanations. For example,
for a statement of the form "The COBOL SORT statement can only be used with sequential files";
an answer like "False, the SORT statement can be used with other types of files." Is not 
acceptable. The correct answer should be something like "False, the SORT statement can be used 
with relative files too".

a) The ORGANIZATION and ACCESS MODE clauses are optional in the SELECT statements for sequential files. False . You cannot use ACCESS MODE clause with sequential files. b) You can specify only one sort key in the SORT statement for indexed sequential files. False. You cannot use the SORT statement to sort indexed files. c) Within a program, you can access an indexed sequential file sequentially or randomly only if you open the file in UPDATE mode. False. Accessing indexed files sequentially or randomly is determined by the ACCESS MODE clause used in the SELECT statement; has nothing to do with OPEN mode. d) The REWRITE statement opens a file if it is not already opened. False. For any input/output, you must explicitly open a file using an appropriate OPEN statement. REWRITE statement will cause an error if it is executed for a closed file. e) To delete an indexed file from the disk, first you must delete all the records in it. False. Deleting records from a file does not delete the file itself. In order to delete a file from the disk, you must use the delete file command of the operating system you are using.

Q4.(25 pts) Write a FULL COBOL program to solve the following problem : Suppose you are given an indexed sequential file of purchase orders with the following record structure: THE FILE INDEXED ON "ITEM-CODE". Item-code 10 bytes alphanumeric Item Description 20 bytes alphanumeric Order Date yyyy/mm/dd format date Purchase Price 10 bytes numerical. Your program should reduce the prices of all items in this file by 10%. -------------------------- IDENTIFICATION DIVISION. .... ENVIRONMENT DIVISION. ... INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ITEMFILE ASSIGN TO DISK "........DAT" ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS ITEM-CODE. DATA DIVISION. FILE SECTION. FD ITEMFILE. 01 ITEM-REC. 02 ITEM-CODE PIC X(10). 02 FILLER PIC X(28). 02 ITEM-PRICE PIC 9(10). PROCEDURE DIVISION. MAIN. OPEN INPUT ITEMFILE. MAIN-LOOP. READ ITEMFILE AT END CLOSE ITEMFILE STOP RUN. COMPUTE ITEM-PRICE = ITEM-PRICE * 0.9 REWRITE ITEM-REC. GO TO MAIN-LOOP. --------------------------

Q5.(10 pts) Write the COBOL declaration statements to declare and initialize a table (array) which has the following values in its entries : CTP 06 CAD 12 CAA 13 EE 14 EECS 15 BBCE 123 01 DEPT-TABLE-INIT. 02 FILLER PIC X(7) VALUE "CTP 06". 02 FILLER PIC X(7) VALUE "CAD 12". 02 FILLER PIC X(7) VALUE "CAA 13". 02 FILLER PIC X(7) VALUE "EE 14". 02 FILLER PIC X(7) VALUE "EECS 15". 02 FILLER PIC X(7) VALUE "BBCE123". or 01 DEPT-TABLE-INIT. 02 FILLER PIC X(42) VALUE "CTP 06CAD 12CAA 13EE 14EECS 15BBCE123" and 01 DEPT-TABLE REDEFINES DEPT-TABLE-INIT. 02 DEPT-ENTRIES OCCURS 6 TIMES. 03 DEPT-CODE PIC XXXX. 03 DEPT-VALUE PIC 999.

Q6.(30 pts)Write a COMPLETE COBOL program to solve the following problem: You are given a sequential file with the following record structure : Car Plate Numbers 2 digit city code 3 byte letter group 3 digit number Owner name (32 bytes) Brand/Model Your program is supposed to count the number of cars registered to each city and produce a report listing these counts. (Hint : Use tables). -------------------------- IDENTIFICATION DIVISION. .... ENVIRONMENT DIVISION. ... INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CARFILE ASSIGN TO DISK "........DAT" ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD CARFILE. 01 CAR-REC. 02 PLATE. 03 CITY-CODE PIC 99. 03 FILLER PIC X(6). 02 FILLER PIC X(52). WORKING-STORAGE SECTION. 01 CAR-COUNTS. 02 COUNTS OCCURS 80 TIMES. 03 COUNT PIC 9999999. PROCEDURE DIVISION. MAIN. * INITIALIZE THE TABLE TO ALL ZEROS. PERFORM TABLE-INIT VARYING I FROM 1 BY 1 UNTIL I > 80. OPEN INPUT CARFILE. MAIN-LOOP. READ CARFILE AT END GO TO REPORT-COUNTS. IF CITY-CODE > 0 AND < 81 ADD 1 TO COUNTS(CITY-CODE) ELSE DISPLAY "INVALID CITY CODE IN PLATE" CITY-CODE. GO TO MAIN-LOOP. TABLE-INIT. MOVE ZERO TO COUNTS(I). REPORT-COUNTS. DISPLAY "City", "No.Of Cars". PERFORM DISPLAY-REPORT-LINE VARYING I FROM 1 BY 1 UNTIL I > 80. CLOSE CARFILE STOP RUN. DISPLAY-REPORT-LINE. DISPLAY I, COUNTS(I). --------------------------
Back to first page...