Deck 8: Modules and Functions

Full screen (f)
exit full mode
Question
Structured programming, the method for creating all programs from sequence, selection, and repetition structures, is about clarity.
Use Space or
up arrow
down arrow
to flip the card.
Question
Clumsy programming involves code that repeats throughout a program, long modules without any apparent organization, and use of the infamous GOTO statement.
Question
Modules cannot call other modules.
Question
In most programming languages, global variables are declared explicitly as global or declared in the main module outside any other modules.
Question
In general, variables are assumed to be global unless they are declared as local.
Question
All variables declared in separate modules are global and cannot be affected by other modules.
Question
If two variables in different modules happen to have the same name, they are stored in different memory locations, and the statements affecting one do not affect the other.
Question
The flowchart shape for a called module is a parallelogram with stripes, which indicates a predefined process.
Question
A For loop is depicted like a While loop in a flowchart, with initialization and incrementing as separate steps.
Question
An efficient way of providing data to modules and still allowing the use of local variables is to pass the data as an argument.
Question
Data sent when a module is called is a parameter.
Question
A parameter consists of the data type and variable pair to receive the data.
Question
Modules can be designed to accept more than one argument.
Question
Parameters and arguments must match in number, data type, and order.
Question
Functions can return more than one value.
Question
When you call a module by using an argument, you are sending data to the module.
Question
Functions return values by sending data back to the calling module.
Question
You should design your modules and functions to be capable of being used in more than one way.
Question
Low coupling limits a module's flexibility.
Question
Modularizing a program makes it more efficient by including highly cohesive code and calling another module for each separate task.
Question
If you have more than five to six statements that are closely related to the same purpose and have the potential of being used in more than one place in your program, you should consider turning these statements into a module.
Question
Modules cannot be reused in a program.
Question
Programmers can work on separate modules for efficiency without having to worry about variable names used in other modules.
Question
An advantage of modularization is that the main module is easier to understand yet still gives the "big picture" of what's happening.
Question
In a pseudocode class definition, if a method returns a value, the method header starts with the method name
Question
A(n) ____ is simply a section of a program that performs a specific task.

A) module
B) constant
C) argument
D) parameter
Question
Instead of listing all the code in the main program, your main program calls the ____.

A) argument
B) parameter
C) module
D) constant
Question
____ is used to create a program's overall outline and describe tasks to be accomplished, and then details of these tasks are refined later.

A) Cohesion
B) Top-down design
C) Coupling
D) Bottom-up design
Question
When output is meant for the screen, you should use the ____ keyword.

A) Declare
B) Print
C) Display
D) Input
Question
When output is meant for a printer, you should use the ____ keyword.

A) Print
B) Input
C) Display
D) Declare
Question
____ are created when a module is called and exist only while statements in the module are performed.

A) Arguments
B) Global variables
C) Parameters
D) Local variables
Question
With modular programming, a variable's ____ is the section of program code in which a variable can be accessed.

A) overhead
B) scope
C) coupling
D) cohesion
Question
____ are available to all modules in the program.

A) Arguments
B) Global variables
C) Local variables
D) Parameters
Question
In the code below, why is it that the displayName() module cannot print the person's name?
Start
Call getInput()
Call displayName()
Stop
Module getInput()
Declare String name
Display "Enter your name: "
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module

A) The name variable is outside the displayName() module's scope.
B) The name variable is a global variable.
C) The name variable is strongly cohesive.
D) The name variable has high coupling.
Question
In which of the following is the variable name declared as a global variable?

A) Start
Call getInput()
Call displayName()
Stop
Module getInput()
Declare String name
Display "Enter your name"
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module

B) Start
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Declare String name
Display "Your name is: " + name
End Module

C) Start
Call name
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Declare String name
Display "Your name is: " + name
End Module

D) Start
Declare String name
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module
Question
Why is it that all variables are not declared as global?

A) Local variables, in different modules, are completely dependent on each other.
B) Local variables are restrictive.
C) By using local variables, programmers working on a module do not have to worry about what variable names are used in the main module or any other module.
D) Global variables, in different modules, are completely dependent on each other.
Question
What happens if a module uses a local variable with the same name as a main module variable, which is assumed to be global?

A) In this case, the variable declared globally is used.
B) It would cause a syntax error.
C) It would cause a logic error.
D) In this case, the variable declared locally is used.
Question
____ are values represented as constants or variables, which are enclosed in the parentheses following the module name in the Call statement.

