Exam 17: Templates
Exam 1: Introduction to Computer and C Programming55 Questions
Exam 2: C++ Basics54 Questions
Exam 3: More Flow of Control44 Questions
Exam 4: Procedural Abstraction and Functions That Return a Value51 Questions
Exam 5: Functions for All Sub Tasks53 Questions
Exam 6: Io Streams As an Introduction to Objects and Classes51 Questions
Exam 7: Arrays34 Questions
Exam 8: Strings and Vectors63 Questions
Exam 9: Pointers and Dynamic Arrays40 Questions
Exam 10: Defining Classes50 Questions
Exam 11: Friends, overloaded Operators, and Arrays in Classes49 Questions
Exam 12: Separate Compilation and Namespaces38 Questions
Exam 13: Pointers and Linked Lists51 Questions
Exam 14: Recursion43 Questions
Exam 15: Inheritance53 Questions
Exam 16: Exception Handling47 Questions
Exam 17: Templates33 Questions
Exam 18: Standard Template Library57 Questions
Select questions type
Using template functions is an example of ___________ abstraction.
Free
(Short Answer)
4.7/5
(36)
Correct Answer:
Algorithm
When you define a class as a template,then that class can contain _________ data type.
Free
(Short Answer)
4.9/5
(35)
Correct Answer:
any well-defined
Which of the following describes a class that would be a good candidate for conversion to a template class?
Free
(Multiple Choice)
4.8/5
(35)
Correct Answer:
A
If your program defines a class template,then the compiler will generate a class for each different data type for which it is instantiated.
(True/False)
4.9/5
(41)
In a template function definition,all parameters must be of the template class T).
(True/False)
4.9/5
(34)
Given the following template function definition,which of the following is not a valid invocation of the function?
Template <class T>
Void swapT& left,T& right)
{
//implementation goes here,not relevant to the question
}
Int int1,int2;
Float flt1,flt2;
Char ch1,ch2;
String s1,s2;
(Multiple Choice)
4.8/5
(43)
Which would be the correct way to instantiate a containerClass object in your main program?
Template <class T>
Class containerClass
{
Public:
ContainerClass);
ContainerClassint newMaxSize);
ContainerClassconst containerClass& source);
~containerClass);
T getItem);
Int getCount);
Int getSize);
Void addItemT item);
Private:
T *container;
Int maxSize,count;
};
(Multiple Choice)
4.9/5
(38)
If you want to make a function a template function,you must precede the function declaration and definition with
(Multiple Choice)
4.7/5
(29)
Given the following function template,which of the following are NOT valid calls to larger?
Template <class T>
T largerconst T& left,const T& right)
{
Ifleft > right)
Return left;
Else
Return right;
}
(Multiple Choice)
4.9/5
(36)
Using templates in your program where warranted,is an example of
(Multiple Choice)
4.9/5
(35)
In a class template implementation,every use of the class name as the name of the class should be followed by <T>.
(True/False)
4.9/5
(34)
If you need to pass a class template named myClass)function an object of the class as a value parameter,then the type of the parameter is
(Short Answer)
4.7/5
(30)
In the following function template,what must be true in order to use the function with a given data type?
Template <class T>
Int smallest T array[],int size)
{
Int small=0,i;
Fori=0;i<size;i++)
{
Ifarray[i] < array[small])
Small=i;
}
Return small;
}
(Multiple Choice)
4.7/5
(42)
If you define some list class template in your program,and then declare a list of integers,2 lists of doubles and 1 list of strings,how many different version of the template class will the compiler provide?
(Multiple Choice)
4.7/5
(38)
Showing 1 - 20 of 33
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)