Page 1 COMPUTER SCIENCE 255 SECOND HOUR EXAM NAME ________________________ Thursday, March 9 2:00 PM 100 pts. I. Multiple Guess (25 pts.) 1. Condition names are given the level number: a. 01 b. 77 c. 49 d. 88 e. it depends on the level 2. The unused space between physical records in a tape file is called the: a. label record b. physical record c. inter-record gap d. logical record 3. The number of buffers used for processing your file can be a. LABEL RECORDS clause b. BLOCK CONTAINS clause c. RESERVE clause d. REDEFINES clause 4. The size of a physical record is specified in the: a. LABEL RECORDS clause b. RESERVE clause c. BLOCK CONTAINS clause d. REDEFINES clause 5. The BLOCK CONTAINS clause will be found a. in the FD entry of the File Section of the Data Division b. In the SELECT statement of the input-output section of the environment division c. in the first paragraph of the Procedure Division d. any of the above e. none of the above 6. The RESERVE clause a. specifies the amount of memory needed for the program b. specifies the level of confidentiality needed by the program c. specifies the number of buffers to be used in a file d. specifies the number of bytes in a record e. none of the above 7. The RESERVE clause a. in the FD entry of the File Section of the Data Division b. In the SELECT statement of the input-output section of the environment division c. in the first paragraph of the Procedure Division d. any of the above e. none of the above 8. A single element of a table can be referenced a. using the field name and a subscript b. using the table name c. in a MOVE statement only d. by input operations only e. in arithmetic statements only 9. In order to use the SEARCH statement, the OCCURS clause in the table definition must include the: a. KEY IS phrase b. VALUE clause c. INDEXED By phrase d. all of the above 10. The SEARCH ALL statement performs: a. a binary search b. a sequential (linear) search c. bubble sort d. none of the above 11. If using the SEARCH ALL statement, the table description for the table to be searched must contain the: a. INDEXED BY phrase b. OCCURS clause c. KEY IS phrase d. all of the above 12. The internal representation of a data item may be specified by the a. REDEFINES clause b. USAGE clause c. VALUE clause d. RESERVE clause 13. A binary search of a table of size N requires (on the average): a. N/2 table accesses b. log2N table accesses c. N**2 table accesses d. 2*N table accesses 14. Suppose that we have 01 DATA-REC PIC X(20) VALUE "ABCDEFGHIJKLMNOPQRST" 01 TEST-REC REDEFINES DATA-REC. 05 FLD-A OCCURS 2 TIMES 10 FLD-B PIC X(2) 10 FLD-C PIC X(2) OCCURS 4 TIMES. What is the value of FLD-A(2)? a. ABCDEFGHIJ b. DEFGHIJKLM c. KLMNOPQRST d. none of the above 15. Suppose that we have 01 DATA-REC PIC X(20) VALUE "ABCDEFGHIJKLMNOPQRST" 01 TEST-REC REDEFINES DATA-REC. 05 FLD-A OCCURS 2 TIMES 10 FLD-B PIC X(2) 10 FLD-C PIC X(2) OCCURS 4 TIMES. What is the value of FLD-B(1)? a. DEF b. CD c. N d. AB e. none of the above 16. Suppose that we have 01 DATA-REC PIC X(20) VALUE "ABCDEFGHIJKLMNOPQRST" 01 TEST-REC REDEFINES DATA-REC. 05 FLD-A OCCURS 2 TIMES 10 FLD-B PIC X(2) 10 FLD-C PIC X(2) OCCURS 4 TIMES. What is the value of FLD-C(2,2)? a. AB b. CD c. KL d. OP e. none of the above 2. True/False Questions (15 pts.) 1. The REDEFINES clause may not be used with a level 88 item ______ 2. The smallest subscript allowed in COBOL is 0. ______ 3. Indexes may be initialized by the PERFORM VARYING statement. ______ 4. Indexes are assigned values by the MOVE verb. ______ 5. The SEARCH verb may contain only one WHEN statement. ______ 6. The OCCURS clause may not be used with a PICTURE CLAUSE. ______ 7. A sequential search of a table with 500 elements may require 500 accesses. ______ 8. A binary search of a table with 500 elements requires no more than 9 accesses. ______ 9. Perform VARYING may manipulate both indexes and subscripts. ______ 10. The SEARCH statement is used to search files. ______ 11. The default data representation technique is to store numbers as characters. ______ 12. Storing numbers in machine form helps program portability. ______ 13. A data item stored as USAGE COMP is stored as a string of characters. ______ 14. Condition names must have level number 77. ______ 15. The basic idea of Warnier-Orr and Jackson design methodologies is that the form of the data can sometimes be used to drive the design of a program to manipulate that data. ______ 16. The number of logical records in a physical record is known as the blocking factor ______ 17. The gap between physical records on a tape is known as a logical record. ______ 18. Multiple buffering refers to a technique to make aspirin more palatable. ______ 3. (10 pts.) After each operation on a file, the operating system stores a result code in a status field which can be specified by the programmer in the SELECT statement for that file. The status field is a two-byte alphanumeric field, of which the following is an example: 05 EMP-FILE-STATUS PIC XX. Status codes have the following meanings: If the status code is a "00" the operation completed normally. If the status code is a "10" the operation resulted in an END-OF-FILE condition. If the first character is a "2" then an "invalid key" condition exists, and the meaning of the second character is as follows: 2 - duplicate key condition 3 - record not found 4 - boundary condition. Write condition names to describe these codes (revising the 05 entry above), and then re-write the statement: IF EMP-FILE-STATUS = "23" THEN DISPLAY "EMPLOYEE RECORD NOT FOUND - RE-ENTER EMPLOYEE NUMBER" 4. Tables. The file "INVENTORY.DAT" contains records organized as follows: 01 INVENTORY-REC. 02 CATALOG-NO PIC X(5). 02 DESCRIPTION PIC X(20). 02 UNIT-COST PIC 999V99. 02 AMOUNT PIC 999. The file is in order by CATALOG-NO an contains exactly 1024 records. a. (10 pts.) Write a table description for a table which will be able to hold all 1024 records. We will want to use the COBOL binary search verb on this table, and so make sure that all of the necessary clauses are in place so that we can do this. b. (10 pts.) Write the code necessary to load the table from the file. c. (15 pts.) Write the code necessary to do a binary search of the table for the item with catalog number "12345", and print the item description, unit cost, and amount on hand. If the item is not in the table, print an error message. Use the COBOL binary search verb. 5. (15 pts.) A level break program. Records in the file "TIMESHEET.DAT" have the following format: 01 TIME-REC. 02 STUDENT-NUMBER PIC X(5). 02 STUDENT-NAME PIC X(20). 02 WEEK. 03 MONTH PIC X(3). 03 DAY PIC 99. 02 HOURS PIC 99. Write the PROCEDURE DIVISION entries necessary to read this file and produce, for each student, a print line with the number and name of the student, and the total hours for that student. Do not write the IDENTIFICATION, ENVIRONMENT, or DATA DIVISION entries. When you need to use something that you would specify in one of those divisions, just make up a (reasonable) name. Do not use the report writer for this problem. (additional workspace for problem #5)