Midterm_Practice

advertisement
1. Application programs perform tasks required by users.
2. Interactive programs, as opposed to batch programs, process data at periodic intervals.
3. COBOL code is an example of a machine language program.
4. Object code programs are executable.
5. Several COBOL instructions should be coded on a single line.
6. A slash (/) in column 7 indicates a comment.
7. COBOL statements that must begin in Area A cannot extend into Area B.
8. Division names must begin in Area A.
9. Each sentence in the ENVIRONMENT DIVISION must end with a period.
10. A division name may appear on the same line as a section name.
11. Paragraph names may appear on the same line as statements.
12. A statement may contain several sentences.
13. The IDENTIFICATION DIVISION is always required.
14. The ENVIRONMENT DIVISION is a required entry in a COBOL program.
Page 1
15. Entries under the CONFIGURATION SECTION are coded primarily for documentation.
16. VALUE clauses used to initialize fields may be found in the FILE SECTION.
17. A file contains one or more records.
18. The WORKING-STORAGE SECTION of the DATA DIVISION describes all fields not
part of input or output but needed for processing.
19. The FILE SECTION of the DATA DIVISION is always required in a COBOL program.
20. The RECORD CONTAINS clause in the FILE SECTION is always optional.
21. An alphanumeric field may include special characters.
22. Nonnumeric literals found in VALUE clauses may span more than one coding line.
23. Paragraph-names end with periods.
24. A file must be opened before it can be processed.
25. PERFORM 200-LABEL-RTN is an example of an in-line PERFORM.
26. When a READ statement is executed, one data record is copied into primary storage.
27. COBOL 74 does not have a standard in-line PERFORM UNTIL...END-PERFORM
statement.
Page 2
28. Every PERFORM UNTIL includes a conditional test.
29. With a simple PERFORM 200-para-rtn., the named paragraph will always be executed
exactly once.
30. This form of the PERFORM statement can be used in COBOL 85:
PERFORM paragraph-name UNTIL condition.
31. A CLOSE statement will indicate if a file is to be closed as an input file or as an output
file.
32. The word FILLER is required in the DATA DIVISION for unused areas in COBOL 74.
33. The coding of modules in a hierarchical manner is called top-down programming.
34. An in-line PERFORM always ends with an END-PERFORM.
35. The logical control structure of iteration is sometimes called an IF-THEN-ELSE control
structure.
36. Iteration is also called looping.
37. MOVE instructions are found in the PROCEDURE DIVISION.
38. The receiving field of a MOVE instruction may be a literal.
39. Numeric literals should be moved to fields of the same type.
Page 3
40. ZEROS may be moved to alphanumeric fields.
41. The following is a correct COBOL statement: ADD BONUS TO 50
42. AMOUNT needs to have an initial value before the following statement is executed:
ADD BONUS REGULAR-PAY TO AMOUNT
43. AMOUNT needs to have an initial value before the following statement is executed:
ADD BONUS REGULAR-PAY GIVING AMOUNT
44. In the following statement, AMOUNT may be a report-item:
ADD BONUS REGULAR-PAY GIVING AMOUNT
45. In the following statement, BONUS may be a report-item:
ADD BONUS REGULAR-PAY GIVING AMOUNT
46. Commas must never be used when several items are added together.
47. The following statement is correct:
MULTIPLY AMT1 BY AMT2 BY AMT3 GIVING TOTAL
48. The following statement is correct: MULTIPLY AMT1 TIMES AMT2 GIVING
TOTAL
49. The following statement is correct: DIVIDE AMT1 INTO AMT2
50. The following statement is correct: DIVIDE AMT1 BY AMT2
51. The following statement is correct: DIVIDE AMT1 INTO AMT2 GIVING AMT2
Page 4
52. When a REMAINDER clause is used with a DIVIDE, the results of the original DIVIDE
operation are not changed.
53. The ROUNDED clause may be used with any arithmetic operation.
54. What is the purpose of a printer spacing chart?
_______________________________________________________________
55. An example of a run-time error is _____________________________________
56. What division of a COBOL program defines the input and output formats?
_______________________________________________________________
57. What type of error is including an ADD instruction instead of a MULTIPLY instruction?
_____________________________________________________
58. Documentation is intended for
A) those who will be working with the output of a program
B) computer operators who will run the program
C) maintenance programmers
D) all of the above
E) none of the above
59. The division in a COBOL program which describes the computer equipment that will be
used is called
A) Identification Division
D) Data Division
B) Equipment Division
E) Procedure Division
C) Environment Division
Page 5
60. Which of the following statements is NOT correct about COBOL?
A) COBOL is a standard language
B) COBOL is a business-oriented language
C) COBOL is a machine language
D) COBOL is an English-like language
E) COBOL is a user-friendly language
61. Write the IDENTIFICATION DIVISION code for this program.
62. Write the statement that will cause the paragraph 200-LABEL-RTN to be executed.
63. Write the COBOL code to read a record from this file and place the value 'NO' into the
field ARE-THERE-MORE-RECORDS' if the record cannot be read.
64. For SCOUT-FILE we have records with the following data formats:
SCOUT-NAME-IN
with 10 alphanumeric characters
1 unused character space
MINT-BOXES-IN
with 3 numeric digits
1 unused character space
SAMOA-BOXES-IN
with 3 numeric digits
Write the COBOL code for the input record description.
65. Given input file SALES-FILE and output file REPORT-FILE, where the device names
on the computer system are the drive specification and the disk file-name, write the
SELECT-ASSIGN statements. Assume you are working on a PC.
66. A GIRL-SCOUT file has the following record layout:
NAME
BOXES OF COOKIES SOLD
LAST
FIRST
MINTS
SAMOAS
1-10
12-21
25-26
28-29
Write the record description for this layout. Use group fields as indicated. Assume
COBOL 85.
Page 6
67. An inventory file has the following record layout:
Field
Positions in Record
ITEM-CODE-IN
1-5
Not used
6-7
STOCK-QUANTITY-IN
8-10
Not used
11-12
UNIT-PRICE-IN
13-15
(in whole dollars)
Write the record description for this layout. Assume COBOL 85.
Page 7
68. A PAYROLL program uses one input file, PAYROLL-FILE, and one output file,
REPORT-FILE. It has a main module and one subordinate module that processes each
employee record. You are given the following input and output record layouts:
Input Record Layout for PAYROLL-FILE
FIELD
Columns
TYPE
EMPLOYEE-NAME-IN
1 - 20
Alphanumeric
DEPARTMENT-IN
22 - 25
Alphanumeric
HOURS-WORKED-IN
27 - 28
Numeric
HOURLY-RATE-IN
30-32
Numeric (in dollars)
Output REPORT-FILE Record Layout
FIELD
EMPLOYEE-NAME-OUT
DEPARTMENT-OUT
GROSS-PAY-OUT
Columns
1 - 20
22 - 25
27 - 31
TYPE
Alphanumeric
Alphanumeric
Numeric
You are given this main module:
100-MAIN-MODULE.
OPEN INPUT PAYROLL-FILE
OUTPUT REPORT-FILE.
READ PAYROLL-FILE
AT END MOVE 'NO' TO ARE-THERE-MORE-RECORDS.
PERFORM 200-PROCESS-RTN
UNTIL ARE-THERE-MORE-RECORDS = 'NO'.
CLOSE PAYROLL-FILE
REPORT-FILE.
STOP RUN.
Write the COBOL code for 200-PROCESS-RTN.
69. A PAYROLL program uses one input file, PAYROLL-FILE, and one output file,
REPORT-FILE. It has a main module and one subordinate module that processes each
employee record. Write the PROCEDURE DIVISION code for the main module.
Assume COBOL 74.
Page 8
70. An Employee file has the following record specification:
Columns
Employee name
1-15
Alphanumeric
Hours worked
17-18
integer
Hourly rate
20-24
999V99
# Deductions
26
integer
A program produces an output file that has the following information:
Employee name
Gross pay
FICA amount Net pay
Where Gross pay = hours worked X hourly rate
FICA amount = Gross pay X .0765
Deduction amount = 10 X Deductions
Net pay = Gross pay - FICA amount - Deduction amount
Write the PROCEDURE DIVISION code to do the above calculations.
71. Write the arithmetic statements using a COMPUTE statement that will calculate the
value of RESULT and retain the values of A, B, C, D, F where
72. Write the arithmetic statements using ADD, MULTIPLY, SUBTRACT and/or DIVIDE
that will calculate the value of RESULT and retain the values of A, B, C, D, F where
73. Which of the following statements is NOT correct?
A) DISPLAY FUNCTION MIN (1 2 3 4 5)
B) COMPUTE Y = SQRT (X)
C) COMPUTE Y = FUNCTION RANDOM
D) MOVE FUNCTION MAX (A B C D E F) TO Y
E) COMPUTE Y = FUNCTION ANNUITY ( 0.10, 120)
Page 9
74. Which operation is evaluated first in the following statement?
COMPUTE Y = A ** B * (C + D) / E - F
A) A ** B B) B * C C) C + D D) D / E E) E - F
75. SPACES may be moved to numeric fields.
Page 10
Answer Key -- midterm prac 04
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
True
False
False
True
False
False
False
True
True
False
True
False
True
False
True
False
True
True
False
True
True
True
True
True
False
True
True
True
True
True
False
True
True
True
False
True
True
False
True
True
Page 11
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
False
True
False
True
False
False
False
False
True
False
True
True
True
To lay out the output
division by zero, missing input file
Data Division
logic error
D
C
C
Note that the name in PROGRAM-ID may be different.
IDENTIFICATION DIVISION.
PROGRAM-ID.
SCOUT.
62. PERFORM 200-LABEL-RTN.
63.
READ SCOUT-FILE
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS.
64.
01
SCOUT-REC
03
SCOUT-NAME-IN
PIC X(10).
03
PIC X.
03
MINT-BOXES-IN
PIC 9(3).
03
PIC X.
03
SAMOA-BOXES-IN
PIC 9(3).
65.
SELECT SALES-FILE ASSIGN TO 'C:SALES.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE ASSIGN TO 'C:REPORT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
66.
01 SCOUT-RECORD-IN.
Page 12
05
05
05
NAME-IN.
10
LAST-NAME-IN
10
10
FIRST-NAME-IN
BOXES-SOLD-IN.
10
MINTS-IN
10
10
SAMOAS-IN
PIC X(10).
PIC X.
PIC X(10).
PIC X(4).
PIC 9(2).
PIC X.
PIC 9(2).
67.
01
INVENTORY-RECORD-IN.
05
ITEM-CODE-IN
05
05
STOCK-QUANTITY-IN
05
05
UNIT-PRICE-IN
PIC X(5).
PIC X(2).
PIC 9(3).
PIC X(2).
PIC 9(3).
68.
MOVE EMPLOYEE-NAME-IN TO EMPLOYEE-NAME-OUT.
MOVE DEPARTMENT-IN TO DEPARTMENT-OUT.
MULTIPLY HOURS-IN BY HOURLY-RATE-IN GIVING GROSS-PAY-OUT.
WRITE REPORT-REC.
READ PAYROLL-FILE
AT END MOVE 'NO' TO ARE-THERE-MORE-RECORDS.
69.
100-MAIN-MODULE.
OPEN INPUT PAYROLL-FILE
OUTPUT REPORT-FILE.
READ PAYROLL-FILE
AT END MOVE 'NO' TO ARE-THERE-MORE-RECORDS.
PERFORM 200-PROCESS-RTN
UNTIL ARE-THERE-MORE-RECORDS = 'NO'.
CLOSE PAYROLL-FILE
REPORT-FILE.
STOP RUN.
70.
300-PROCESS-RTN.
COMPUTE GROSS-PAY = HOURS-WORKED * HOURLY-RATE
COMPUTE FICA-AMOUNT = GROSS-PAY * .0765
COMPUTE DEDUCTION-AMOUNT = DEDUCTION * 10
COMPUTE NET-PAY = GROSS-PAY - FICA-AMOUNT
- DEDUCTION-AMOUNT
Page 13
OR
MULTIPLY HOURS-WORKED BY HOURLY-RATE GIVING GROSS-PAY
MULTIPLY GROSS-PAY BY .0765 GIVING FICA-AMOUNT
MULTIPLY DEDUCTION BY 10 GIVIING DEDUCTION-AMOUNT
SUBTRACT FICA-AMOUNT DEDUCTION-AMOUNT
FROM GROSS-PAY GIVING NET-PAY
71. Note: There are several ways to do this.
COMPUTE RESULT = ( A ** 3 + B ) / ( C – D ) – F
72. Note: There are several ways to do this.
MULTIPLY A BY A GIVING TEMP1
MULTIPLY A BY TEMP1
ADD B TO TEMP1
SUBTRACT D FROM C GIVING TEMP2
DIVIDE TEMP2 INTO TEMP1
SUBTRACT F FROM TEMP1 GIVING RESULT
73. B
74. A
75. False
Page 14
Download