Deck 11: Using Templates

Full screen (f)
exit full mode
Question
The keyword ____ can replace class in a template definition in some C++ compilers.

A) struct
B) generic
C) template
D) typename
Use Space or
up arrow
down arrow
to flip the card.
Question
To create a function template that employs multiple generic types, you simply use a(n) ____ for each type.

A) #include statement
B) function prototype
C) unique type identifier
D) separate template class
Question
Function templates serve as an outline or pattern for a group of functions that differ in the types of parameters they use.
Question
You ____ functions when you create functions with the same name but with different argument lists.

A) abstract
B) replace
C) overload
D) override
Question
To create a class template, you begin with the template ____.

A) implementation
B) prototype
C) declaration
D) definition
Question
You can use multiple explicit types when you call a template function.
Question
A ____ is a data structure in which elements are removed in the same order they were entered.

A) queue
B) list
C) stack
D) vector
Question
Complete the following function template:
____
T reverse(T x)
{
Return -x;
}

A) template : class T
B) template
C) template (class T)
D) template {class T}
Question
The purpose of container classes is to manage groups of other classes.
Question
In template , T stands for a programmer created class.
Question
Function templates ____ support multiple parameters.

A) can
B) cannot
C) sometimes
D) should not
Question
Function templates cannot use variables of multiple types.
Question
The option of using multiple types in a function template is available on all C++ compilers.
Question
You can overload function templates only when each version of the function takes a different parameter list.
Question
A(n) ____ is one that can stand for any number of C++ types.

A) abstract data type
B) generic parameter
C) structure
D) container class
Question
If doubleVal() is a function template that takes one parameterized type, doubleVal (a) is exactly the same as ____.

A) doubleVal( a)
B) doubleVal (a)
C) doubleVal(a)
D) doubleVal (a)
Question
The ____ operator is automatically defined for classes you create, but you can also overload it.

A) %
B) =
C) +
D) >>
Question
The function call ____ specifies that someFunction 's parameterized type (for example, T ) will be char , no matter what type someArgument is.

A) someFunction:char(someArgument);
B) someFunction (someArgument);
C) someFunction((char) someArgument);
D) someFunction{char}(someArgument);
Question
The terms template function and ____ are often used interchangeably.

A) template class
B) generic method
C) function template
D) class template
Question
Consider the following function template:
Template
Void repeatValue(T val, int times)
{
Int x;
For(x = 0; x
Which of the following statements is true?

A) No restrictions apply.
B) Any type of object from a user defined class can be displayed the specified number of times.
C) It can be called only with primitive data types.
D) Any type of object can be displayed the specified number of times as long as the << operator is defined for the object's data type.
Question
What happens when you call a function template?
Question
The designation of the parameterized type is ____________________; that is, it is determined not by naming the type, but by the compiler's ability to determine the argument type.
Question
You can calculate the size of an array (the number of elements) called nums as follows ____.

A) sizeof(nums)
B) nums.length
C) nums.length()
D) sizeof(nums)/sizeof(nums[0]);
Question
In Java, C#, and Smalltalk, all objects derive from the same container class, called ____.

A) Object
B) Container
C) Base
D) Class
Question
FIFO stands for ____________________.
Question
A(n) ____ is a template class that has been written to perform common class tasks.

A) parameterized argument
B) abstract data type
C) container class
D) generic class
Question
Where in your program can you place function templates? Do any restrictions apply?
Question
Because a generic linked list class is so useful, the developers of C++ have already created such a container class: its name is ____, and it contains functions such as merge() and reverse() .

A) set
B) list
C) linkedList
D) vector
Question
Write a function template that compares three parameters and returns the largest of the three.
Question
The subscript for any array can hold a value of 0 through ____.

A) 1
B) the array size
C) 1 less than the array's size
D) 1 more than the array's size
Question
Different versions of ____________________ function templates do not need to use the same identifier to stand in for the variable type or class.
Question
LIFO stands for ____________________.
Question
Provide an example of an overloaded function template.
Question
Explain why overloading can sometimes require a lot of unnecessary, tedious coding.
Question
When you create a(n) ____, you create a list of same-type objects at adjacent memory locations.

A) array
B) linked list
C) queue
D) stack
Question
Which of the following is not a common task to perform with an array?

