Exam 17: Templates
Exam 1: Introduction to Computer and C++ Programming56 Questions
Exam 2: C++ Basics57 Questions
Exam 3: More Flow of Control45 Questions
Exam 4: Procedural Abstraction and Functions That Return a Value53 Questions
Exam 5: Functions for All Sub Tasks54 Questions
Exam 6: Io Streams As an Introduction to Objects and Classes52 Questions
Exam 7: Arrays48 Questions
Exam 8: Strings and Vectors69 Questions
Exam 9: Pointers and Dynamic Arrays39 Questions
Exam 10: Defining Classes61 Questions
Exam 11: Friends, Overloaded Operators, and Arrays in Classes56 Questions
Exam 12: Separate Compilation and Namespaces41 Questions
Exam 13: Pointers and Linked Lists64 Questions
Exam 14: Recursion48 Questions
Exam 15: Inheritance53 Questions
Exam 16: Exception Handling47 Questions
Exam 17: Templates35 Questions
Exam 18: Standard Template Library59 Questions
Select questions type
Given a class template named listClass, declare a listClass object named myList that can hold strings.
Free
(Short Answer)
4.8/5
(41)
Correct Answer:
listClass<string> myList;
Using template functions is an example of ___________ abstraction.
Free
(Short Answer)
4.8/5
(42)
Correct Answer:
Algorithm
Given that you have two versions of a function that are the same except that one expects some integer parameters, and the other expects a float and an integer parameter, which parameters would you change to a T in order to make this a template function?
Free
(Multiple Choice)
4.7/5
(35)
Correct Answer:
B
Using templates in your program where warranted, is an example of
(Multiple Choice)
4.8/5
(46)
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
(35)
When you define a class as a template, then that class can contain _________ data type.
(Short Answer)
4.9/5
(45)
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.8/5
(32)
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.8/5
(37)
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
(41)
Given a class template named listClass, declare a listClass object named myList that can hold doubles.
(Short Answer)
4.9/5
(38)
You may not have overloaded friend operators in a class template
(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.9/5
(37)
Why can you not use the swap template function to swap two complete arrays?
Template <class T>
Void swapT& left, T& right)
{
T tmp=left;
Left=right;
Right=tmp;
}
(Multiple Choice)
4.9/5
(36)
Given a class template, how many different times can you instantiate the class?
(Multiple Choice)
4.9/5
(34)
Give the following class template, what changes need to be made to the default constructor definition?
Template <class T>
Class containerClass
{
Public:
ContainerClass);
ContainerClassint newMaxSize);
ContainerClassconst containerClass& source);
~containerClass);
T getItem);
Int getCount);
Int getSize);
Void addItemT item);
Private:
T *bag;
Int maxSize, count;
};
ContainerClass::containerClass)
{
MaxSize = 10;
Bag = new int[maxSize];
Count=0;
}
(Multiple Choice)
4.7/5
(37)
If you want to make a function a template function, you must precede the function declaration and definition with
(Multiple Choice)
4.9/5
(37)
Showing 1 - 20 of 35
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)