Chapter 7 Questions
Multiple Choice Questions
1. When is an array based implementation of the ADT stack not a better choice?
a) the stack can be large, but often is not
b) the stack does not exceed the fixed size of the array
c) the stack is most always right around 80 characters
d) the stack represents the number of students in a typical class
2. When should a constructor use an initializer?
a) when the value of the data member needs validation
b) when the stack is full
c) when the value of the data member has no restrictions
d) when the stack is empty
3. What is accomplished by hiding implementations of a stack in a class?
a) client code can access any entries of the stack
b) only the top of the stack can be accessed by client code
c) you can also treat the ADT as a queue
d) the code runs faster
4. In a link-based implementation of a stack you must write both a copy constructor and
a) a virtual constructor
b) a virtual destructor
c) a sort() method
d) a virtual instructor
5. What command is used to enforce a precondition that the peek() method cannot work on an empty stack.
a) result = false;
b) if (top < MAX_STACK – 1)
c) return top < 0;
d) assert (!isEmpty());
6. Given the following code:
template < class ItemType>
ArrayStack<ItemType>::ArrayStack() : top(–1)
{
}
What method is this?
a) the default destructor
b) the virtual destructor
c) the default constructor
d) the copy constructor
7. Given the following code:
template < class ItemType>
bool ArrayStack<ItemType>::doSomething()
{
bool result = false ;
if (!isEmpty())