Question: Q) Our original bag classes in Chapters 3-5 used a typedef to define the Item data type. What problem is solved by using a template
Q) Our original bag classes in Chapters 3-5 used a typedef to define the Item data type. What problem is solved by using a template bag class instead of these original typedef versions?
A. None of the typedef versions permit a program to use a bag of Strings.
B. With all of the typedef versions, it is difficult for a program to use several bags with different Item types.
C. With all of the typedef versions, the CAPACITY of the bag is fixed during compilation. A program cannot dynamically allocate a bag.
D. With all of the typedef versions, the Item data type must be one of the built-in C++ data types (char, int, etc.)
Q) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?
A. bag b;
B. bag
C. bag of int b;
D. int bag b;
Q) Why is it recommended to first implement a class using a typedef for the Item type, before implementing the template version?
A. It is easier to debug the typedef version.
B. The typedef version requires less disk space during the design stage.
C. The typedef version requires less memory during execution.
D. The template version will not compile unless you implement the typedef version first.
Q) When you write a template class, where does the template prefix occur?
A. Before the template class definition
B. Before each member function implementation.
C. Before any other template functions that manipulate the template class.
D. TWO of the above answers are correct.
E. All of the (A), (B), and (C) are correct.
Q) Suppose that a program wants to use both a bag of doubles and a bag of strings. Which version of the bag could you use?
A. You can use the array version of the non-template bag
B. You can use the linked list version of the non-template bag
C. You can use the array version of the template bag
D. Two of the above answers are right
E. Answers A, B, and C are all right
Q) What technique is used to provide the capability to step through items of a container class?
A. A copy constructor.
B. A default constructor.
C. A destructor.
D. An iterator.
E. An overloaded assignment operator.
Q) Why does the new node template class require two versions of the data member function, but the node in Chapter 5 needed only one?
A. The Chapter 5 node was singly linked, but the node template class is doubly linked.
B. The Chapter 5 data function returned a copy of the data, but the data function for the node template class returns a reference to the data.
C. The Chapter 5 node had no iterator.
D. All of the above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
