Title: Modules, Hierarchy Charts, and Documentation
1Modules, Hierarchy Charts, and Documentation
3
- Programming Logic and Design, Second Edition,
Comprehensive
2Objectives
- After studying Chapter 3, you should be able to
- Describe the advantages of modularization
- Modularize a program
- Understand how a module can call another module
- Explain how to declare variables
3Objectives
- After studying Chapter 3, you should be able to
- Create hierarchy charts
- Understand documentation
- Create print charts
- Interpret file descriptions
- Understand the attributes of complete
documentation
4Modules
- Large programs are never written as one huge
series of steps. - Programs are broken down into units called
modules. - Modules are also referred to as
- subroutines
- functions
- procedures
- methods
5AdvantagesModularization AllowsMultiple
Programmers to Work on a Problem
- Dissect large task into modules
- divide the task among various people
-
6Modularization Allows You to Reuse Your Work
- REUSE YOUR WORK
- You can find many real-world examples of
reusability
7Modularization
Makes It Easier to Identify Structures
- When you combine several programming tasks into
modules, it may be easier for you to identify
structures
8Selection of Logic From a Payroll Program
9Modularized Logic from a Payroll Program
- The single program segment shown in Figure 3-2
accomplishes the same steps as the two program
segments shown together in Figure 3-3 both
programs are structured
10Another Example
- Modules can better help you determine if your
flowchart is structured.
11Modularizing a Program- Flowchart Symbols
- Sentinel Symbols
- A module has it own sentinel symbols (Start and
End) - The Start symbol has the name of the module
- The End symbol has the word RETURN
12Modularize a ProgramNaming the MODULE
- In this text, module names will follow the same
two rules used for variable names - Module names must be one word
- Module names should have some meaning
- Additionally, in this text module names will be
followed by a set of parentheses
13Another Example
14Lets try
- Example 1 -
- Write a flowchart showing the logic to calculate
the volume of an undetermined amount of rooms.
(Volume Length Width Height) - Think about what your logic needs -
- Input
- Processing (for more than one room)
- Output
- Create a flowchart first without and then with a
module.
15Example 1 - Without a module
16Example 1 - With a Module
17Example 2
- Create a flowchart showing the logic needed to
accept a series of numbers, print each number
when it is read, and print the total after all
the numbers are read. - An example run 28
- of the program 10
- 15
- 53
-
18Example 2 - Without a Module
19Example 2 - With a Module
20Modules Calling Other Modules
- A module can be called by both the main program
or by another module - Modules called by other modules are called
submodules.
21Averaging Program with Submodules
22Flowchart and Pseudocode for Averaging Program
with Modules
23Flowchart for Averaging Program with Submodules
24 Another ToolCreating Hierarchy Charts
- You can use a hierarchy chart to illustrate
modules relationships - A hierarchy chart does not tell you what tasks
are to be performed within a module it does not
tell you when or how a module executes - The hierarchy chart for the last version of the
value-averaging program looks like Figure 3-7
25Hierarchy Chart for Value-Averaging Program
26An Organizational Hierarchy Chart
27Declaring Variables
- Declaring a variable provides a name for a memory
location - where computer stores variable values
- notifies computer of data type
- Programming languages declare variables
differently, but minimally you must - give the variable a name
- give the variable a data type
28Declaring Variables
- An annotation symbol or annotation box is simply
an attached box containing notes - You can use an annotation symbol any time you
have more to write than conveniently fits within
a flowchart symbol - Programmers sometimes create a data dictionary,
which is a list of every variable name used in a
program, along with its type, size, and
description - When a data dictionary is created, it becomes
part of the program documentation
29Declaring Variables in a Flowchart
- One of first things done in a program in
declaring variables
- Next to the process symbol Declare Variables is
an annotation box stating the names and types of
the variables - Annotation boxes can be used anytime text does
not fit in a symbol
30Declaring Variables
- Languages including COBOL, C, C, Java, and
Pascal require declaration of variables with name
and type - Modern programming languages variables are
declared within each module that uses them. Such
variables are known as local variables - We will use global variablesvariables that are
given a type and name once- used in all modules
of the program
31What is Documentation
- All supporting material that goes along with a
program - User documentation
- Manuals
- Training material
- Program documentation
- used for planning or modifying programs
- internal and external program documentation
32PROGRAM Input Documentation
- A file description describes the data contained
in an input file - Files description as part of an organizations
information systems documentation
33Input The inventory file description in Figure
3-20 shows that each items name occupies the
first 15 characters of each record in the file
- The price of any item in the inventory file is
allowed five positions, 16 through 20 - Two of the positions are reserved for decimal
places - Typically, decimal points themselves are not
stored in data files they are implied or assumed
34Input Documentation
- Numeric data are stored with leading zeros
- Programmers create one variable for each field in
the input file
35Input Documentation
- Recall the data hierarchy relationship introduced
in Chapter 1 - Database
- File
- Record
- Field
- Character
36Input Documentation
- The programmer needs to know is
- What is the name of the file?
- What data does it contain?
- How much room does the file and each of its
fields take up? - What type of data is each fieldcharacter or
numeric?
37Expanded Inventory File Description
- The file description in Figure 3-21 contains nine
fields
38Internal Documentation
- //
- / Program Payroll /
- / Author Dan Dainton /
- / Date March 2, 1999 /
- //
- Comments within programming code
- Lines of code that do not effect the running of
the program. - Written so programmers can
- understand what the program is doing
- why the program is doing it
// / This module
calculates/ / tax deductions for / /
payroll checks. / /
/
39External Documentation
- All supporting paperwork a programmer develops
before writing a program. - External documentation can describe
- Input
- Processing
- Output
- Output documentation is developed first. Why?
40Output Documentation
- Generally, the reason you would write a program
in a business environment is because particular
information is needed. - Can the programmer decide what information is
needed and how its designed? Can the user
requesting the information?
41Output DocumentationDesigning a Report
- Printed reports are the most common type of
output. - Reports are designed on printer spacing charts.
- Looks like a grid
- One character per box
42A Report Design Example
- This report will track inventory for a company
- Report Title ie Inventory Report
43Creating Column Headings
- Report column heading
- constant that appear on every page of the report
- Because the headings remain the same throughout
the report, they are written on the print chart
literally.
44More on Detail Lines
- Detail lines
- have variable data
- probably have a variable amount of detail lines
on the report - All the detail lines look the same, but you need
to show 2 - 3 lines in your print chart. Why?
45Understanding Documentation
- Documentation refers to all of the supporting
material that goes with a program - Two broad categories of documentation are
intended for the programmer and for the user - People who use computer programs are called end
users, or users for short - When programmers begin to plan the logic of a
computer program, they require instructions known
as program documentation
46Understanding Documentation
- Program documentation falls into two categories
internal and external - Internal program documentation consists of
program comments, or nonexecuting statements that
programmers place within their code to explain
program statements in English - External program documentation includes all the
supporting paperwork that programmers develop
before they write a program
47Output Documentation
- Output documentation is usually the first to be
written - The most common type of output is a printed
report - You can design a printed report on a printer
spacing chart, which is also referred to as a
print chart or a print layout - The title and column headings will be constant on
every page of the report so they are written on
the print chart literally
48Printer Spacing Chart
49Printer Spacing Chart with First Title
50Printer Spacing Chart with Title and Column
Headings
51Output Documentation
- The exact spacing and use of upper- or lowercase
make a difference - Notice that the constants used within a report do
not need to follow the same rules as variable
names - A print layout typically shows how the variable
data will appear on the report - Each line with its Xs and 9s representing data is
a detail line because it contains the data details
52Print Chart with Generic Data
53Variable Data in Report Heading
54Heading with Page Numbers
55Print Chart with Literal in Each Detail Line
56Output Documentation
- Detail lines typically appear many times per
page, as opposed to heading lines, which usually
appear only once per page - Besides header lines and detail lines, reports
often include special lines at the end of a
report - Even though lines at the end of a report dont
always contain numeric totals, they are usually
referred to generically as total lines
57Report with Variable Data at End
58Report with Constant Data at End
59Report with Combined Constant and Variable Data
at End
60Completing the Documentation
- Program Documentation
- Design outputPlan the logic of the program
- Code the program
- Test the program
- User documentation
- User documentation instructional materials
that nontechnical people use
61Completing the Documentation
- The areas addressed in user documentation may
include - Description of input for the program
- Who needs the output
- What output should look like
- How to interpret and react to any error message
generated by the program - How frequently the program needs to run
62IN Summary- Review Modules
- Programming using modules
- Module is given a name- that name is CALLED by
the calling program - A module can call other modules
63Summary- Variables
- To Declaring a Variable providing a name for
the memory location where the value is stored - Identify the data type You can use a hierarchy
chart to illustrate modules relationships - Documentation refers to all of the supporting
material that goes with a program - Output documentation is usually written first
64Summary- Documentation
- File description lists the data in a file (
description, size, and data type) - Program documentation file descriptions,
printer spacing charts etc - User Documentation manuals or other
instructional materials that nontechnical people
use as well as the operating instructions that
computer operators and data-entry personnel may
need