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:
Write a new simple string class, where each object stores the characters of a in a linked list (with one character per node). The pieces must be written from scratch using the header file simplestring.h as the starting point. Please use the name csci2270 for the namespace.
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. simplestring.h: The header file for the string class that uses a linked list to store the elements.
  2. simplestring.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 download my version of stringtest.cxx. I honestly don't know whether it tests everything, so please read through it and add more features if you need to.
PleaSE Do Your Work in These Steps:
  1. Finish implementing 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). We'll talk about why the cursor is needed in class.
  2. Implement the copy constructor, the other constructor, the destructor, and the length function. 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. Test your work now before proceeding.
  3. Implement the rest of the member functions. This includes the assignment operator, but does not yet include the nonmember functions. Test your work again before proceeding.
  4. Implement the nonmember functions. These may all be friends if you wish.

Frequently Asked Questions
  1. Do I need to do all four parts for the first week?
    Yes, please.
  2. Should the assignment operator return a value?
    Yes. Please return *this (a reference to the string that activated the assignment).

Michael Main (main@colorado.edu)