Deck 6: Functions

ملء الشاشة (f)
exit full mode
سؤال
A local variable and a global variable may not have the same name within a program.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Functions are ideal for menu-driven programs. When the user selects a menu item, the program can __________ the appropriate function.

A) call
B) append
C) define
D) declare
E) None of these
سؤال
A collection of statements that performs a specific task is a(n)

A) infinite loop
B) variable
C) constant
D) function
E) decision
سؤال
These types of arguments are passed to parameters automatically if no argument is provided in the function call.

A) local
B) default
C) global
D) reference
E) None of these
سؤال
A function __________ contains the statements that make up the function.

A) prototype
B) definition
C) call
D) expression
E) parameter list
سؤال
This type of variable is defined inside a function and is not accessible outside the function.

A) global
B) reference
C) local
D) counter
E) None of these
سؤال
A function can have no parameters, one parameter, or many parameters and can return __________ value(s).

A) zero to many
B) no
C) only one
D) a maximum of ten
E) None of these
سؤال
A function's return data type must be the same as the function's parameters.
سؤال
You must always furnish an argument with a function call.
سؤال
Global variables are initialized to zero by default.
سؤال
It is not considered good programming practice to declare all your variables globally.
سؤال
The value in this type of variable persists between function calls.

A) global
B) internal
C) static
D) dynamic
E) None of these
سؤال
A static variable that is defined within a function is initalized only once, the first time it is called.
سؤال
It is possible for a function to have some parameters with default arguments and some without.
سؤال
Local variables are initialized to zero by default.
سؤال
You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
سؤال
A parameter is a special purpose variable that is declared inside the parentheses of a function definition.
سؤال
A function is executed when it is

A) defined
B) prototyped
C) declared
D) called
E) None of these
سؤال
When a function is called, flow of control moves to the function's prototype.
سؤال
One reason for using functions is to break programs into manageable units or modules.
سؤال
What will the following code display?
#include
Using namespace std;
Void showDub(int);
Int main()
{
Int x = 2;
ShowDub(x);
Cout << x << endl;
Return 0;
}
Void showDub(int num)
{
Cout << (num * 2) << endl;
}

A) 2
2
B) 4
2
C) 2
4
D) 4
4
سؤال
A __________ argument is passed to a parameter when the actual argument is left out of the function.

A) False
B) true
C) null
D) default
E) None of these
سؤال
What will the following code display?
#include
Using namespace std;
Void doSomething(int&);
Int main()
{
Int x = 2;
Cout << x << endl;
DoSomething(x);
Cout << x << endl;
Return 0;
}
Void doSomething(int& num)
{
Num = 0;
Cout << num << endl;
}

A) 2
0
2
B) 2
2
2
C) 0
0
0
D) 2
0
0
سؤال
It is good programming practice to __________ your functions by writing comments that describe what they do.

A) execute
B) document
C) retrieve
D) create
E) None of these
سؤال
This statement causes a function to end.

A) end
B) terminate
C) return
D) release
E) None of these
سؤال
A function _________ eliminates the need to place a function definition before all calls to the function.

A) header
B) prototype
C) argument
D) parameter
E) None of these
سؤال
If a function is called more than once in a program, the values stored in the function's local variables do not _________ between function calls.

A) persist
B) execute
C) communicate
D) change
E) None of these
سؤال
A _________ variable is declared outside all functions.

A) local
B) global
C) floating-point
D) counter
E) None of these
سؤال
The value in a __________ variable persists between function calls.

A) dynamic
B) global
C) floating-point
D) static local
E) counter
سؤال
This is a dummy function that is called instead of the actual function it represents:

A) main
B) stub
C) a driver
D) an overloaded function
سؤال
Which of the following causes a function to execute?

A) a for loop
B) a do-while loop
C) a function prototype
D) a function call
E) None of these
سؤال
A(n) __________ is information that is passed to a function, and a(n) __________ is information that is received by a function.

A) function call, function header
B) parameter, argument
C) argument, parameter
D) prototype, header
E) None of these
سؤال
EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

A) EXIT_TERMINATE
B) EXIT_SUCCESS
C) EXIT_OK
D) RETURN_OK
سؤال
When used as parameters, these types of variables allow a function to access the parameter's original argument:

A) reference
B) floating-point
C) counter
D) undeclared
E) None of these
سؤال
Given the following function:
Void calc (int a, int& b)
{
Int c;
C = a + 2;
A = a * 3;
B = c + a;
}
What is the output of the following code segment that invokes calc():
Int x = 1;
Int y = 2;
Int z = 3;
Calc(x, y);
Cout << x << " " << y << " " << z << endl;

A) 1 2 3
B) 1 6 3
C) 3 6 3
D) 1 14 9
E) 2 3 4 5
سؤال
If a function does not have a prototype, default arguments may be specified in the __________.

