Deck 6: User-Defined Functions

Full screen (f)
exit full mode
Question
To use the predefined function tolower,the program must include the header file ____.

A)
B)
C)
D)
Use Space or
up arrow
down arrow
to flip the card.
Question
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
Question
The data type of a variable in a return statement must match the function type.
Question
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
Question
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
Question
The function main is always compiled first,regardless of where in the program the function main is placed.
Question
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
Question
Assume that all variables are properly declared.The following statement in a value-returning function is legal.
if (x % 2 == 0)
return x;
else
return x + 1;
Question
The execution of a return statement in a user-defined function terminates the program.
Question
The following return statement returns the value 10.
return 10,16;
Question
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
Question
The heading of the function is also called the ____.

A) title
B) function signature
C) function head
D) function header
Question
Functions that do not have a return type are called ____ functions.

A) zero
B) null
C) void
D) empty
Question
The following function heading in a C++ program is valid:
int funcExp(int u,char v,float g)
Question
In C++,a function prototype is the function heading without the body of the function.
Question
If the formal parameter list of a function is empty,the parentheses after the function name are not needed.
Question
The output of the statement: cout << tolower('$')<< endl;
Is ____.

A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
Question
The standard header file for the abs(x)function is ____.

A)
B)
C)
D)
Question
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.
Question
A variable listed in a header is known as a(n)____ parameter.

A) actual
B) local
C) formal
D) function
Question
The statement: return 8,10; returns the value ____.

A) 8
B) 10
C) 18
D) 80
Question
The statement: return 37,y,2 * 3; returns the value ____.

A) 2
B) 3
C) y
D) 6
Question
The statement: return 2 * 3 + 1,1 + 5; returns the value ____.

A) 2
B) 3
C) 6
D) 7
Question
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);
Question
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.
Question
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);
Question
____________________ 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
Question
What value is returned by the following return statement? int x = 5;
Return x + 1;

A) 0
B) 5
C) 6
D) 7
Question
A(n)____________________ parameter is a formal parameter that receives the location (memory address)of the corresponding actual parameter.
Question
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
Question
If a formal parameter is a nonconstant reference parameter,during a function call,its corresponding actual parameter must be a(n)____________________.
Question
A(n)____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.
Question
When you attach & after the dataType in the formal parameter list of a function,the variable following that dataType becomes a(n)____________________ parameter.
Question
Given the following function: int strange(int x,int y)
{
If (x > y)
Return x + y;
Else
Return x - y;
}
What is the output of the following statement?
Cout << strange(4,5)<< endl;

A) -1
B) 1
C) 9
D) 20
Question
Given the following function: int next(int x)
{
Return (x + 1);
}
What is the output of the following statement?
Cout << next(next(5))<< endl;

A) 5
B) 6
C) 7
D) 8
Question
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);
Question
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);
Question
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', '&');
Question
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);
Question
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);
Question
A variable for which memory remains allocated as long as the program executes is called a(n)____________________ variable.
Question
____________________ identifiers are not accessible outside of the function (block).
Question
In C++,:: is called the ____________________.
Question
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.
Question
A function ____________________ is a function that is not fully coded.
Question
The ____________________ of an identifier refers to where in the program an identifier is accessible (visible).
Question
The ____________________ of a function consists of the function name and its formal parameter list.
Question
A variable for which memory is allocated at block entry and deallocated at block exit is called a(n)____________________ variable.
Question
Stream variables (for example,ifstream and ofstream)should be passed by ____________________ to a function.
Question
The program that tests a function is called a(n)____________________ program.
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 6: User-Defined Functions
1
To use the predefined function tolower,the program must include the header file ____.

A)
B)
C)
D)
A
2
Using functions greatly enhances a program's readability because it reduces the complexity of the function main.
True
3
The data type of a variable in a return statement must match the function type.
True
4
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
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 50 flashcards in this deck.
Unlock Deck
k this deck
7
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Assume that all variables are properly declared.The following statement in a value-returning function is legal.
if (x % 2 == 0)
return x;
else
return x + 1;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The execution of a return statement in a user-defined function terminates the program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The following return statement returns the value 10.
return 10,16;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 50 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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
Functions that do not have a return type are called ____ functions.

A) zero
B) null
C) void
D) empty
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
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 50 flashcards in this deck.
Unlock Deck
k this deck
15
In C++,a function prototype is the function heading without the body of the function.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
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 50 flashcards in this deck.
Unlock Deck
k this deck
17
The output of the statement: cout << tolower('$')<< endl;
Is ____.

A) '$'
B) '0'
C) '1'
D) An error, because you cannot use tolower with '$'.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
The standard header file for the abs(x)function is ____.

A)
B)
C)
D)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
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 50 flashcards in this deck.
Unlock Deck
k this deck
20
A variable listed in a header is known as a(n)____ parameter.

A) actual
B) local
C) formal
D) function
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
The statement: return 8,10; returns the value ____.

A) 8
B) 10
C) 18
D) 80
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
The statement: return 37,y,2 * 3; returns the value ____.

A) 2
B) 3
C) y
D) 6
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
The statement: return 2 * 3 + 1,1 + 5; returns the value ____.

A) 2
B) 3
C) 6
D) 7
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
____________________ 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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What value is returned by the following return statement? int x = 5;
Return x + 1;

A) 0
B) 5
C) 6
D) 7
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
A(n)____________________ parameter is a formal parameter that receives the location (memory address)of the corresponding actual parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
If a formal parameter is a nonconstant reference parameter,during a function call,its corresponding actual parameter must be a(n)____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
A(n)____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
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 50 flashcards in this deck.
Unlock Deck
k this deck
34
Given the following function: int strange(int x,int y)
{
If (x > y)
Return x + y;
Else
Return x - y;
}
What is the output of the following statement?
Cout << strange(4,5)<< endl;

A) -1
B) 1
C) 9
D) 20
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Given the following function: int next(int x)
{
Return (x + 1);
}
What is the output of the following statement?
Cout << next(next(5))<< endl;

A) 5
B) 6
C) 7
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
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', '&');
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
A variable for which memory remains allocated as long as the program executes is called a(n)____________________ variable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
____________________ identifiers are not accessible outside of the function (block).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
In C++,:: is called the ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
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 50 flashcards in this deck.
Unlock Deck
k this deck
45
A function ____________________ is a function that is not fully coded.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
The ____________________ of an identifier refers to where in the program an identifier is accessible (visible).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
The ____________________ of a function consists of the function name and its formal parameter list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
A variable for which memory is allocated at block entry and deallocated at block exit is called a(n)____________________ variable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Stream variables (for example,ifstream and ofstream)should be passed by ____________________ to a function.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
The program that tests a function is called a(n)____________________ program.
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.