A) Data types
B) Parameters
C) Data sets
D) Arguments
Question
Which of the following statements is true?

A) Data types do not need to be declared in function parameters.
B) Modules are designed to accept only one argument.
C) Typically, parameter variable names are longer than variable names in the main module to indicate their permanent nature.
D) Data types must be declared in function parameters.
Question
Sending the value of a variable or constant to a module, where a local variable is initialized to the argument's value is known as ____.

A) passing by value
B) coupling
C) passing by reference
D) cohesion
Question
When ____, the variable's actual memory address is sent to the module, and the parameter variable is the same location in memory as the variable in the calling module.

A) passing by value
B) cohesion
C) passing by reference
D) coupling
Question
A ____ error occurs when JavaScript's language rules are violated.

A) global
B) syntax
C) local
D) logic
Question
A ____ error occurs when the wrong instruction is given to the computer for solving a problem.

A) local
B) syntax
C) global
D) logic
Question
With a ____ error, the syntax is correct so the computer can process the instruction, but it is not the correct instruction.

A) global
B) syntax
C) local
D) logic
Question
A ____ is a value that is sent back to the calling module from a called module.

A) return value
B) parameter
C) constructor
D) argument
Question
____ is the measure of the degree to which all statements and variables in the module relate to one purpose.

A) Coupling
B) Vulnerability
C) Cohesion
D) Efficiency
Question
____ is the degree to which a module depends on other modules to do its work.

A) Cohesion
B) Coupling
C) Efficiency
D) Vulnerability
Question
The following function has ____.
Function Numeric average()
// Declare variables
Declare Numeric inputNum // number entered
Declare Numeric quantity // numbers input
Declare Numeric total = 0 // accumulated total
Declare Numeric index // loop variable
Declare Numeric avg // avg of numbers

// Ask user how many numbers to input
Display "How many numbers will you input? "
Input quantity

// Ask user how many numbers to input
Display "How many numbers will you input? "
Input quantity

// Compute and return average, end function
Avg = total / quantity
Return avg
End Function

A) strong cohesion
B) high coupling
C) weak cohesion
D) strong vulnerability
Question
You might be "____" your code if you write a separate module for every task.

A) over designing
B) overmodularizing
C) over programming
D) strongly coupling
Question
The prompt() command in JavaScript is actually a(n) ____.

A) variable
B) parameter
C) function
D) argument
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Modules and Functions
1
Structured programming, the method for creating all programs from sequence, selection, and repetition structures, is about clarity.
True
2
Clumsy programming involves code that repeats throughout a program, long modules without any apparent organization, and use of the infamous GOTO statement.
True
3
Modules cannot call other modules.
False
4
In most programming languages, global variables are declared explicitly as global or declared in the main module outside any other modules.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
In general, variables are assumed to be global unless they are declared as local.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
All variables declared in separate modules are global and cannot be affected by other modules.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
If two variables in different modules happen to have the same name, they are stored in different memory locations, and the statements affecting one do not affect the other.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
The flowchart shape for a called module is a parallelogram with stripes, which indicates a predefined process.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
A For loop is depicted like a While loop in a flowchart, with initialization and incrementing as separate steps.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
An efficient way of providing data to modules and still allowing the use of local variables is to pass the data as an argument.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Data sent when a module is called is a parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
A parameter consists of the data type and variable pair to receive the data.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
Modules can be designed to accept more than one argument.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Parameters and arguments must match in number, data type, and order.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Functions can return more than one value.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
When you call a module by using an argument, you are sending data to the module.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
Functions return values by sending data back to the calling module.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
You should design your modules and functions to be capable of being used in more than one way.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Low coupling limits a module's flexibility.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Modularizing a program makes it more efficient by including highly cohesive code and calling another module for each separate task.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
If you have more than five to six statements that are closely related to the same purpose and have the potential of being used in more than one place in your program, you should consider turning these statements into a module.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Modules cannot be reused in a program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Programmers can work on separate modules for efficiency without having to worry about variable names used in other modules.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
An advantage of modularization is that the main module is easier to understand yet still gives the "big picture" of what's happening.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
In a pseudocode class definition, if a method returns a value, the method header starts with the method name
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
A(n) ____ is simply a section of a program that performs a specific task.

A) module
B) constant
C) argument
D) parameter
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Instead of listing all the code in the main program, your main program calls the ____.

A) argument
B) parameter
C) module
D) constant
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
____ is used to create a program's overall outline and describe tasks to be accomplished, and then details of these tasks are refined later.

