Quiz — Chapter 8: Paragraph and Section Design
Multiple Choice
1. The IPT pattern stands for:
a) Input-Process-Transfer b) Initialize-Process-Terminate c) Iterate-Parse-Transform d) Import-Prepare-Transmit
2. Which paragraph name best follows the verb-noun convention?
a) PARA-1
b) ACCOUNT-DATA
c) 2100-VALIDATE-ACCOUNT
d) DO-STUFF
3. What happens when you PERFORM a section?
a) Only the first paragraph in the section is executed b) All paragraphs within the section are executed in sequence c) A random paragraph within the section is executed d) Only the section header is executed
4. In hierarchical numbering, paragraph 2110 would typically be:
a) A main-level paragraph b) A sub-step of paragraph 2100 c) An error handling paragraph d) An initialization paragraph
5. A paragraph with HIGH cohesion:
a) Contains many different types of operations b) Has all statements contributing to a single, well-defined purpose c) PERFORMs many other paragraphs d) Contains at least 50 lines
6. Which is the most widely accepted use of GO TO in modern COBOL?
a) Jumping backward to create loops b) Jumping to an exit paragraph within a PERFORM THRU range c) Jumping between unrelated paragraphs d) GO TO is never acceptable
7. According to Miller's Rule of 7 (±2), a paragraph should PERFORM no more than approximately:
a) 3 subordinate paragraphs b) 7 subordinate paragraphs c) 15 subordinate paragraphs d) There is no recommended limit
8. What is the purpose of the EXIT statement in an exit paragraph?
a) It terminates the program b) It returns to the calling PERFORM c) It is a no-op that serves as a target for GO TO and a THRU range endpoint d) It exits the current loop
9. Two paragraphs are TIGHTLY COUPLED when:
a) They are adjacent in the source code b) One depends on the internal implementation details of the other c) They are both PERFORMed by the same parent paragraph d) They both modify the same file
10. The structured programming theorem (Bohm-Jacopini) proves that any algorithm can be expressed using:
a) Sequence, selection, and recursion b) Sequence, selection, and iteration c) Loops, jumps, and subroutines d) IF, GO TO, and PERFORM
True or False
11. A section in the PROCEDURE DIVISION can contain zero paragraphs.
12. The verb-noun naming convention means paragraphs should be named with an action verb followed by the object of that action.
13. A paragraph that can be described as "validates the account AND calculates interest AND writes the report line" has high cohesion.
14. 88-level condition names help reduce coupling between paragraphs by creating semantic contracts.
15. The EXIT statement performs a meaningful operation — it frees resources allocated by the paragraph.
Short Answer
16. Explain why "self-documenting code" does not mean "code with no comments." What role do comments still play in a well-named COBOL program?
17. A colleague argues: "Paragraph structure doesn't matter — the compiler produces the same machine code regardless of how many paragraphs you have." Why is this argument incorrect from a software engineering perspective?
18. Given the following main paragraph, identify at least two structural problems and suggest corrections:
1000-MAIN.
OPEN INPUT CUST-FILE OUTPUT RPT-FILE.
MOVE 0 TO WS-COUNT.
READ CUST-FILE AT END MOVE 'Y' TO WS-EOF.
PERFORM 2000-PROCESS UNTIL WS-EOF = 'Y'.
DISPLAY 'TOTAL: ' WS-COUNT.
CLOSE CUST-FILE RPT-FILE.
STOP RUN.
19. Describe the difference between using sections for program organization versus using only paragraphs with hierarchical numbering. Under what circumstances would you choose one approach over the other?
20. Write a paragraph named 2200-CALCULATE-SHIPPING-COST that demonstrates all of the following principles: verb-noun naming, use of 88-level condition names, EVALUATE statement, single responsibility, and a maximum of 20 lines.
Answer Key
1. b) Initialize-Process-Terminate — the standard structure for batch COBOL programs.
2. c) 2100-VALIDATE-ACCOUNT — has a hierarchical number, a verb (VALIDATE), and a noun (ACCOUNT).
3. b) All paragraphs within the section are executed in sequence.
4. b) A sub-step of paragraph 2100. The numbering 2110 indicates it is a detail-level paragraph within the 2100 group.
5. b) Has all statements contributing to a single, well-defined purpose.
6. b) Jumping to an exit paragraph within a PERFORM THRU range — the guard clause / early exit pattern.
7. b) 7 subordinate paragraphs. Miller's research shows humans can hold approximately 7 items in working memory.
8. c) It is a no-op that serves as a target for GO TO and a THRU range endpoint. EXIT does nothing itself.
9. b) One depends on the internal implementation details of the other — e.g., knowing that flag value 'A' means valid.
10. b) Sequence, selection, and iteration — the three fundamental control structures of structured programming.
11. False. A section must contain at least one paragraph (even if it is just an EXIT paragraph).
12. True. Examples: VALIDATE-ACCOUNT, CALCULATE-INTEREST, WRITE-REPORT.
13. False. The use of "AND" connecting three unrelated operations indicates LOW cohesion. Each operation should be a separate paragraph.
14. True. 88-levels create a semantic interface (VALIDATION-PASSED) rather than requiring knowledge of internal values ('Y', 'P', etc.).
15. False. EXIT is a no-op — it performs no operation. It simply provides a named location in the program.
16. Self-documenting code means the names and structure communicate the what. Comments should still explain the why — business context, regulatory requirements, non-obvious design decisions, and references to external requirements. Example: code that uses IF CLM-AMOUNT > 10000 needs no comment about what it does (checks if amount exceeds 10,000), but may need a comment explaining why: "Per CMS regulation 42 CFR 405.1835, claims over $10,000 require manual review."
17. Programs are read and modified by humans far more often than they are compiled. Paragraph structure affects: (1) readability — how quickly a maintenance programmer can understand the code; (2) testability — whether individual units of logic can be tested in isolation; (3) modifiability — whether a change can be made in one place without cascading effects; (4) bug density — well-structured programs have fewer bugs per line of code. The compiler may not care, but the total cost of ownership over the program's 30-year lifespan depends enormously on structure.
18. Problems: (1) 1000-MAIN mixes multiple responsibilities: file operations, initialization, processing, and reporting are all in one paragraph rather than delegated to sub-paragraphs. (2) No 88-level condition name for end-of-file — uses raw value comparison WS-EOF = 'Y'. (3) File OPEN and CLOSE should be in separate paragraphs for clarity and single responsibility. (4) No error handling for file operations (should check FILE STATUS). Corrected:
1000-MAIN.
PERFORM 1100-INITIALIZE
PERFORM 1200-OPEN-FILES
PERFORM 2100-READ-CUSTOMER
PERFORM 2000-PROCESS-CUSTOMER
UNTIL END-OF-FILE
PERFORM 1300-DISPLAY-TOTALS
PERFORM 1400-CLOSE-FILES
STOP RUN.
19. Sections provide an explicit grouping mechanism — PERFORMing a section executes all its paragraphs. Hierarchical numbering provides implicit grouping through naming conventions (all 21xx paragraphs belong to the 2100 group). Sections are preferred in very large programs (>2000 lines) where the explicit grouping aids navigation, when DECLARATIVES are needed, or when shop standards require them. Paragraph-only design is simpler, avoids section-scoping complexities, and is sufficient for most programs under 2000 lines.
20.
2200-CALCULATE-SHIPPING-COST.
EVALUATE TRUE ALSO TRUE
WHEN ZONE-DOMESTIC ALSO PKG-SMALL
MOVE 5.99 TO WS-SHIP-COST
WHEN ZONE-DOMESTIC ALSO PKG-MEDIUM
MOVE 9.99 TO WS-SHIP-COST
WHEN ZONE-DOMESTIC ALSO PKG-LARGE
MOVE 14.99 TO WS-SHIP-COST
WHEN ZONE-INTERNATIONAL ALSO PKG-SMALL
MOVE 15.99 TO WS-SHIP-COST
WHEN ZONE-INTERNATIONAL ALSO PKG-MEDIUM
MOVE 24.99 TO WS-SHIP-COST
WHEN ZONE-INTERNATIONAL ALSO PKG-LARGE
MOVE 39.99 TO WS-SHIP-COST
WHEN OTHER
MOVE 0 TO WS-SHIP-COST
SET SHIPPING-ERROR TO TRUE
END-EVALUATE
.