1. How do modules help you to reuse code in a program?
If a operation needs to be performed in several places, the same module can be called and re-used cutting down on unnecessary code.
2. Name and describe the two parts that a module definition has in most languages. The two parts are a header and a body
3. When a module is executing, what happens when the end of the module is reached? It jumps back to the part of the program that called it. This is known as the return point
4. What is a local variable? What statements are able to access a local variable? A local variable is declared inside a module and cannot be accessed by statements that are outside the module.
5. In most languages, where does a local variable’s scope begin and end? Usually begins at the variables declaration and ends at the end of the module
6. What is the difference between passing an argument by value and passing it by reference? Passing an argument by value copies the data from the variable but does not change the original data. Passing a variable by reference will overwrite the existing data at that reference point in memory.
7. Why do global variables make a program difficult ot debug? If there is a debug issue, you have to step through ALL modules looking for the module that is incorrectly accessing that variable. Most programs have many many modules. This makes global variables very time consuming to debug.
Algorithm Workbench Review Questions 1,5,6, and 7 from page 111
1. Design a module named timesTen. The module should accept an Integer argument. When this module is called, it should display the product of its argument multiplied by 10
1. Declare a variable called number and set the value of it 2. Call the module timesTen passing as an argument the variable number by reference 3. In the module named timesTen create a parameter named number that the argument will be passed into 4. Calculate and set the variable number * 10
5. Display the variable number
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