A) function call
B) function header
C) execution
D) return type
E) None of these
سؤال
Which line in the following program contains the prototype showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
سؤال
__________ functions may have the same name as long as their parameter lists are different.

A) Only two
B) Two or more
C) No
D) Un-prototyped
E) None of these
سؤال
This function causes a program to terminate, regardless of which function or control mechanism is executing.

A) exit()
B) terminate()
C) return()
D) continue()
E) None of these
سؤال
What will the following code display?
#include
Using namespace std;
Void doSomething(int);
Int main()
{
Int x = 2;
Cout << x << endl;
DoSomething(x);
Cout << x << endl;
Return 0;
}
Void doSomething(int num)
{
Num = 0;
Cout << num << endl;
}

A) 2
0
2
B) 2
2
2
C) 0
0
0
D) 2
0
0
سؤال
What is the data type of the following function prototype's return value?
Int myFunction(double);

A) int
B) double
C) void
D) cannot tell from the prototype
سؤال
Select all that apply. Which of the following statement(s) about global variables is(are) true?

A) A global variable is accessible only to the main function.
B) A global variable is declared in the highest-level block in which it is used.
C) A global variable can have the same name as a variable that is declared locally within a function.
D) A global variable is the same as a named constant.
E) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function.
سؤال
Which line in the following program contains the header for the showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
سؤال
Which line in the following program contains a call to the showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
سؤال
What will the following code display?
#include
Using namespace std;
Int getValue(int);
Int main()
{
Int x = 2;
Cout << getValue(x) << endl;
Return 0;
}
Int getValue(int num)
{
Return num + 5;
}

A) 5
B) 2
C) 7
D) getValue(x)
سؤال
Given the following header for a function named computeValue, which of the following is a valid call to the function?
Void computeValue(int value)

A) computeValue(10)
B) computeValue(10);
C) void computeValue(10);
D) void computeValue(int x);
سؤال
Select all that apply. Which of the following must be included in a function header?

A) the data type of each parameter
B) the data type of the return value
C) the name of the function
D) the names of parameter variables
سؤال
In the following function prototype, how many parameter variables does this function have?
Int myFunction(double, double, double);

A) 1
B) 2
C) 3
D) cannot tell from the prototype
سؤال
What is the data type of the following function prototype's parameter variable?
Int myFunction(double);

A) int
B) double
C) void
D) cannot tell from the prototype
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/49
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 6: Functions
1
A local variable and a global variable may not have the same name within a program.
False
2
Functions are ideal for menu-driven programs. When the user selects a menu item, the program can __________ the appropriate function.

A) call
B) append
C) define
D) declare
E) None of these
A
3
A collection of statements that performs a specific task is a(n)

A) infinite loop
B) variable
C) constant
D) function
E) decision
D
4
These types of arguments are passed to parameters automatically if no argument is provided in the function call.

A) local
B) default
C) global
D) reference
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
5
A function __________ contains the statements that make up the function.

A) prototype
B) definition
C) call
D) expression
E) parameter list
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
6
This type of variable is defined inside a function and is not accessible outside the function.

A) global
B) reference
C) local
D) counter
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
7
A function can have no parameters, one parameter, or many parameters and can return __________ value(s).

A) zero to many
B) no
C) only one
D) a maximum of ten
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
8
A function's return data type must be the same as the function's parameters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
9
You must always furnish an argument with a function call.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
10
Global variables are initialized to zero by default.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
11
It is not considered good programming practice to declare all your variables globally.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
12
The value in this type of variable persists between function calls.

A) global
B) internal
C) static
D) dynamic
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
13
A static variable that is defined within a function is initalized only once, the first time it is called.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
14
It is possible for a function to have some parameters with default arguments and some without.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
15
Local variables are initialized to zero by default.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
16
You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
17
A parameter is a special purpose variable that is declared inside the parentheses of a function definition.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
18
A function is executed when it is

A) defined
B) prototyped
C) declared
D) called
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
19
When a function is called, flow of control moves to the function's prototype.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
20
One reason for using functions is to break programs into manageable units or modules.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
21
What will the following code display?
#include
Using namespace std;
Void showDub(int);
Int main()
{
Int x = 2;
ShowDub(x);
Cout << x << endl;
Return 0;
}
Void showDub(int num)
{
Cout << (num * 2) << endl;
}

A) 2
2
B) 4
2
C) 2
4
D) 4
4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
22
A __________ argument is passed to a parameter when the actual argument is left out of the function.

A) False
B) true
C) null
D) default
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
23
What will the following code display?
#include
Using namespace std;
Void doSomething(int&);
Int main()
{
Int x = 2;
Cout << x << endl;
DoSomething(x);
Cout << x << endl;
Return 0;
}
Void doSomething(int& num)
{
Num = 0;
Cout << num << endl;
}

