Deck 11: Using Templates
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
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Question
Match between columns
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/54
Play
Full screen (f)
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
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
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
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
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
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}
____
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
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
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)
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) >>
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);
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
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.
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]);
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
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
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
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
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
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.
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
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
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
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
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
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
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
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck