Title: Understanding the Mainline Logical Flow Through a Program (continued)
1Understanding the Mainline Logical Flow Through a
Program (continued)
- Procedural program one procedure follows another
from beginning to end - Mainline logic has three distinct parts
- Housekeeping steps to get ready
- Main loop instructions executed for every input
record - End-of-job steps taken at end of program
- Break the logic down into at least three modules
2Understanding the Mainline Logical Flow Through a
Program (continued)
3Understanding the Mainline Logical Flow Through a
Program (continued)
- Modularization of the program
- Keeps the job manageable
- Allows multiple programmers to work
simultaneously - Keeps the program structured
4Housekeeping Tasks
- Housekeeping tasks include all steps that occur
at the beginning of the program - Declare variables
- Open files
- Perform one-time-only tasks such as printing
headings - Read the first input record
5Declaring Variables
- Assign identifiers to memory locations
- Specify the name and data type
- Use meaningful names and follow standards
- Prefixes may be used to group related variables
- Declare a variable for each field in a data file
6Declaring Variables (continued)
- Initializing (or defining) the variable
providing an initial value - Some languages provide default initial values
- Other languages leave variables with an unknown
or garbage value - Variables representing data fields in files do
not need to be initialized
7Declaring Variables (continued)
- Can use variables for report headings
- Embed any required spaces
- Heading can be printed using these variables
8Declaring Variables (continued)
- Local variables declared within a module
- Global variables declared at the beginning of
the program, and used in all modules - Annotation box flowchart symbol containing notes
- Data Dictionary list of variables used in a
program, with their type, size, and description
9Opening Files
- Specify file name and path (location)
- Issue a file open command
- If no input file is opened, input may be accepted
from the standard input device (e.g., keyboard) - You must open both input and output files to be
used, including printer output device - If no output file is opened, standard output
device (e.g., monitor) may be used
10Printing Headings
- Printing headings for reports usually is done at
beginning of the program or possibly for each new
page
11Reading an Input Record
- Reading the first input record is the last
housekeeping task - Interactive application
- Interacts with users via keyboard or mouse input
- Program pauses when the read command is executed
until the user enters data - Delimiter a character designated as a separator
between data values - Prompt an output statement that asks the user to
enter specific data
12Reading the First Input Record (continued)
- Interactive input (from a keyboard)
13Reading an Input Record
14Checking for the End of the File
- After reading a file
- For an interactive program, EOF may be determined
when - User enters a predetermined sentinel value
- User selects a screen option using a mouse
- For input from a file, the input device
recognizes EOF - EOF may occur on the first read
- If there is data, each record is processed before
the next read occurs
15Checking for End of File (continued)
16Modules, Subroutines, Procedures, Functions, or
Methods
- Module
- Unit of code that performs one small task
- Called a subroutine, procedure, function, or
method - Modularization breaking a large program into
modules
17Modules, Subroutines, Procedures, Functions, or
Methods (continued)
- Advantages of modularization
- Provides abstraction
- Allows multiple programmers to work
simultaneously - Allows code reuse
- Makes identifying structures easier
18Modularization Provides Abstraction
- Abstraction
- Focusing on important properties while ignoring
non-essential details - Avoids the low-level details and uses a
high-level approach - Makes complex tasks look simple
19Modularization Provides Abstraction (continued)
- A To-Do list
- with abstraction without abstraction
20Modularization Allows Multiple Programmers to
Work on a Problem
- Large programming projects can be divided into
modules - Modules can be written by different programmers
- Development time is significantly reduced
21Modularization Allows You to Reuse Your Work
- Reusability the ability to use modules in a
variety of applications - Reliability assurance that a module has been
tested and proven to function correctly
22Modularizing a Program
- Most programs contain a main module
- Contains the mainline logic
- Accesses other modules or subroutines
- Rules for module names used here
- Must be one word
- Should be meaningful
- Are followed by a set of parentheses
23Modularizing a Program (continued)
- Calling program (or calling module) one that
uses another module - Flowchart symbol for calling a module a
rectangle with bar across the top - Flowchart for the module contains
- Module name in the start symbol
- exit or return in the stop symbol
- When a module is called, logic transfers to the
model - When module ends, logic transfers back to the
caller
24Modularizing a Program (continued)
25Modules Calling Other Modules
26Understanding Documentation
- Documentation
- All supporting material that goes with a program
- Two major categories for users and for
programmers - Usually created by system analysts and/or tech
writers - May be printed or electronic (Web or CD)
- End users people who use computer programs
- Program Documentation
- Internal program documentation comments within
code - External program documentation supporting
paperwork written before programming begins
27Completing the Documentation
- Program documentation may contain
- Output design
- Input description
- Flowcharts
- Pseudocode
- Program code listing
- User documentation may contain
- Manuals
- Instructional material
- Operating instructions