Sample Assignment: The Linked String Class
(Chapter 5)



Data Structures and Other Objects Using C++
Third Edition
by Michael Main and Walter Savitch
ISBN 0-321-19716-X

The Assignment:
Revise your string class from Section 4.5 so that the characters of the string are stored in a linked list. You may use the node class from Chapter 5 without any of the linked list toolkit non-member functions. When you need to do some operation to a linked list, you must write the code to do so from scratch as part of your new string class member functions.
Purposes:
Ensure that you can write a class that uses a linked list to store its information.
Before Starting:
Read Sections 5.1 through 5.3
Files that you must write:
  1. mystring.h: The new header file for the string class that uses a linked list to store the elements.
  2. string.cxx: The implementation file for the new string class. You will write all of this file, which will have the implementations of all the string's member functions.
  3. stringtest.cxx A simple interactive test program. You may write this program on your own, or you may work together with one or two other students (sharing your test code). You may even use the same test program that you used for the last assignment!
Parts:
  1. Implement the header file. Include at least three private member variables: a head pointer, a tail pointer and a cursor (that is either NULL or points to the node that was most recently used). Implement the copy constructor, the other constructor, the destructor, the length function and a reserve function that does no work for this version of the string. Note: You may choose to store the current length in a private member variable. This makes the length function simple, but it also means that all string functions must correctly maintain the length member variable.
  2. Implement the rest of the member functions. This includes the assignment operator, but does not yet include the nonmember functions or comparison operators.
  3. Implement the nonmember functions and comparison operators. These may all be friends if you wish.

Michael Main (main@colorado.edu)