A) Display an element in a specified position in the array.
B) Reverse the order of elements in an array.
C) Convert the array to a stack.
D) Sort the elements in an array in ascending or descending order.
Question
The terms template class and ____________________ are often used interchangeably.
Question
When using function templates, you can code empty angle brackets after the function name in a function call to indicate that the types should be deduced and not ____________________.
Question
A ____ is a data structure in which elements are removed in the reverse order from which they were entered.

A) queue
B) list
C) stack
D) vector
Question
What are macros? Should you use them?
Question
Match between columns
chain of objects
stack
chain of objects
family of functions
chain of objects
function template
chain of objects
linked list
chain of objects
class template
chain of objects
queue
chain of objects
generic parameter
chain of objects
template class
chain of objects
template function
Question
Match between columns
data structure in which elements are removed in LIFO order
stack
data structure in which elements are removed in LIFO order
family of functions
data structure in which elements are removed in LIFO order
function template
data structure in which elements are removed in LIFO order
linked list
data structure in which elements are removed in LIFO order
class template
data structure in which elements are removed in LIFO order
queue
data structure in which elements are removed in LIFO order
generic parameter
data structure in which elements are removed in LIFO order
template class
data structure in which elements are removed in LIFO order
template function
Question
Match between columns
data structure in which elements are removed in FIFO order
stack
data structure in which elements are removed in FIFO order
family of functions
data structure in which elements are removed in FIFO order
function template
data structure in which elements are removed in FIFO order
linked list
data structure in which elements are removed in FIFO order
class template
data structure in which elements are removed in FIFO order
queue
data structure in which elements are removed in FIFO order
generic parameter
data structure in which elements are removed in FIFO order
template class
data structure in which elements are removed in FIFO order
template function
Question
When is explicitly specifying a type for the parameterized type useful?
Question
Match between columns
is generated by a class template
stack
is generated by a class template
family of functions
is generated by a class template
function template
is generated by a class template
linked list
is generated by a class template
class template
is generated by a class template
queue
is generated by a class template
generic parameter
is generated by a class template
template class
is generated by a class template
template function
Question
At a minimum, what components should a linked list element have?
Question
Write the class definition for a Number class that has one data member which can hold any number, a constructor that takes an argument, and a displayNumber() function.
Question
Match between columns
class in which at least one type is generic or parameterized
stack
class in which at least one type is generic or parameterized
family of functions
class in which at least one type is generic or parameterized
function template
class in which at least one type is generic or parameterized
linked list
class in which at least one type is generic or parameterized
class template
class in which at least one type is generic or parameterized
queue
class in which at least one type is generic or parameterized
generic parameter
class in which at least one type is generic or parameterized
template class
class in which at least one type is generic or parameterized
template function
Question
Match between columns
is generated by a function template
stack
is generated by a function template
family of functions
is generated by a function template
function template
is generated by a function template
linked list
is generated by a function template
class template
is generated by a function template
queue
is generated by a function template
generic parameter
is generated by a function template
template class
is generated by a function template
template function
Question
Match between columns
can stand for any number of C++ types
stack
can stand for any number of C++ types
family of functions
can stand for any number of C++ types
function template
can stand for any number of C++ types
linked list
can stand for any number of C++ types
class template
can stand for any number of C++ types
queue
can stand for any number of C++ types
generic parameter
can stand for any number of C++ types
template class
can stand for any number of C++ types
template function
Question
Match between columns
group of functions that generates from the same template
stack
group of functions that generates from the same template
family of functions
group of functions that generates from the same template
function template
group of functions that generates from the same template
linked list
group of functions that generates from the same template
class template
group of functions that generates from the same template
queue
group of functions that generates from the same template
generic parameter
group of functions that generates from the same template
template class
group of functions that generates from the same template
template function
Question
Create a displayAndCompare() function that displays two values, compares them, and displays a message indicating which is larger. The function works when any two parameters are passed, whether or not the two parameters are of the same type, as long as > and == are defined correctly for the parameters.
Question
What are common uses of template classes?
Question
Match between columns
function that uses variable data types
stack
function that uses variable data types
family of functions
function that uses variable data types
function template
function that uses variable data types
linked list
function that uses variable data types
class template
function that uses variable data types
queue
function that uses variable data types
generic parameter
function that uses variable data types
template class
function that uses variable data types
template function
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/54
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Using Templates
1
The keyword ____ can replace class in a template definition in some C++ compilers.

