Programming w/ C++ II Test 2
In the statement template <class T>, what does T represent?
A generic data type that is used in a function template
True/False: A program may not contain a "regular" version of a function and a template version of the function at the same time.
False
True/False: An exception is a condition that can be caused by a syntax error in the program.
False
True/False: At most one catch block may be attached to a single try block.
False
True/False: If an exception is not caught, it is stored for later use.
False
True/False: Inserting an item into a linked list requires that all the items past the point of the insertion be shifted to make room for the new item.
False
True/False: Linked lists are less complex to code and manage than arrays.
False
True/False: Nodes in a linked list are stored in contiguous memory.
False
True/False: Non-template functions have a slight advantage in speed over template functions.
False
True/False: There is no difference between defining an object of an ordinary class and an object of a template class.
False
True/False: When an item stored in a linked list is removed, all list items stored after it have to be moved down to plug up the hole.
False
True/False: When you create a linked list, you must know in advance how many nodes the list will contain.
False
The successor pointer in the last node of a linked list should have its value set to
NULL
How much memory is reserved for a function template?
No memory
When more than one class is derived from a base class, the situation is called
None of the above
True/False: A linked list can grow and shrink as a program runs.
True
True/False: A sequential container organizes data in a sequential fashion, similar to an array or linked list.
True
True/False: A thrown exception for which there is no matching catch block will cause the execution of the program to abort.
True
True/False: Deleting an entire linked list requires a call to the delete operator for each node in the list.
True
True/False: Deleting an entire list requires traversing the list to delete the nodes.
True
True/False: Function templates allow you to write a single function definition that works with many different data types.
True
True/False: If a node is not the first node in a linked list, deleting it may require setting the successor pointer in its predecessor.
True
True/False: In C++ polymorphism is very difficult to achieve unless you also use inheritance
True
True/False: Iterators are objects that are similar to pointers.
True
True/False: Pointers to a base class may be assigned the address of a derived class object
True
True/False: Static binding occurs when the compiler binds a function call at compile time.
True
True/False: 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.
True
True/False: The STL vector and list classes are examples of sequential containers.
True
True/False: The Standard Template Library (STL) contains templates for useful algorithms and data structures.
True
True/False: The Standard Template Library (STL) provides a linked list container.
True
True/False: The line containing a throw statement is known as the throw point.
True
True/False: The values stored in the value portion of a node of a linked list can be simple data types, structures, objects of classes, or any other data type.
True
True/False: Using a function template often requires writing less code than overloading a function.
True
True/False: When you delete a node from a linked list, you must ensure that the links in the surrounding nodes are set to bypass the node being deleted.
True
An actual instance of a template function is created in memory when the compiler encounters
a call to the template function
Which of the following are linked list operations?
adding an item, traversing the list, removing an item
If new information needs to be added to a linked list, the program simply ________ and inserts it into the list.
allocates another node
A class with at least one pure virtual function is called
an abstract class
A catch block serves as
an exception handler
The bad_alloc exception is thrown
by the new operator
A try block must immediately be followed by one or more
catch blocks
In the statement template <class T>, what does the word class indicate?
class is a keyword that indicates that T is a type parameter
A(n)________ is a class that stores data and organizes it in some fashion.
container
The most important data structures in the STL are ________ and ________.
containers, iterators
Each node in a ________ list contains pointers to the nodes before and after it.
doubly-linked
The list container provided by the Standard Template Library is a template version of a
doubly-linked list
Variations of the linked list are
doubly-linked list and circular linked list
Class templates allow you to create one general version of a class without having to
duplicate code to handle multiple data types
__________ are used to signal errors or unexpected events that occur while a program is running
exceptions
True/False: A new node cannot become the first node in the list.
false
True/False: A new node must always be made the last node in the list.
false
When a virtual member function of a class in a class hierarchy is invoked through a pointer to an object in the class hierarchy, the compiler will select the member function to be invoked
from the class of the object that is pointed to
All type parameters defined in a function template must appear at least once in the
function parameter list.
A __________ is a "generic" function that can work with different data types.
function template
The algorithms provided by the STL are implemented as ________, and perform various operations on elements of containers.
function templates
A pure virtual function
has no implmentation
To catch an exception, a program must
have a try/catch construct
The ________ of a linked list points to the first node in the list.
head
Types of iterators are
input and output, forward and bidirectional, random-access
One advantage a linked list has over a vector is that
insertion and removal of items is faster with lists than with vectors.
A(n) ________ is like a pointer. It is used to access the individual data elements in a container.
iterator
An associative container uses ________ to access values stored in it.
keys
The STL implementation of a linked list is a class called
list
Polymorphism is when __________ in a class hierarchy perform differently, depending upon the class of the object making the call
member function
A pure virtual function
must be overridden in a derived class for the function to be useful.
A function template's prefix contains ________ in angled brackets.
one or more generic data types
An abstract class is
one that has at least one pure virtual function
In a function template, the programmer substitutes ________ for ________.
parameters, data types
A ________ is used to step through a linked list and search for data.
pointer
__________ to a base class may be assigned the address of a derived class object
pointers
The term __________ means the ability to take many forms
polymorphism
Two types of container classes in the STL are
sequential and associative
To build a linked list, we can
start with an empty list, and then perform a series of add item operations.
When the compiler binds a call to a member function using only information available at compile time, the compiler is said to use __________ binding
static
The beginning of a function template is marked by a
template prefix
In many recursive operations on linked lists,
the base case is when the list is empty or has a single element
A linked list class using dynamically allocated memory should free its memory when the list is destroyed. This can be done by
the class destructor
An abstract class is somewhat restricted in how it can be used because
the compiler does not allow objects of the class to be created
The defining characteristic of a linked list is that
the locations that store list data do not have to be consecutive in memory
In a doubly-linked list, each node contains a pointer to the next node in the list, as well as a pointer to
the previous node
If the head pointer points to NULL, it is an indication that
there are no nodes in the list
When an error occurs, an exception is
thrown
To concatenate two linked lists, it is necessary to
traverse one of the lists to get to its end
Moving through a linked list is referred to as ________ the list.
traversing
A(n) ________ is used in a function template to specify a generic data type.
type parameter
Linked lists of items are commonly implemented by
using a structure containing an item and a pointer to the structure type.
The three sequential container objects currently provided by the STL are
vector, deque, list
A virtual function is declared by placing the keyword __________ in front of the return type in the base class's function declaration
virtual
In C++, polymorphism is based on the ability to make member functions of a class ________.
virtual
__________ functions are dynamically bound by the compiler
virtual
Declaring a member function of a class to be a ________ will cause the C++ compiler to use dynamic binding.
virtual function
When using a node pointer to traverse a linked list, we know we have reached the end of a list when
we encounter a successor pointer value of NULL in the current node
To indicate that a member function of a class is pure virtual,
you must put = 0 where the body of the function would go