Deck 16: Exceptions, Templates, and the Standard Template Library STL
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/39
Play
Full screen (f)
Deck 16: Exceptions, Templates, and the Standard Template Library STL
1
Class templates allow you to create one general version of a class without having to
A) write any code.
B) use member functions.
C) use private members.
D) duplicate code to handle multiple data types.
E) None of these
A) write any code.
B) use member functions.
C) use private members.
D) duplicate code to handle multiple data types.
E) None of these
D
2
To handle an exception that has been thrown, a program must have a(n) _________________.
A) throw() function
B) try/catch construct
C) fatal error
D) unrecoverable error
E) None of these
A) throw() function
B) try/catch construct
C) fatal error
D) unrecoverable error
E) None of these
B
3
The beginning of a function template is marked by a
A) return type.
B) parameter list.
C) template prefix.
D) semicolon.
E) None of these
A) return type.
B) parameter list.
C) template prefix.
D) semicolon.
E) None of these
C
4
In the following statement template
What does the word class indicate?
A) class is a keyword that is used to precede the type parameter T
B) you are deriving a class from an existing class called T
C) you are deriving a class called T from a class called template
D) a class named T will automatically be created by the compiler
E) None of these
What does the word class indicate?
A) class is a keyword that is used to precede the type parameter T
B) you are deriving a class from an existing class called T
C) you are deriving a class called T from a class called template
D) a class named T will automatically be created by the compiler
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
5
A(n) _________ is like a pointer. It is used to access the individual data elements in a container.
A) element access operator
B) subscript indicator
C) global data finder
D) iterator
E) None of these
A) element access operator
B) subscript indicator
C) global data finder
D) iterator
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
6
The _______ starts with the keyword try, and is followed by a block of code executing any statements that might cause an exception to be thrown.
A) try block
B) try/catch class
C) try() function
D) catch() function
E) None of these
A) try block
B) try/catch class
C) try() function
D) catch() function
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
7
These are used to signal errors or unexpected events that occur while a program is running.
A) Virtual functions
B) Destructors
C) Exceptions
D) Templates
E) None of these
A) Virtual functions
B) Destructors
C) Exceptions
D) Templates
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
8
A(n) ____________ is a value or an object that signals an error.
A) destructor
B) template
C) throw
D) exception
E) None of these
A) destructor
B) template
C) throw
D) exception
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
9
Catch blocks serve as ________________.
A) exception handlers
B) wide receivers
C) temporary variables
D) permanent storage for trapped errors
E) None of these
A) exception handlers
B) wide receivers
C) temporary variables
D) permanent storage for trapped errors
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
10
A(n) ___________ is used in a function template to specify a generic data type.
A) dummy variable
B) exception
C) catch block
D) type parameter
A) dummy variable
B) exception
C) catch block
D) type parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
11
In a function template, the programmer substitutes _________ for __________.
A) parameters, data types
B) parameters, arguments
C) arguments, parameters
D) angle brackets, parentheses
E) None of these
A) parameters, data types
B) parameters, arguments
C) arguments, parameters
D) angle brackets, parentheses
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
12
Two types of container classes in the STL are:
A) sequence and associative
B) box and cylinder
C) array and struct
D) constant and literal
E) None of these
A) sequence and associative
B) box and cylinder
C) array and struct
D) constant and literal
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
13
In the following statement template < class T >
What does T represent?
A) The name of the function template
B) "T" stands for "Template"
C) A generic data type that is used in a function template
D) The int data type
E) None of these
What does T represent?
A) The name of the function template
B) "T" stands for "Template"
C) A generic data type that is used in a function template
D) The int data type
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
14
The try block is immediately followed by one or more _____________.
A) errors
B) error messages
C) catch blocks
D) throw blocks
E) None of these
A) errors
B) error messages
C) catch blocks
D) throw blocks
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
15
The three sequence container objects provided by the STL are:
A) set, multiset, map
B) vector, deque, list
C) map, list, array
D) multimap, map, multilist
E) None of these
A) set, multiset, map
B) vector, deque, list
C) map, list, array
D) multimap, map, multilist
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
16
If an exception is thrown by a member function of a class object, then the class __________ is called.
A) constructor
B) destructor
C) catcher
D) handler
E) None of these
A) constructor
B) destructor
C) catcher
D) handler
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
17
An exception thrown from outside a try block
A) will be caught outside the catch block
B) will be caught inside the catch block
C) will remain inside the throw block
D) will cause the program to abort execution
E) None of these
A) will be caught outside the catch block
B) will be caught inside the catch block
C) will remain inside the throw block
D) will cause the program to abort execution
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
18
This is a "generic" function that can work with any data type.
A) function argument
B) function parameter
C) function template
D) member function
E) None of these
A) function argument
B) function parameter
C) function template
D) member function
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
19
How much memory is reserved for a function template?
A) four bytes
B) eight bytes
C) two bytes
D) no memory
E) None of these
A) four bytes
B) eight bytes
C) two bytes
D) no memory
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
20
When an error occurs, an exception is
A) created
B) thrown
C) passed
D) ignored
E) None of these
A) created
B) thrown
C) passed
D) ignored
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
21
A sequence container organizes data in a sequential fashion, similar to an array.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
22
Using a function template requires less code than overloading a function.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
23
Function templates allow you to write a single function definition that works with many different data types.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
24
The try/catch/throw construct is able to handle only one type of exception in a try block.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
25
An associative container uses these to access elements rapidly.
A) data
B) functions
C) keys
D) complex sort algorithms
E) None of these
A) data
B) functions
C) keys
D) complex sort algorithms
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
26
Types of iterators are
A) input and output
B) forward and bidirectional
C) random-access
D) All of these
E) None of these
A) input and output
B) forward and bidirectional
C) random-access
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
27
The Standard Template Library (STL) contains templates for useful algorithms and data structures.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
28
A function template prefix is placed before the function header. A class template prefix is placed ______________.
A) following the public: access specification
B) following the private: access specification
C) before the class declaration
D) before the class constructor function header
E) None of these
A) following the public: access specification
B) following the private: access specification
C) before the class declaration
D) before the class constructor function header
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
29
There is no difference between declaring an object of an ordinary class and an object of a template class.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
30
An actual instance of the function is created in memory when the compiler encounters________________.
A) the template prefix
B) a call to the template function
C) a try block
D) a catch block
E) None of these
A) the template prefix
B) a call to the template function
C) a try block
D) a catch block
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
31
A(n)__________ is a class that stores data and organizes it in some fashion.
A) iterator
B) container
C) template
D) box
E) None of these
A) iterator
B) container
C) template
D) box
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
32
The most important data structures in the STL are _______ and _________.
A) arrays, structs
B) lists, groups
C) containers, iterators
D) templates, prototypes
E) None of these
A) arrays, structs
B) lists, groups
C) containers, iterators
D) templates, prototypes
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
33
When you declare an iterator to work with a container, the compiler automatically chooses the right type.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
34
A program may not contain both a "regular" version of a function and a template version of the function.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
35
All type parameters defined in a function template must appear at least once in the
A) function parameter list.
B) preprocessor directives.
C) function call.
D) type.h file.
E) None of these
A) function parameter list.
B) preprocessor directives.
C) function call.
D) type.h file.
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
36
If an exception is not caught, it is stored for later use.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
37
A function template's prefix contains __________ enclosed in angled brackets.
A) one or more generic data types
B) the function definition
C) constant values
D) the function's return type
E) None of these
A) one or more generic data types
B) the function definition
C) constant values
D) the function's return type
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
38
The line containing a throw statement is known as the throw point.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
39
The algorithms provided by the STL are implemented as _____________, and perform various operations on elements of containers.
A) virtual functions
B) function templates
C) global variables
D) private data members
E) None of these
A) virtual functions
B) function templates
C) global variables
D) private data members
E) None of these
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck