Exam 17: Templates

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

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:
Verified

listClass<string> myList;

Using template functions is an example of ___________ abstraction.

Free
(Short Answer)
4.8/5
(42)
Correct Answer:
Verified

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:
Verified

B

Using templates in your program where warranted, is an example of

(Multiple Choice)
4.8/5
(46)

All classes should be converted to templates

(True/False)
4.8/5
(30)

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)

Templates are an example of algorithm abstraction

(True/False)
4.9/5
(41)

In a template, all members must be private

(True/False)
5.0/5
(32)

Which of the following are valid template prefixes?

(Multiple Choice)
4.8/5
(40)

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
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)