A) Cohesion
B) Top-down design
C) Coupling
D) Bottom-up design
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
When output is meant for the screen, you should use the ____ keyword.

A) Declare
B) Print
C) Display
D) Input
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
When output is meant for a printer, you should use the ____ keyword.

A) Print
B) Input
C) Display
D) Declare
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
____ are created when a module is called and exist only while statements in the module are performed.

A) Arguments
B) Global variables
C) Parameters
D) Local variables
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
With modular programming, a variable's ____ is the section of program code in which a variable can be accessed.

A) overhead
B) scope
C) coupling
D) cohesion
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
____ are available to all modules in the program.

A) Arguments
B) Global variables
C) Local variables
D) Parameters
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
In the code below, why is it that the displayName() module cannot print the person's name?
Start
Call getInput()
Call displayName()
Stop
Module getInput()
Declare String name
Display "Enter your name: "
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module

A) The name variable is outside the displayName() module's scope.
B) The name variable is a global variable.
C) The name variable is strongly cohesive.
D) The name variable has high coupling.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
In which of the following is the variable name declared as a global variable?

A) Start
Call getInput()
Call displayName()
Stop
Module getInput()
Declare String name
Display "Enter your name"
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module

B) Start
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Declare String name
Display "Your name is: " + name
End Module

C) Start
Call name
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Declare String name
Display "Your name is: " + name
End Module

D) Start
Declare String name
Call getInput()
Call displayName()
Stop
Module getInput()
Display "Enter your name"
Input name
End Module
Module displayName()
Display "Your name is: " + name
End Module
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Why is it that all variables are not declared as global?

A) Local variables, in different modules, are completely dependent on each other.
B) Local variables are restrictive.
C) By using local variables, programmers working on a module do not have to worry about what variable names are used in the main module or any other module.
D) Global variables, in different modules, are completely dependent on each other.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
What happens if a module uses a local variable with the same name as a main module variable, which is assumed to be global?

A) In this case, the variable declared globally is used.
B) It would cause a syntax error.
C) It would cause a logic error.
D) In this case, the variable declared locally is used.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
____ are values represented as constants or variables, which are enclosed in the parentheses following the module name in the Call statement.

A) Data types
B) Parameters
C) Data sets
D) Arguments
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements is true?

A) Data types do not need to be declared in function parameters.
B) Modules are designed to accept only one argument.
C) Typically, parameter variable names are longer than variable names in the main module to indicate their permanent nature.
D) Data types must be declared in function parameters.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Sending the value of a variable or constant to a module, where a local variable is initialized to the argument's value is known as ____.

A) passing by value
B) coupling
C) passing by reference
D) cohesion
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
When ____, the variable's actual memory address is sent to the module, and the parameter variable is the same location in memory as the variable in the calling module.

A) passing by value
B) cohesion
C) passing by reference
D) coupling
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
A ____ error occurs when JavaScript's language rules are violated.

A) global
B) syntax
C) local
D) logic
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
A ____ error occurs when the wrong instruction is given to the computer for solving a problem.

A) local
B) syntax
C) global
D) logic
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
With a ____ error, the syntax is correct so the computer can process the instruction, but it is not the correct instruction.

A) global
B) syntax
C) local
D) logic
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
A ____ is a value that is sent back to the calling module from a called module.

A) return value
B) parameter
C) constructor
D) argument
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
____ is the measure of the degree to which all statements and variables in the module relate to one purpose.

A) Coupling
B) Vulnerability
C) Cohesion
D) Efficiency
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
____ is the degree to which a module depends on other modules to do its work.

A) Cohesion
B) Coupling
C) Efficiency
D) Vulnerability
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
The following function has ____.
Function Numeric average()
// Declare variables
Declare Numeric inputNum // number entered
Declare Numeric quantity // numbers input
Declare Numeric total = 0 // accumulated total
Declare Numeric index // loop variable
Declare Numeric avg // avg of numbers

// Ask user how many numbers to input
Display "How many numbers will you input? "
Input quantity

// Ask user how many numbers to input
Display "How many numbers will you input? "
Input quantity

// Compute and return average, end function
Avg = total / quantity
Return avg
End Function

A) strong cohesion
B) high coupling
C) weak cohesion
D) strong vulnerability
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
You might be "____" your code if you write a separate module for every task.

A) over designing
B) overmodularizing
C) over programming
D) strongly coupling
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
The prompt() command in JavaScript is actually a(n) ____.

A) variable
B) parameter
C) function
D) argument
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.