Programming Fundalmentals II — Test 4
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
In the statement template <class T>, 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
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
A pure virtual function ________. A) must be overridden in a derived class for the function to be useful B) executes more efficiently than a non-pure virtual function C) must be accompanied by a virtual constructor of the same class D) All of the above E) None of the above
A) must be overridden in a derived class for the function to be useful
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
An abstract class is ________. A) one that has at least one pure virtual function B) one that supports polymorphism C) one that has all of its member functions declared private D) one that has all of its member variables declared private E) None of the above
A) one that has at least one pure virtual function
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
Polymorphism in C++ will not work unless ________. A) pointers or references are being used B) the members of the class are public C) the <polymorphic> header file is included D) All of the above E) None of the above
A) pointers or references are being used
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
A virtual function is declared by placing the keyword ________ in front of the return type in the base class's function declaration. A) virtual B) private C) public D) protected E) None of the above
A) virtual
In the 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 the above
C) A generic data type that is used in a function template
________ 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
C) Exceptions
A class with at least one pure virtual function is called ________. A) a pure virtual class B) a virtual base class C) an abstract class D) All of the above E) None of the above
C) an abstract class
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
C) catch blocks
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
C) containers, iterators
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
C) function template
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
C) keys
Polymorphism is when ________ in a class hierarchy perform differently, depending upon the class of the object making the call. A) base class constructors B) derived class destructors C) member functions D) derived class constructors E) None of the above
C) member functions
When the compiler binds a call to a member function using only information available at compile time, the compiler is said to use ________ binding. A) local B) safe C) static D) dynamic E) None of the above
C) static
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
C) template prefix
In C++, polymorphism is based on the ability to make member functions of a class ________. A) static B) protected C) virtual D) encapsulated E) None of the above
C) virtual
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
D) All of the above
________ to a base class may be assigned the address of a derived class object. A) Access specifiers B) Static members C) Private members D) Pointers E) None of the above
D) Pointers
________ functions are dynamically bound by the compiler. A) Constructor B) Destructor C) Static D) Virtual E) None of the above
D) Virtual
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
D) duplicate code to handle multiple data types
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
D) iterator
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
D) no memory
An abstract class is somewhat restricted in how it can be used because ________. A) it cannot use dynamic binding for its member functions B) it cannot use static binding for its member functions C) All of its members must be public D) the compiler does not allow objects of the class to be created E) None of the above
D) the compiler does not allow objects of the class to be created
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
D) type parameter
Declaring a member function of a class to be a ________ will cause the C++ compiler to use dynamic binding. A) constructor function B) destructor function C) static function D) virtual function E) None of the above
D) virtual function
When more than one class is derived from a base class, the situation is called ________. A) polymorphism B) population C) multiplicity D) encapsulation E) None of the above
E) None of the above
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: 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: 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: Function templates allow you to write a single function definition that works with many different data types.
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 line containing a throw statement is known as the throw point.
True
True/False: Using a function template often requires writing less code than overloading a function.
True
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
B) a call to the template function
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
B) by the new operator
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
B) container
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 ________. A) from the class of the type of the pointer B) from the class of the object that is pointed to C) from the base class of the inheritance hierarchy D) from the derived class of the base pointer object E) None of the above
B) from the class of the object that is pointed to
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
B) function templates
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
B) have a try/catch construct.
A pure virtual function ________. A) is a virtual function that has been completely debugged B) is a virtual function that has no implementation C) is a virtual function that performs a single task in program D) is one that is only called from within a virtual constructor E) is none of these
B) is a virtual function that has no implementation
The term ________ means the ability to take many forms. A) inheritance B) polymorphism C) member function D) encapsulation E) None of the above
B) polymorphism
When an error occurs, an exception is ________. A) created B) thrown C) passed D) ignored E) None of the above
B) thrown
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
B) vector, deque, list
To indicate that a member function of a class is pure virtual, ________. A) you use the keywords pure virtual B) you must put = 0 where the body of the function would go C) you must include the <pure> header file D) All of the above E) None of the above
B) you must put = 0 where the body of the function would go