IBM is hosting a career fair this Saturday

advertisement
PROCEDURE DIVISION.
PREPARE-SENIOR-REPORT.
OPEN INPUT STUDENT-FILE
OUTPUT PRINT-FILE.
READ STUDENT-FILE
AT END MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.
PERFORM WRITE-HEADING-LINE.
PERFORM PROCESS-RECORDS
UNTIL DATA-REMAINS-SWITCH = 'NO'.
CLOSE STUDENT-FILE
PRINT-FILE.
STOP RUN.
WRITE-HEADING-LINE.
MOVE HEADING-LINE TO PRINT-LINE.
WRITE PRINT-LINE.
PROCESS-RECORDS.
IF STU-CREDITS > 110 AND
STU-MAJOR = 'ENGINEERING'
MOVE STU-NAME TO PRINT-NAME
MOVE DETAIL-LINE TO PRINT-LINE
WRITE PRINT-LINE
END-IF.
READ STUDENT-FILE
AT END MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.
Pseudocode initial attempt
Read Student-file until End-of-File
Write Report Heading
IF engineering major with more
than 110 credits
Write student’s name
Else
Skip to next record
End-If
Pseudocode
PROCEDURE DIVISION.
PREPARE-SENIOR-REPORT.
OPEN INPUT STUDENT-FILE
OUTPUT PRINT-FILE.
READ STUDENT-FILE
AT END MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.
PERFORM WRITE-HEADING-LINE.
PERFORM PROCESS-RECORDS
UNTIL DATA-REMAINS-SWITCH = 'NO'.
CLOSE STUDENT-FILE
PRINT-FILE.
STOP RUN.
WRITE-HEADING-LINE.
MOVE HEADING-LINE TO PRINT-LINE.
WRITE PRINT-LINE.
PROCESS-RECORDS.
IF STU-CREDITS > 110 AND
STU-MAJOR = 'ENGINEERING'
MOVE STU-NAME TO PRINT-NAME
MOVE DETAIL-LINE TO PRINT-LINE
WRITE PRINT-LINE
END-IF.
READ STUDENT-FILE
AT END MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.
Open files
Initialization
Read first record
Write heading
Processing
DO while data remains
IF engineering major with more th
Write student’s name
ENDIF
ENDDO
Close files
Termination
Stop
Sequence
--------------------------------------------------------
Everything in here
is executed
in a top-to-bottom
sequence
James Martin, Recommended Diagramming Standards for Analysts &
Programmers
Action Diagrams
Use of Brackets for
Sequence
Condition
Case
Repetition
from top to bottom
Depends on the condition
Only one is executed
Repeated until loop ends
A bracket corresponds to a program module
Use of parent child relationship
One entry point for the bracket and one exit point
Peel like onions
Main Line bracket
Paragraph bracket
Consider the batch processing (unattended processing):
1. Read a record
2. Write a line on the report
3. Repeat the process until the End of File (no more records in the
file)
The algorithm would look like this
1. Write the report heading
2. Read the first record
3. While there are more records
3.1
Write a detail line
3.2
Read the next record
End-While
4. End program
Note: The report heading should be printed only once hence it is
outside the loop
But why the first read since we have to read the file within the loop ?
If we remove the first read then the code would look like this:
1. Write the report heading
2. While there are more records
2.1Write a detail line
2.2Read the next record
End-While
3. End program
 ??? What is wrong
Or maybe you would move it around to look like this:
1. Write the report heading
2. While there are more records
2.1
Read the next record
2.2
Write a detail line
End-While
3. End program
Student Name 1
Student Name 2
Student Name 3
 What is wrong
Major
Major
Major
The problem with this algorithm is when you hit end of file.
Here it will still try to “Write a detail line”.
Reading the file should take place at the end of the loop so that
when End of File is detected the loop immediately ends.
IDENTIFICATION DIVISION.
PROGRAM-ID.
Senior.
AUTHOR.
Yourname.
INSTALLATION. Seneca College.
DATE-WRITTEN. September 27, 1999.
DATE-COMPILED. The compiler supplies the compilation date.
SECURITY.
Forget it.
REMARKS.
Use to define the function of the program.
Also use comments to describe the program.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER.
OBJECT-COMPUTER.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
I-O-CONTROL.
Computer Name + Model# (where compiled) *
Computer Name + Model# (where it will run)
Assigning implementation names, etc.
Refer to Chapter 2 page 56-57.
Allows backup, log, and audit records to be created
DATA DIVISION.
FILE SECTION.
Describes files, records, and data items
WORKING-STORAGE SECTION. Program described data items
LINKAGE SECTION.
Defines data items from another program.
Group Items
 Parents
Have no PIC clause
Elementary Items
 Children
Have a PIC clause
Level numbers
01
(01 to 49)
is for the whole record and a parent of 02 and higher levels
02 is child of 01 and parent of 03 and higher levels
Use identation for level numbers
Download