Presentation is loading. Please wait.

Presentation is loading. Please wait.

5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.

Similar presentations


Presentation on theme: "5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John."— Presentation transcript:

1 5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John Wiley & Sons, Inc. PowerPoint Winifred J. Rex Presentation Bowling Green State University 10th edition

2 5-2 Chapter Objectives To familiarize you with 1.  Structured programs 2.  Pseudocode 3.  Hierarchy or Structure Charts 4.  Logical Control Structures 5.Good programming techniques 6.Interactive processing

3 5-3 Well-Designed Programs Are structured programs – when using procedural languages (COBOL, C, …) Use instructions executed in standardized order Divide program into modules, each performing a specific function Control returns to place module called from Simple PERFORM used in COBOL to execute modules (paragraphs)

4 5-4 Well-Designed Programs Use top-down approach Code modules in hierarchical order Main modules first, then secondary modules with detailed code Step-wise refinement Top modules are ‘control’ modules; abstract; drivers; contain ‘Performs’… As we go down the hierarchy, control becomes less and computations and data manipulation becomes greater.

5 5-5 Well-Designed Programs Are modular Group related statements together into modules Execute each module or paragraph in COBOL with simple PERFORM For example, statements to calculate students’ tuition in one module, statements to calculate room and board in another module

6 5-6 Designing Before Coding Design program first –So program will work efficiently –So program works as integrated whole –Design techniques applicable to all languages  Code program only after design done –Use syntax rules of language –Syntax rules are language-specific

7 5-7 Pseudocode Primary tool for planning program logic We will use structure charts for our architectural design and pseudo- code for our lower-level detail (algorithmic) design. Specifies instructions and logical control structures used by program Use one or more lines of pseudo-code to describe each program step

8 5-8 Four Logical Control Structures Used by structured programs to specify order in which instructions are executed 1.Sequence 2.Selection 3.Iteration 4.Case Structure All programs may be written using some combination of these control structures!

9 5-9 Sequence Instructions executed in order they appear Three instructions below executed one after the other (pseudo-code shown) START Read Amt1, Amt2 Compute Total = Amt1 + Amt2 Write Total STOP Note: no syntax; no periods, just generic procedure. Imperative statements. Nothing conditional or repetitive.

10 5-10 Selection (true / false) Instructions executed depending on existence of a condition Called IF-THEN-ELSE logical control structure Condition: if amt > 40 … The condition is amt>40. This is evaluated. It is either TRUE or FALSE. Present value of amt either equals 40 or not! Subsequent actions take place based on the truth value of the condition!

11 5-11 Selection Structure Pseudocode IF condition THEN instructions to do if condition exists ELSE instructions to do if condition doesn’t exist END-IF Example (again, this is in pseudocode.) IF X is Less Than Y THEN Add X To Y ELSE Subtract X From Y END-IF

12 5-12 Iteration (Looping Constructs) To specify repeated execution of series of steps Use in-line or standard PERFORM … UNTIL for iteration in COBOL –There are additional forms – later. Both execute group of instructions repeatedly until a condition is met

13 5-13 Iteration Pseudocode In-line PERFORM UNTIL PERFORM UNTIL condition.. statements to be repeated. END-PERFORM.. Statements following PERFORM. MUST use a scope terminator! Needed to ‘bound’ the scope. Note: statements within Perform may never be executed. Remember the ‘pre-condition’ followed by ‘post-conditions.’

14 5-14 Iteration Pseudocode Standard PERFORM UNTIL PERFORM paragraph-1 UNTIL condition.. Statements following PERFORM. Paragraph-1. located elsewhere in program.. statements to be repeated.

15 5-15 Infinite Loops In-line and standard PERFORM UNTIL both repeat instructions until condition met If condition never met, loop never ends Causes error called an infinite loop

16 5-16 Infinite Loops Make sure loop ends by including instruction in loop that causes condition to be met For example, if condition is WS-MORE-DATA = ‘NO’ Make sure there is statement in loop that sets WS-MORE-DATA to ‘NO’ when there is no more data

17 5-17 move 0 to counter. perform until counter > 10 …. end-perform Will generate an infinite loop: move 0 to counter. perform until counter = 10 …. add 1 to counter end-perform Will terminate loop after 10 iterations: Two Examples

18 5-18 Case Structure To choose from one of several sets of instructions depending on a condition For example, assume –Different instructions should be executed when field Code-In has values of 1, 2 or 3 –Any other value of Code-In is considered an error

19 5-19 Case Structure Pseudocode EVALUTATE Code-In WHEN 1 PERFORM paragraph-1 WHEN 2 PERFORM paragraph-2 WHEN 3 PERFORM paragraph-3 WHEN OTHER PERFORM error-paragraph END-EVALUATE Note: scope terminator, indentation. Will cause branches only if value of Code-In is either a 1 or a 2 or a 3; otherwise, error-paragraph will be performed. Note also: ‘integer’ values!

20 5-20 Hierarchy Charts (Structure Charts) To illustrate top-down relationships among modules Graphic method to divide program into modules Modules shown as rectangular boxes Relationships among modules represented by connected lines Note: only DOWN not across. We are functionally decomposing higher- level modules into its parts.

21 5-21 Example of Hierarchy Chart 0000-main 1000-some-name. 2000-some-name1 1300-xxx 1600-xxx 2300-yyy 2600-yyy 2900-yyy DISCUSS PARAGRAPH NAMING CONVENTIONS Very Important!

22 5-22 Hierarchy Chart Letters A-H represent modules or paragraphs A is main module B and C are subordinate modules called from main paragraph with a PERFORM D and E represent modules called from paragraph B We will use our standards.

23 5-23 Pseudocode and Hierarchy Charts Pseudocode shows actual sequence of instructions – detailed algorithmic steps. –Do this secondly Hierarchy charts show relationships among modules – higher level, architectural design. Do this first. Both help programmers –Develop efficient programs –Debug and modify programs

24 5-24 Naming Paragraphs Name up to 30 characters - letters, digits, hyphen Choose meaningful name that describes type of instructions in module Use numeric prefixes to indicate relative location of module in program Examples 1000-Main-Module 2000-Process- Data


Download ppt "5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John."

Similar presentations


Ads by Google