Chapter 3 Questions
Multiple Choice
1. Which of the following provides a way to enforce the wall of an ADT?
a. Implement the ADT as a C++ class
b. Always use public fields
c. Never use private records together methods
d. Link records together
2. Each method for the array based implementation of the ADT bag will require access to the array
of entries and what else?
a. The number of fields
b. The current number of entries in the bag
c. The ID of the previous bag entry
d. The ID of the next bag entry
3. The default constructor for an array implementation of the ADT Bag should do what?
a. Load the bag with blanks and zeros
b. Set itemCount to DEFAULT_CAPACITY
c. Initialize the current number of items
d. Load the new entry with blanks and zeros
4. Why should we prevent a client’s direct access to a data structure?
a. To protect the job security of the systems analyst
b. It is a federal law
c. Most computer languages do not allow it
d. The client could possibly damage the ADT’s data
5. Which of the following methods would definitely be considered part of a core group?
a. add
b. findNext
c. clear
d. search
6. An add method that encounters a full array should either signal it’s client or
a. Crash the program
b. Allocate a larger array
c. Loop back to the beginning of the array for another pass through the array
d. Merely increment the loop counter into the next area of memory
7. Rather than returning a value, a method can signal its client by
a. Crashing the program
b. Beeping
c. Throwing an exception
d. Ignoring the requested record
Chapter 3 Questions
8. What did the method getCurrentSize return?
a. The value of DEFAULT_CAPACITY
b. The value stored in maxItems
c. The ID of the most recently added element
d. The value stored in itemCount
9. What is the type of the value returned by the method isEmpty?
a. bool
b. int
c. real
d. long
10. Which method uses a while loop to cycle through an array’s indices from 0 to itemCount – 1,
comparing a given object to every object in the array?
a. delete
b. getFrequencyOf
c. toVector
d. isFull
11. What method could be easily defined by calling getFrequencyOf?
a. itemCount
b. isEmpty
c. add
d. delete
12. What was the method recommended to avoid gaps in the array when an element is removed?
a. Shift all the entries beyond the new gap back one slot
b. Shift all the entries in front of the new gap up one slot
c. Set the pointer in the entry before the gap to the entry after the gap
d. Replace the entry being removed with the last entry in the array
13. What is an easy way for the method clear to make the bag appear empty?
a. Set itemCount to zero
b. Set all the data values in all the entries to blanks and zeros
c. Set itemCount to maxItems – 1
d. Set maxItems to zero
Chapter 3 Questions
True or False
1. Specifications indicate how to implement ADT operations, but not what the operations do
2. Generally it is unwise to define an entire class then attempt to test it
3. The method getIndexOf should generally be declared as private.
4. Data structures for an ADT can be determined at any time during the process of specifying its
operations.
5. C++ arrays are data structures
6. Choices made during the implementation process have no effect on execution time of your code.
7. According to the text, when adding a first entry to an array, always place it in the first element,
the element whose index is zero.
7. The method toVector must “know” where the add has placed the entries.
8. The client of a class can access the class’s private members directly by use of a password.
9. The entries in a bag have no particular order.
Chapter 3 Questions
Short Answer
1. Why would we set the default capacity of ArrayBag to a low number when we are first
implementing it?
2. How can we keep a method from being able to alter a class’s data members?
3. Why do public data members make more difficult the debugging a program’s logic.
4. What did the method toVector do in the initial core group presented in the text?
5. When a stub is used within a test program, what should it do?
6. What is the purpose of using longer mnemonic names for loop variables?
7. What are the three problems mentioned concerning an array full of gaps?
8. Why would the reference bag.itemCount be illegal within the client?
9. You decide to use recursion in your implementation. Consider method getIndexOf. You use
a variable searchIndex to work your way through the array. What would be the two base
cases?