Programming Chap 3
Programming Chap 3
•Introduction to Modules
•Defining and Calling a Module
•Local Variables
•Passing Arguments to Modules
•Global Variables and Global Constants
Introduction to Modules
Call showMessage()
Module showMessage()
Display "Hello world"
End Module
Flowcharting a Program with Modules
In a flowchart, a module call is shown with a rectangle that
has vertical bars at each side, as shown in below. The
name of the module that is being called is written on the
symbol.
showMessage()
Flowchart for Module Example 1
Main()
showMessage()
Display ”I have a
message for you.” Display “Hello
World”
showMessage()
Return
End
Hierarchy Charts
Flowcharts are good tools for graphically depicting the flow
of logic inside a module, but they do not give a visual
representation of the relationships between modules.
Programmers commonly use hierarchy charts for this
purpose. A hierarchy chart, which is also known as a
structure chart, shows boxes that represent each module in
a program.
main()
Module getName()
Declare String name This is local variable.
Display "Enter your name."
Input name
End Module
Scope and Local Variables
Module getName()
Display "Enter your name."
Input name This statement will cause an error
because
Declare String name the name variable has not been
declared yet.
End Module
Duplicate Variable Names
You cannot have two variables with the same name in the same
module because the compiler or interpreter would not know
which variable to use when a statement tries to access one of
them. All variables that exist within the same scope must have
unique names.
Module getTwoAges()
Declare Integer age
Display "Enter your age."
Input age
Global Variable
Module showNumber()
Display "The number you entered is ", number
End Module
Global Variable Constant
Hierarchy Chart:
main()