Deck 6: User-Defined Function
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/41
Play
Full screen (f)
Deck 6: User-Defined Function
1
Functions that do not have a return type are called ____ functions.
A) zero
B) null
C) void
D) empty
A) zero
B) null
C) void
D) empty
C
2
The execution of a return statement in a user-defined function terminates the program.
False
3
The output of the statement:cout << tolower('$') << endl; is ____.
A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
A
4
The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.
A) 11.0
B) 12.0
C) 13.0
D) 14.0
A) 11.0
B) 12.0
C) 13.0
D) 14.0
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
5
Assume the following.
Static_cast('a') = 97
Static_cast('A') = 65
The output of the statement:
Cout << static_cast(tolower('B')) << endl;
Is ____.
A) 65
B) 67
C) 96
D) 98
Static_cast
Static_cast
The output of the statement:
Cout << static_cast
Is ____.
A) 65
B) 67
C) 96
D) 98
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
6
A variable listed in a header is known as a(n) ____ parameter.
A) actual
B) local
C) formal
D) function
A) actual
B) local
C) formal
D) function
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
A variable or expression listed in a call to a function is called the ____.
A) formal parameter
B) actual parameter
C) data type
D) type of the function
A) formal parameter
B) actual parameter
C) data type
D) type of the function
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
The output of the statement:cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____.
A) 6.0
B) 7.0
C) 8.0
D) 9.0
A) 6.0
B) 7.0
C) 8.0
D) 9.0
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
9
To use the predefined function tolower, the program must include the header file ____.
A)
B)
C)
D)
A)
B)
C)
D)
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
The following function heading in a C++ program is valid:int funcExp(int u, char v, float g)
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
The heading of the function is also called the ____.
A) title
B) function signature
C) function head
D) function header
A) title
B) function signature
C) function head
D) function header
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
13
The function main is always compiled first, regardless of where in the program the function main is placed.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
The following return statement returns the value 10.
return 10, 16;
return 10, 16;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
If the formal parameter list of a function is empty, the parentheses after the function name are not needed.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
16
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
17
The data type of a variable in a return statement must match the function type.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
The standard header file for the abs(x)function is ____.
A)
B)
C)
D)
A)
B)
C)
D)
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
Assume that all variables are properly declared.The following statement in a value-returning function is legal.


Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
In C++, a function prototype is the function heading without the body of the function.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
21
Given the following function:what is the output of the following statement? cout << next(next(5)) << endl;

A) 5
B) 6
C) 7
D) 8

A) 5
B) 6
C) 7
D) 8
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
The statement: return 8, 10; returns the value ____.
A) 8
B) 10
C) 18
D) 80
A) 8
B) 10
C) 18
D) 80
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ____________________ parameter.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
24
The statement: return 37, y, 2 * 3; returns the value ____.
A) 2
B) 3
C) y
D) 6
A) 2
B) 3
C) y
D) 6
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following function prototypes is valid?
A) int funcTest(int x, int y, float z){}
B) funcTest(int x, int y, float){};
C) int funcTest(int, int y, float z)
D) int funcTest(int, int, float);
A) int funcTest(int x, int y, float z){}
B) funcTest(int x, int y, float){};
C) int funcTest(int, int y, float z)
D) int funcTest(int, int, float);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
26
Which statement below about prototypes and headers is true?
A) Parameter names must be listed in the prototype, but not necessarily in the header.
B) Prototypes end with a semicolon, but headers do not.
C) Headers should come before prototypes.
D) Headers end with a semicolon, but prototypes do not.
A) Parameter names must be listed in the prototype, but not necessarily in the header.
B) Prototypes end with a semicolon, but headers do not.
C) Headers should come before prototypes.
D) Headers end with a semicolon, but prototypes do not.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
A function ____________________ is a function that is not fully coded.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
____________________ parameters are useful in three situations:• When the value of the actual parameter needs to be changed
• When you want to return more than one value from a function
• When passing the address would save memory space and time relative to copying a large amount of data
• When you want to return more than one value from a function
• When passing the address would save memory space and time relative to copying a large amount of data
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
30
Given the following function prototype: int myFunc(int, int);
Which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> myFunc(y);
B) cout << myFunc(myFunc(7, 8), 15);
C) cin >> myFunc('2', '3');
D) cout << myFunc(myFunc(7), 15);
Which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> myFunc(y);
B) cout << myFunc(myFunc(7, 8), 15);
C) cin >> myFunc('2', '3');
D) cout << myFunc(myFunc(7), 15);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following function prototypes is valid?
A) int funcExp(int x, float v);
B) funcExp(int x, float v){};
C) funcExp(void);
D) int funcExp(x);
A) int funcExp(int x, float v);
B) funcExp(int x, float v){};
C) funcExp(void);
D) int funcExp(x);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
32
Given the following function:what is the output of the following statement? cout << strange(4, 5) << endl;

A) -1
B) 1
C) 9
D) 20

A) -1
B) 1
C) 9
D) 20
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
Given the following function prototype: int test(float, char);
Which of the following statements is valid?
A) cout << test(12, &);
B) cout << test("12.0", '&');
C) int u = test(5.0, '*');
D) cout << test('12', '&');
Which of the following statements is valid?
A) cout << test(12, &);
B) cout << test("12.0", '&');
C) int u = test(5.0, '*');
D) cout << test('12', '&');
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
Given the following function prototype: double tryMe(double, double);
Which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> tryMe(x);
B) cout << tryMe(2.0, 3.0);
C) cout << tryMe(tryMe(double, double), double);
D) cout << tryMe(tryMe(float, float), float);
Which of the following statements is valid? Assume that all variables are properly declared.
A) cin >> tryMe(x);
B) cout << tryMe(2.0, 3.0);
C) cout << tryMe(tryMe(double, double), double);
D) cout << tryMe(tryMe(float, float), float);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
What value is returned by the following return statement? int x = 5;
Return x + 1;
A) 0
B) 5
C) 6
D) 7
Return x + 1;
A) 0
B) 5
C) 6
D) 7
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
A function prototype is ____.
A) a definition, but not a declaration
B) a declaration and a definition
C) a declaration, but not a definition
D) a comment line
A) a definition, but not a declaration
B) a declaration and a definition
C) a declaration, but not a definition
D) a comment line
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
38
Given the function prototype: double testAlpha(int u, char v, double t);
Which of the following statements is legal?
A) cout << testAlpha(5, 'A', 2);
B) cout << testAlpha( int 5, char 'A', int 2);
C) cout << testAlpha('5.0', 'A', '2.0');
D) cout << testAlpha(5.0, "65", 2.0);
Which of the following statements is legal?
A) cout << testAlpha(5, 'A', 2);
B) cout << testAlpha( int 5, char 'A', int 2);
C) cout << testAlpha('5.0', 'A', '2.0');
D) cout << testAlpha(5.0, "65", 2.0);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
Given the function prototype:float test(int, int, int); which of the following statements is legal?
A) cout << test(7, test(14, 23));
B) cout << test(test(7, 14), 23);
C) cout << test(14, 23);
D) cout << test(7, 14, 23);
A) cout << test(7, test(14, 23));
B) cout << test(test(7, 14), 23);
C) cout << test(14, 23);
D) cout << test(7, 14, 23);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.
A) 2
B) 3
C) 6
D) 7
A) 2
B) 3
C) 6
D) 7
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
The ____________________ of a function consists of the function name and its formal parameter list.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck