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
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 16: Exceptions, Templates, and the Standard Template Library Stl
1
A sequential container organizes data in a sequential fashion, similar to an array or linked list.
True
2
The beginning of a function template is marked by a
A) return type.
B) parameter list.
C) template prefix.
D) semicolon.
E) None of the above
A) return type.
B) parameter list.
C) template prefix.
D) semicolon.
E) None of the above
C
3
The bad_alloc exception is thrown
A) when program code encounters a bad memory location.
B) by the new operator.
C) when you forget to free memory with the delete operator.
D) only when the program contains a catch block.
E) None of the above
A) when program code encounters a bad memory location.
B) by the new operator.
C) when you forget to free memory with the delete operator.
D) only when the program contains a catch block.
E) None of the above
B
4
The C++ mechanism for exception handling encloses code that might throw an exception in a try block and puts exception handling code in catch blocks attached to the try block.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
A program may not contain a "regular" version of a function and a template version of the function at the same time.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
The Standard Template Library (STL) contains templates for useful algorithms and data structures.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
In the statement template , 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 the above
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 the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
When an error occurs, an exception is
A) created.
B) thrown.
C) passed.
D) ignored.
E) None of the above
A) created.
B) thrown.
C) passed.
D) ignored.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
________ 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 the above
A) Virtual functions
B) Destructors
C) Exceptions
D) Templates
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
The three sequential container objects currently provided by the STL are
A) set, multiset, map.
B) vector, deque, list.
C) map, list, array.
D) multimap, map, multilist.
E) None of the above
A) set, multiset, map.
B) vector, deque, list.
C) map, list, array.
D) multimap, map, multilist.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
A thrown exception for which there is no matching catch block will cause the execution of the program to abort.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
Two types of container classes in the STL are
A) sequential and associative.
B) box and cylinder.
C) array and struct.
D) constant and literal.
E) None of the above
A) sequential and associative.
B) box and cylinder.
C) array and struct.
D) constant and literal.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
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
E) None of the above
A) dummy variable
B) exception
C) catch block
D) type parameter
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
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 the above
A) write any code.
B) use member functions.
C) use private members.
D) duplicate code to handle multiple data types.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
At most one catch block may be attached to a single try block.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
There is no difference between defining an object of an ordinary class and an object of a template class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
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 the above
A) element access operator
B) subscript indicator
C) global data finder
D) iterator
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
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 the above
A) parameters, data types
B) parameters, arguments
C) arguments, parameters
D) angle brackets, parentheses
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
In the statement template , what does the word class indicate?
A) class is a keyword that indicates that T is a type parameter.
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 called T will automatically be created by the compiler.
E) None of the above
A) class is a keyword that indicates that T is a type parameter.
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 called T will automatically be created by the compiler.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
If an exception is not caught, it is stored for later use.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
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 the above
A) iterator
B) container
C) template
D) box
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
Using a function template often requires writing less code than overloading a function.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
Iterators are objects that are similar to pointers.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
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 the above
A) function parameter list.
B) preprocessor directives.
C) function call.
D) type.h file.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
A function template's prefix contains ________ 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 the above
A) one or more generic data types
B) the function definition
C) constant values
D) the function's return type
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
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 the above
A) virtual functions
B) function templates
C) global variables
D) private data members
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
An actual instance of a template 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 the above
A) the template prefix.
B) a call to the template function.
C) a try block.
D) a catch block.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
A ________ is a "generic" function that can work with different data types.
A) function argument
B) function parameter
C) function template
D) member function
E) None of the above
A) function argument
B) function parameter
C) function template
D) member function
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
A catch block serves as
A) an exception handler.
B) an indicator of program correctness.
C) a temporary variable.
D) permanent storage for trapped errors.
E) None of the above
A) an exception handler.
B) an indicator of program correctness.
C) a temporary variable.
D) permanent storage for trapped errors.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
The STL vector and list classes are examples of sequential containers.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The line containing a throw statement is known as the throw point.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Types of iterators are
A) input and output.
B) forward and bidirectional.
C) random-access.
D) All of the above.
E) None of the above.
A) input and output.
B) forward and bidirectional.
C) random-access.
D) All of the above.
E) None of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
How much memory is reserved for a function template?
A) four bytes
B) eight bytes
C) two bytes
D) no memory
E) None of the above
A) four bytes
B) eight bytes
C) two bytes
D) no memory
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
To catch an exception, a program must
A) have a throw() function.
B) have a try/catch construct.
C) first experience a fatal error.
D) first experience an unrecoverable error.
E) None of the above
A) have a throw() function.
B) have a try/catch construct.
C) first experience a fatal error.
D) first experience an unrecoverable error.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Non-template functions have a slight advantage in speed over template functions.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
A try block must immediately be followed by one or more
A) error parameters.
B) error messages.
C) catch blocks.
D) throw blocks.
E) None of the above
A) error parameters.
B) error messages.
C) catch blocks.
D) throw blocks.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
Function templates allow you to write a single function definition that works with many different data types.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
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 the above
A) arrays, structs
B) lists, groups
C) containers, iterators
D) templates, prototypes
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
An associative container uses ________ to access values stored in it.
A) data
B) functions
C) keys
D) complex sort algorithms
E) None of the above
A) data
B) functions
C) keys
D) complex sort algorithms
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
An exception is a condition that can be caused by a syntax error in the program.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck