Unit 4
Unit 4
INTRODUCTION TO STRUCTURED
PROGRAM DESIGN
print
getInput( ) “Enter a
number” print
sum = (firstNum average
+ secondNum)
calculateAv
erage( ) read
firstNumber print
“Thank You”
printResult
() average = sum/2
print “Enter
another
number” return
stop
read return
secondNumbe
r
return
MODULES CALLING OTHER MODULES
● Any module can call another module, just as a program can call
a module or subroutine
● Example
○ Main program calls the getInput( ) module
○ The getInput( ) module calls the getFirstValue( ) module
○ The getFirstValue( ) displays a prompt and reads a number
○ getFirstValue( ) ends, control is passed back to getInput( ), where
getSecondValue( ) is called
○ getSecondValue( ) displays a prompt, and reads a second value from user
○ getSecondValue( ) ends and control is passed back to getInput( )
○ getInput( ) ends and control is passed back to the main program
○ calculateAverage( ) and printResult( ) execute as before
PSEUDOCODE OF MODULES CALLING
OTHER MODULES
start getSecondValue( )
perform getInput( ) print “Enter another number”
perform calculateAverage( ) read secondNum
perform printResult( ) return
stop
calculateAverage( )
getInput( ) sum = firstNum + secondNum
perform getFirstValue( ) average = sum / 2
perform getSecondValue ) return
return
printResult( )
getFirstValue( )
print average
print “Enter a number”
read firstNum print “Thank you”
return
return
SPEED BYTE
● Draw the Psuedocode from the
example of modules calling other
modules.
DECLARING VARIABLES IN PSEUDOCODE
● Variables are declared as the first step in the
program before you use any of them
● They appear to the side of the “declare variables”
step in an annotation symbol or annotation box,
which is simply an attached box containing notes.
● Annotation symbols can be used anytime you have
more to write than you can conveniently fit within a
flowchart
DECLARING VARIABLES IN PSEUDOCODE
Class Exercise Group 1
● Write the Pseudocode for a program that
accepts 5 numbers and sorts the numbers in
descending order.
● Draw the associated flowchart
Class Exercise Group 2
● Write the Pseudocode for a program that
accepts a number N from the user and
prints the first N terms of the Fibonacci
sequence.
● Draw the associated flow chart
END