A) 2
0
2
B) 2
2
2
C) 0
0
0
D) 2
0
0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
24
It is good programming practice to __________ your functions by writing comments that describe what they do.

A) execute
B) document
C) retrieve
D) create
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
25
This statement causes a function to end.

A) end
B) terminate
C) return
D) release
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
26
A function _________ eliminates the need to place a function definition before all calls to the function.

A) header
B) prototype
C) argument
D) parameter
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
27
If a function is called more than once in a program, the values stored in the function's local variables do not _________ between function calls.

A) persist
B) execute
C) communicate
D) change
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
28
A _________ variable is declared outside all functions.

A) local
B) global
C) floating-point
D) counter
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
29
The value in a __________ variable persists between function calls.

A) dynamic
B) global
C) floating-point
D) static local
E) counter
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
30
This is a dummy function that is called instead of the actual function it represents:

A) main
B) stub
C) a driver
D) an overloaded function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following causes a function to execute?

A) a for loop
B) a do-while loop
C) a function prototype
D) a function call
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
32
A(n) __________ is information that is passed to a function, and a(n) __________ is information that is received by a function.

A) function call, function header
B) parameter, argument
C) argument, parameter
D) prototype, header
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
33
EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

A) EXIT_TERMINATE
B) EXIT_SUCCESS
C) EXIT_OK
D) RETURN_OK
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
34
When used as parameters, these types of variables allow a function to access the parameter's original argument:

A) reference
B) floating-point
C) counter
D) undeclared
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
35
Given the following function:
Void calc (int a, int& b)
{
Int c;
C = a + 2;
A = a * 3;
B = c + a;
}
What is the output of the following code segment that invokes calc():
Int x = 1;
Int y = 2;
Int z = 3;
Calc(x, y);
Cout << x << " " << y << " " << z << endl;

A) 1 2 3
B) 1 6 3
C) 3 6 3
D) 1 14 9
E) 2 3 4 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
36
If a function does not have a prototype, default arguments may be specified in the __________.

A) function call
B) function header
C) execution
D) return type
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
37
Which line in the following program contains the prototype showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
38
__________ functions may have the same name as long as their parameter lists are different.

A) Only two
B) Two or more
C) No
D) Un-prototyped
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
39
This function causes a program to terminate, regardless of which function or control mechanism is executing.

A) exit()
B) terminate()
C) return()
D) continue()
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
40
What will the following code display?
#include
Using namespace std;
Void doSomething(int);
Int main()
{
Int x = 2;
Cout << x << endl;
DoSomething(x);
Cout << x << endl;
Return 0;
}
Void doSomething(int num)
{
Num = 0;
Cout << num << endl;
}

A) 2
0
2
B) 2
2
2
C) 0
0
0
D) 2
0
0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
41
What is the data type of the following function prototype's return value?
Int myFunction(double);

A) int
B) double
C) void
D) cannot tell from the prototype
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
42
Select all that apply. Which of the following statement(s) about global variables is(are) true?

A) A global variable is accessible only to the main function.
B) A global variable is declared in the highest-level block in which it is used.
C) A global variable can have the same name as a variable that is declared locally within a function.
D) A global variable is the same as a named constant.
E) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
43
Which line in the following program contains the header for the showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
44
Which line in the following program contains a call to the showDub function?
1 #include
2 using namespace std;
3 void showDub(int);
4 int main()
5 {
6 int x = 2;
7 showDub(x);
8 cout << x << endl;
9 return 0;
10 }
11 void showDub(int num)
12 {
13 cout << (num * 2) << endl;
14 }

A) line 3
B) line 4
C) line 7
D) line 11
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
45
What will the following code display?
#include
Using namespace std;
Int getValue(int);
Int main()
{
Int x = 2;
Cout << getValue(x) << endl;
Return 0;
}
Int getValue(int num)
{
Return num + 5;
}

A) 5
B) 2
C) 7
D) getValue(x)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
46
Given the following header for a function named computeValue, which of the following is a valid call to the function?
Void computeValue(int value)

A) computeValue(10)
B) computeValue(10);
C) void computeValue(10);
D) void computeValue(int x);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
47
Select all that apply. Which of the following must be included in a function header?

A) the data type of each parameter
B) the data type of the return value
C) the name of the function
D) the names of parameter variables
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
48
In the following function prototype, how many parameter variables does this function have?
Int myFunction(double, double, double);

A) 1
B) 2
C) 3
D) cannot tell from the prototype
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
49
What is the data type of the following function prototype's parameter variable?
Int myFunction(double);

A) int
B) double
C) void
D) cannot tell from the prototype
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 49 في هذه المجموعة.