Short Answer
1. How do modules help you to reuse code in a program?
It reduces the duplication of a code within a program by reusing the module that was written once.
2. Name and describe the two parts that a module definition has in most languages.
The Header and a Body
First the Header indicates a starting point
Second the Body is a list of statements
3. When a module is executing, what happens when the end of the module is reached?
Its executed and returned back to the point in the main program where it was sidetracked from
4. What is a local variable? What statements are able to access a local variable?
A variable is declared inside a local module in which it is the only statement within a module
5. In most languages, where does a local variable’s scope begin and end?
It begins at the variables declaration within a module and it ends at the end of the module in which the variable is declared.
6. What is the difference between passing an argument by value and passing it by reference?
By the value only a copy of the arguments value is passed and by reference it is passed into a special modifications parameter.
7. Why do global variables make a program difficult to debug?
It is because the global variables is used throughout all modules and plus they are hard to track.
Algorithm Workbench
1. Design a module named timesTen. The module should accept an Integer argument. When the module is called, it should display the product of its argument multiplied times 10.
Module Main ()
Call timesTen
Module timesTen (Integer Value)
Declare integerValue
Set result = value*10
Display result
End Module
5. Design a module named getNumber, which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.
Module getNumber (Integer Ref value)
Display “Display a number”
Input number
End