Page 1 Computer Science 255 Second Hour Exam Name __________________________________________ Friday, Oct. 15 100 pts. 1. (15 pts.) Suppose that we have A PIC S9(5)V99 VALUE 1234.56 B PIC S9(5)V99 VALUE -1234.56 C PIC S9(5)V99 VALUE 1.23 X PIC ++,++9.99 Y PIC $**,**9.99 What would be the displayed result of the following MOVE statements (i.e., what would X and Y look like if we were to print them? Be sure to indicate any spaces by a check mark). MOVE A TO X MOVE B TO X MOVE C TO X MOVE A TO Y MOVE B TO Y MOVE C TO Y 2. (5 pts.) Suppose that we have DATE-IN PIC X(6). And that we write ACCEPT DATE-IN FROM DATE. MOVE DATE-IN TO DATE-OUT. What PICture clause would you give DATE-OUT so that today's date would come out as 10/15/93 DATE-OUT PIC _______________ 3. (10 pts.) Translate the following Pascal code to COBOL: sum := 0; for i := 1 to 5 do sum := sum + 2*i; writeln(sum) What is the number that will be printed out (be sure to translate the writeln statement to a (rough) COBOL equivalent). 4. (5 pts.) A FILE STATUS is a two-character variable defined by FILE-STATUS PIC XX. A file status of "01" means END-OF-FILE, a "22" means DUPLICATE-KEY, and a "23" means NOT-FOUND. Instead of writing statements such as "IF FILE-STATUS = 22 ..." we would like to write statements such as "IF DUPLICATE-KEY ...". Show how this could be done by completing the following. 02 FILE-STATUS PIC XX. 5. (20 pts.) The next several questions are related. Suppose first that we have an input file consisting of salespersons names and an amount of sale. The record structure for records in this file has the following format: 01 SALES-REC. 02 SP-NAME PIC X(10). 02 SALE PIC 9(5)V99. Records are in order by SP-NAME, and the file is terminated by a record with SP-NAME = ALL "Z". Suppose that we would like to list the records in this file using the COBOL report writer. a. Write the RD section for a reasonable report (problem 5 continued) b. Write the level 1,2, and 3 items for the DETAIL-LINE of the report. 6. (15 pts.) A salesperson's sales commission is based on total sales according to the following table: If TOTAL-SALES do not exceed 10,000, then the commission is 10% of the TOTAL-SALES. For TOTAL-SALES between 10,000 and 50,000, the commission is 1,000 + 20% of the amount in excess of 10,000. Otherwise, the commission is 9,000 + 35% of the amount in excess of 50,000. Suppose that TOTAL-SALES are given and write the COBOL statement to compute the salesperson's commission and place it in the variable COMMISSION. This question will be graded at least in part on efficiency. 7. (30 pts) Do either part (a) or part (b) below. Please clearly indicate which one you have done. (a) A level break problem: On this and the following page, write the procedure division entries only for a program which will read the file described in the last two problems (the sales file) and which will compute and DISPLAY for each employee that employee's total sales. Do not worry about page headers and footers (but be sure to include headers and footers for salespeople), and invent any variable names you need to use (i.e., write the procedure division entries only - not the DATA DIVISION, etc. statements). (b) A report problem. On this and the following page, write the procedure division entries only for a program which will read the file described in the last two problems (the sales file) and which will produce a report with page headers and page footers and a report footer. Again, assume that all of the DATA division entries have been specified and invent any data names you may need (see the note in part (a)). Do not use the report writer for this exercise - papers using the report writer will be assessed a maximum of 20 points for this problem (partial credit). Additional workspace for the final problem