Filters
Question type

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; }


A) int x=3,y=4; cout << largerx,y) ;
B) float x=3,y=4; cout << largerx,y) ;
C) char x='3',y='4'; cout << largerx,y) ;
D) char x[]="3",y[]="4"; cout << largerx,y) ;

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

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;


A) swaps1,s2) ;
B) swapint1,int2) ;
C) swapch1,ch2) ;
D) swapint1,ch2) ;

E) B) and C)
F) All of the above

Correct Answer

verifed

verified

If you want to make a function a template function,you must precede the function declaration and definition with


A) template
B) template <class int>
C) template <class T>
D) template <void>

E) B) and D)
F) B) and C)

Correct Answer

verifed

verified

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


A) data abstraction
B) polymorphism
C) information hiding
D) algorithm abstraction

E) None of the above
F) B) and C)

Correct Answer

verifed

verified

All classes should be converted to templates

A) True
B) False

Correct Answer

verifed

verified

Writing a template class


A) allows us to skip the implementation of that template class
B) allows us to write one class definition that can hold different data types
C) means we never have to write non-template classes again
D) is illegal

E) All of the above
F) C) and D)

Correct Answer

verifed

verified

In a class template implementation,every use of the class name as the name of the class should be followed by <T>.

A) True
B) False

Correct Answer

verifed

verified

Which of the following is a correct template prefix?


A) template <class T>
B) template <Class >
C) <template> class T
D) all of the above

E) A) and B)
F) None of the above

Correct Answer

verifed

verified

Using template functions is an example of ___________ abstraction.

Correct Answer

verifed

verified

Algorithm

Which of the following describes a class that would be a good candidate for conversion to a template class?


A) A class which defines a new type of array
B) A class which defines rational numbers
C) A class which defines customers for a store
D) All of the above

E) None of the above
F) All of the above

Correct Answer

verifed

verified

A

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; };


A) containerClass myContainer;
B) containerClass<T> myContainer;
C) containerClass<int> myContainer;
D) containerClass myContainer<int>

E) A) and D)
F) B) and C)

Correct Answer

verifed

verified

If your program defines a class template,then the compiler will generate a class for each different data type for which it is instantiated.

A) True
B) False

Correct Answer

verifed

verified

When you define a class as a template,then that class can contain _________ data type.

Correct Answer

verifed

verified

any well-defined

Classes can be defined as templates.

A) True
B) False

Correct Answer

verifed

verified

Templates are an example of algorithm abstraction

A) True
B) False

Correct Answer

verifed

verified

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?


A) 1
B) 2
C) 3
D) 4

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

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; }


A) the data type must be a pre-defined data type
B) the data type must have a < operator defined for it
C) the data type must be numeric
D) the data type must be character based

E) None of the above
F) All of the above

Correct Answer

verifed

verified

In a template function definition,all parameters must be of the template class T).

A) True
B) False

Correct Answer

verifed

verified

When would you want to make a function a function template?


A) when the implementation details of the function are independent of the data types) of the parameters.
B) all functions should be function templates
C) when two different functions have different implementation details
D) only when two functions have the same type of parameters

E) B) and C)
F) A) and B)

Correct Answer

verifed

verified

Showing 1 - 20 of 33

Related Exams

Show Answer