A) struct
B) generic
C) template
D) typename
D
2
To create a function template that employs multiple generic types, you simply use a(n) ____ for each type.

A) #include statement
B) function prototype
C) unique type identifier
D) separate template class
C
3
Function templates serve as an outline or pattern for a group of functions that differ in the types of parameters they use.
True
4
You ____ functions when you create functions with the same name but with different argument lists.

A) abstract
B) replace
C) overload
D) override
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
5
To create a class template, you begin with the template ____.

A) implementation
B) prototype
C) declaration
D) definition
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
6
You can use multiple explicit types when you call a template function.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
7
A ____ is a data structure in which elements are removed in the same order they were entered.

A) queue
B) list
C) stack
D) vector
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
8
Complete the following function template:
____
T reverse(T x)
{
Return -x;
}

A) template : class T
B) template
C) template (class T)
D) template {class T}
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
9
The purpose of container classes is to manage groups of other classes.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
10
In template , T stands for a programmer created class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
11
Function templates ____ support multiple parameters.

A) can
B) cannot
C) sometimes
D) should not
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
12
Function templates cannot use variables of multiple types.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
13
The option of using multiple types in a function template is available on all C++ compilers.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
14
You can overload function templates only when each version of the function takes a different parameter list.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
15
A(n) ____ is one that can stand for any number of C++ types.

A) abstract data type
B) generic parameter
C) structure
D) container class
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
16
If doubleVal() is a function template that takes one parameterized type, doubleVal (a) is exactly the same as ____.

A) doubleVal( a)
B) doubleVal (a)
C) doubleVal(a)
D) doubleVal (a)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
17
The ____ operator is automatically defined for classes you create, but you can also overload it.

A) %
B) =
C) +
D) >>
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
18
The function call ____ specifies that someFunction 's parameterized type (for example, T ) will be char , no matter what type someArgument is.

A) someFunction:char(someArgument);
B) someFunction (someArgument);
C) someFunction((char) someArgument);
D) someFunction{char}(someArgument);
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
19
The terms template function and ____ are often used interchangeably.

A) template class
B) generic method
C) function template
D) class template
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
20
Consider the following function template:
Template
Void repeatValue(T val, int times)
{
Int x;
For(x = 0; x
Which of the following statements is true?

A) No restrictions apply.
B) Any type of object from a user defined class can be displayed the specified number of times.
C) It can be called only with primitive data types.
D) Any type of object can be displayed the specified number of times as long as the << operator is defined for the object's data type.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
21
What happens when you call a function template?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
22
The designation of the parameterized type is ____________________; that is, it is determined not by naming the type, but by the compiler's ability to determine the argument type.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
23
You can calculate the size of an array (the number of elements) called nums as follows ____.

A) sizeof(nums)
B) nums.length
C) nums.length()
D) sizeof(nums)/sizeof(nums[0]);
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
24
In Java, C#, and Smalltalk, all objects derive from the same container class, called ____.

A) Object
B) Container
C) Base
D) Class
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
25
FIFO stands for ____________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
26
A(n) ____ is a template class that has been written to perform common class tasks.

A) parameterized argument
B) abstract data type
C) container class
D) generic class
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
27
Where in your program can you place function templates? Do any restrictions apply?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
28
Because a generic linked list class is so useful, the developers of C++ have already created such a container class: its name is ____, and it contains functions such as merge() and reverse() .

A) set
B) list
C) linkedList
D) vector
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
29
Write a function template that compares three parameters and returns the largest of the three.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
30
The subscript for any array can hold a value of 0 through ____.

A) 1
B) the array size
C) 1 less than the array's size
D) 1 more than the array's size
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
31
Different versions of ____________________ function templates do not need to use the same identifier to stand in for the variable type or class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
32
LIFO stands for ____________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
33
Provide an example of an overloaded function template.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
34
Explain why overloading can sometimes require a lot of unnecessary, tedious coding.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
35
When you create a(n) ____, you create a list of same-type objects at adjacent memory locations.

