M2 CH3 Flashcards
(47 cards)
A group of statements that exist within a program for the purpose of performing a specific task is a(n) _______________.
A.) block
B.) parameter
C.) module
D.) expression
C.) module
You ____________ the module to execute it.
A.)define
B.) call
C.) import
D.) export
B.) call
What happens when a module is called?
A.) the program ends
B.) the computer calls the main module
C.) the computer jumps back to the part of the program that called the module
D.) the computer calls the next module in the list
E.) the computer jumps to that module and executes the statements in the module’s body
E.) the computer jumps to that module and executes the statements in the module’s body
After a module has been called and its statements have been executed, what happens when the end of the module is reached?
A.) the program ends
B.) the computer calls the main module
C.) the computer jumps back to the part of the program that called the module
D.) the computer calls the next module in the list
E.) the computer jumps to that module and executes the statements in the module’s body
C.) the computer jumps back to the part of the program that called the module
Chapter 3: A ____________ is a variable that is declared inside a module.
A.) global variable
B.) local variable
C.) hidden variable
D.)none of the above; you cannot declare a variable inside a module
B.) local variable
The ___________ is the part of a program in which a variable may be accessed.
A.) declaration space
B.) area of visibility
C.) scope
D.) mode
C.) scope
Chapter 3: In most languages, where does a local variable’s scope begin and end?
A.) begins at the beginning of the module and ends at the end of module in which the variable is declared
B.) begins at the beginning of the program and ends at the end of the program
C.) begins at the variable’s declaration and ends at the end of the program
D.) begins at the variable’s declaration and ends at the end of module in which the variable is declared
D.) begins at the variable’s declaration and ends at the end of module in which the variable is declared
Chapter 3: A(n) ____________ is a piece of data that is sent into a module.
A.) argument
B.) parameter
C.) header
D.) packet
A.) argument
A(n) ____________ is a special variable that receives a piece of data when a module is called.
A.) argument
B.) parameter
C.) header
D.) packet
B.) parameter
When _____________ , only a copy of the argument’s value is passed into the parameter variable.
A.) passing an argument by reference
B.) passing an argument by name
C.) passing an argument by value
D.) passing an argument by data type
C.) passing an argument by value
When _____________ , the module can modify the argument in the calling part of the program.
A.) passing an argument by reference
B.) passing an argument by name
C.) passing an argument by value
D.) passing an argument by data type
A.) passing an argument by reference
A variable that is visible to every module in the program is a(n) _________________ .
A.) local variable
B.) universal variable
C.) program-wide variable
D.) global variable
D.) global variable
When possible, you should avoid using _________________ variables in a program.
A.) local
B.) global
C.) reference
D.) paramater
B.) global
The benefit(s) of using modules is / are : (CHECK ALL THAT APPLY)
A.) the code tends to be easier to understand
B.) using modules promotes code reuse, which will reduce the duplication of code within the program
C.) modules can be tested and debugged individually which will lead to better overall testing of the code
D.) it allows for easier facilitation of team work - each module can be assigned to a different developer
A, B, C, D
Module names should be as short as possible.
T/F
F
A statement in one module can access a local variable in another module.
T/F
F
Programming languages typically require that arguments be of the same data type as the parameters that they are passed to.
T/F
T
Most languages do not allow you to write modules that accept multiple arguments.
T/F
F
When an argument is passed by reference, the module can modify the argument in the calling part of the program.
T/F
T
Look at the following pseudocode module header:
Module myModule(Integer a, Integer h, Integer c)
Now look at the following call to myModule:
call myModule(3, 2, 1)
When this call executes, the value of ______ will be stored in a, the value of ________ will be stored in b, and the value of ____ will be stored in c.
3, 2, 1
Assume that a pseudocode program contains the following module:
Module display(Integer arg1, Real arg2, String arg3)
Display “Here are the values:”
Display arg1, “ “, arg2, “ “, arg3
End Module
Assume that the same program has a main module with the following variable declarations:
Declare Integer age
Declare real income
Declare String name
Write a statement that calls the display module and passes these variables to it.
Call display(age, income, name)
What is the error in the following pseudocode?
Module main()
Call raiseToPower(2, 1.5)
End Module
Module raiseToPower(Real value, Integer power)
Declare Real result
Set result = value^power
Display result
End Module
Data types must be labeled/declared correctly to be passed forward. Thus, in the raiseToPower module, 2 must be set as an integer and 1.5 must be set as real. Although some languages will allow you to mix data types, the programmer would have to set it up in a way where no date would be lost. However, in this example, the .5 would be lost so it still wouldn’t work.
What will the following pseudocode program display?
Module main()
Declare Integer x = 1
Declare Real y = 3.4
Display x, “ “, y
Call changeUs(x, y)
Display x, “ “, y
End Module
Module changeUs(Integer a, Real b)
Set a = 0
Set b = 0
Display a, “ “, b
End Module
1,3.4
0, 0
1,3.4
Examine the following pseudocode module header, and then write a statement that calls the module, passing 12 as an argument.
Module showValue(Integer quantity)
Call showValue(12)