Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Exercises

  1. Modify the result of Exercise 1 from Chapter XX to use a TStack and TStackIterator instead of an array of Shape pointers. Add destructors to the class hierarchy so you can see that the Shape objects are destroyed when the TStack goes out of scope.
  2. Modify the Sshape2.cpp example from Chapter XX to use TStack instead of an array.
  3. Modify Recycle.cpp to use a TStash instead of a TStack.
  4. Change SetTest.cpp to use a SortedSet instead of a set.
  5. Duplicate the functionality of Applist.cpp for the TStash class.
  6. You can do this exercise only if your compiler supports member function templates. Copy Tstack.h to a new header file and add the function templates in Applist.cpp as member function templates of TStack.
  7. (Advanced) Modify the TStack class to further increase the granularity of ownership: add a flag to each link indicating whether that link owns the object it points to, and support this information in the add( ) function and destructor. Add member functions to read and change the ownership for each link, and decide what the _owns flag means in this new context.
  8. (Advanced) Modify the TStack class so each entry contains reference-counting information ( not the objects they contain), and add member functions to support the reference counting behavior.
  9. (Advanced) Change the underlying implementation of Urand in Sorted.cpp so it is space-efficient (as described in the paragraph following Sorted.cpp) rather than time-efficient.
  10. (Advanced) Change the typedef cntr from an int to a long in Getmem.h and modify the code to eliminate the resulting warning messages about the loss of precision. This is a pointer arithmetic problem.
  11. (Advanced) Devise a test to compare the execution speed of an SString created on the stack versus one created on the heap.
Contents | Prev | Next


Contact: webmaster@codeguru.com
CodeGuru - the website for developers.
[an error occurred while processing this directive]