A) array
B) linked list
C) queue
D) stack
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is not a common task to perform with an array?

A) Display an element in a specified position in the array.
B) Reverse the order of elements in an array.
C) Convert the array to a stack.
D) Sort the elements in an array in ascending or descending order.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
37
The terms template class and ____________________ are often used interchangeably.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
38
When using function templates, you can code empty angle brackets after the function name in a function call to indicate that the types should be deduced and not ____________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
39
A ____ is a data structure in which elements are removed in the reverse order from which they were entered.

A) queue
B) list
C) stack
D) vector
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
40
What are macros? Should you use them?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
chain of objects
stack
chain of objects
family of functions
chain of objects
function template
chain of objects
linked list
chain of objects
class template
chain of objects
queue
chain of objects
generic parameter
chain of objects
template class
chain of objects
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
data structure in which elements are removed in LIFO order
stack
data structure in which elements are removed in LIFO order
family of functions
data structure in which elements are removed in LIFO order
function template
data structure in which elements are removed in LIFO order
linked list
data structure in which elements are removed in LIFO order
class template
data structure in which elements are removed in LIFO order
queue
data structure in which elements are removed in LIFO order
generic parameter
data structure in which elements are removed in LIFO order
template class
data structure in which elements are removed in LIFO order
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
data structure in which elements are removed in FIFO order
stack
data structure in which elements are removed in FIFO order
family of functions
data structure in which elements are removed in FIFO order
function template
data structure in which elements are removed in FIFO order
linked list
data structure in which elements are removed in FIFO order
class template
data structure in which elements are removed in FIFO order
queue
data structure in which elements are removed in FIFO order
generic parameter
data structure in which elements are removed in FIFO order
template class
data structure in which elements are removed in FIFO order
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
44
When is explicitly specifying a type for the parameterized type useful?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
45
Match between columns
is generated by a class template
stack
is generated by a class template
family of functions
is generated by a class template
function template
is generated by a class template
linked list
is generated by a class template
class template
is generated by a class template
queue
is generated by a class template
generic parameter
is generated by a class template
template class
is generated by a class template
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
46
At a minimum, what components should a linked list element have?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
47
Write the class definition for a Number class that has one data member which can hold any number, a constructor that takes an argument, and a displayNumber() function.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
class in which at least one type is generic or parameterized
stack
class in which at least one type is generic or parameterized
family of functions
class in which at least one type is generic or parameterized
function template
class in which at least one type is generic or parameterized
linked list
class in which at least one type is generic or parameterized
class template
class in which at least one type is generic or parameterized
queue
class in which at least one type is generic or parameterized
generic parameter
class in which at least one type is generic or parameterized
template class
class in which at least one type is generic or parameterized
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
is generated by a function template
stack
is generated by a function template
family of functions
is generated by a function template
function template
is generated by a function template
linked list
is generated by a function template
class template
is generated by a function template
queue
is generated by a function template
generic parameter
is generated by a function template
template class
is generated by a function template
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
can stand for any number of C++ types
stack
can stand for any number of C++ types
family of functions
can stand for any number of C++ types
function template
can stand for any number of C++ types
linked list
can stand for any number of C++ types
class template
can stand for any number of C++ types
queue
can stand for any number of C++ types
generic parameter
can stand for any number of C++ types
template class
can stand for any number of C++ types
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
group of functions that generates from the same template
stack
group of functions that generates from the same template
family of functions
group of functions that generates from the same template
function template
group of functions that generates from the same template
linked list
group of functions that generates from the same template
class template
group of functions that generates from the same template
queue
group of functions that generates from the same template
generic parameter
group of functions that generates from the same template
template class
group of functions that generates from the same template
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
52
Create a displayAndCompare() function that displays two values, compares them, and displays a message indicating which is larger. The function works when any two parameters are passed, whether or not the two parameters are of the same type, as long as > and == are defined correctly for the parameters.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
53
What are common uses of template classes?
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
54
Match between columns
function that uses variable data types
stack
function that uses variable data types
family of functions
function that uses variable data types
function template
function that uses variable data types
linked list
function that uses variable data types
class template
function that uses variable data types
queue
function that uses variable data types
generic parameter
function that uses variable data types
template class
function that uses variable data types
template function
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 54 flashcards in this deck.