M2 CH3 Flashcards

(47 cards)

1
Q

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

A

C.) module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

You ____________ the module to execute it.

A.)define
B.) call
C.) import
D.) export

A

B.) call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

E.) the computer jumps to that module and executes the statements in the module’s body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

C.) the computer jumps back to the part of the program that called the module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

B.) local variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

C.) scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

D.) begins at the variable’s declaration and ends at the end of module in which the variable is declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Chapter 3: A(n) ____________ is a piece of data that is sent into a module.

A.) argument

B.) parameter

C.) header

D.) packet

A

A.) argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

B.) parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

C.) passing an argument by value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A.) passing an argument by reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

D.) global variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When possible, you should avoid using _________________ variables in a program.

A.) local
B.) global
C.) reference
D.) paramater

A

B.) global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A, B, C, D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Module names should be as short as possible.
T/F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A statement in one module can access a local variable in another module.
T/F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Programming languages typically require that arguments be of the same data type as the parameters that they are passed to.
T/F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Most languages do not allow you to write modules that accept multiple arguments.
T/F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When an argument is passed by reference, the module can modify the argument in the calling part of the program.
T/F

20
Q

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.

21
Q

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.

A

Call display(age, income, name)

22
Q

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

A

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.

23
Q

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

A

1,3.4

0, 0

1,3.4

24
Q

Examine the following pseudocode module header, and then write a statement that calls the module, passing 12 as an argument.

Module showValue(Integer quantity)

A

Call showValue(12)

25
Write the module called showCost that will accept the cost as a Real produces the following results: The cost is $59.99 You can assume that a main module exists and makes the following call: Module main() Declare Real x = 59.99 Call showCost(x) End Module
Module showCost (Real x) Display “The cost is $”, x End module
26
What is the difference between passing an argument by value and passing it by reference?
Passing an argument by value means that only a copy of the argument's value is passed into the parameter variable. If the contents of the parameter variable are changed inside the module, it has no effect on the argument in the calling part of the program. Passing an argument by reference means that the argument is passed into a special type of parameter known as reference variable. When a reference variable is used as a parameter in a module, it allows the module to modify the argument in the calling part of the program.
27
Why do global variables make a program difficult to debug?
Global variables make debugging difficult. Any statement in the program can change the value of the global variable. Modules that use global variables are usually dependent on those variables. Global variables make a program hard to understand.
28
A ________ structure can execute a set of statements only under certain circumstances. A.) sequence B.) circumstantial C.) decision D.) Boolean
C.) decision
29
A _______ structure provides one alternative path of execution. A.) sequence B.) single alternative decision C.) one path alternative D.) single execution decision
B.) single alternative decision
30
In pseudocode, the If-Then statement is an example of a __________. A.) sequence structure B.) decision structure C.) pathway structure D.) class structure
B.) decision structure
31
A(n) _________ expression has a value of either true or false. A.) binary B.) decision C.) unconditional D.) Boolean
D.) Boolean
32
The symbols >, <, and == are all ________ operators. A.) relational B.) logical C.) conditional D.) ternary
A.) relational
33
A(n) _________ structure tests a condition and then takes one path if the condition is true, or another path if the condition is false. A.) If-Then statement B.) single alternative decision C.) dual alternative decision D.) sequence
C.) dual alternative decision
34
You use a(n) ________ statement in pseudocode to write a single alternative decision structure. A.) Test-Jump B.) If-Then C.) If-Then-Else D.) If-Call
B.) If-Then
35
You use a(n) _________ statement in pseudocode to write a dual alternative decision structure. A.) Test-Jump B.) If-Then C.) If-Then-Else D.) If-Call
C.) If-Then-Else
36
A __________ structure allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute. A.) variable test decision B.) single alternative decision C.) dual alternative decision D.) multiple alternative decision
D.) multiple alternative decision
37
A(n) _________ section of a Select Case statement is branched to if none of the case values match the expression listed after the Select statement. A.) Else B.) Default C.) Case D.) Otherwise
B.) Default
38
AND, OR, and NOT are __________ operators. A.) relational B.) logical C.) conditional D.) ternary
B.) logical
39
A compound Boolean expression created with the _______ operator is true only if both of its subexpressions are true. A.) AND B.) OR C.) NOT D.) BOTH
A.) AND
40
A compound Boolean expression created with the ________ operator is true if either of its subexpressions is true. A.) AND B.) OR C.) NOT D.) EITHER
B.) OR
41
The _______ operator takes a Boolean expression as its operand and reverses its logical value. A.) AND B.) OR C.) NOT D.) EITHER
C.) NOT
42
The scope of a variable is the segment of the program in which the variables can be accessed. T/F
T
43
The scope of the parameter variables is the entire program and it is visible to any statement in the program T/F
T
44
The arguments in a module call and the parameters listed in the module header must be of compatible data types. T/F
T
45
A pass by ____ argument means that the argument is passed into a parameter that will reference the content of the argument in the module. Reference Constant Variable None of these Value
Reference
46
Passing an argument by ___ means that only a copy of the argument’s value is passed into the parameter variable. None of these Reference Constant Value
Constant
47
When an argument is passed by ___, it is not affected by a charge of the content of the parameter variable Value Reference None of these Constant
Value