Data Structures - Chapter 4 - Programming Assignment
Revise the Sequence Class To Use a Dynamic Array

Data Structures and Other Objects Using C++
by Michael Main and Walter Savitch
ISBN 0-8053-7470-1, Softcover, 784 pages, 1997


The Assignment:
You will implement and test a revised sequence class that uses a dynamic array to store the items.
Purposes:
Ensure that you can write a small class that uses a dynamic array as a private member variable.
Before Starting:
Due Date:
Midnight Friday June 11, 2004
Submitting your code:
Leave all your files in the directory lab3 under the 2440 directory.
Files that you will need:
Files that you must write:
  1. sequence2.h: The header file for the new sequence class. Actually, you don't have to write much of this file. Just start with our version and add your name and other information at the top along with your private data members at the bottom. If some of your member functions are implemented as inline functions, then you may put those implementations in this file too. By the way, you might want to compare this header file with your first sequence header file (sequence1.h). The new version no longer has a CAPACITY constant because the items are stored in a dynamic array that grows as needed. But there is a DEFAULT_CAPACITY constant, which provides the initial size of the array for a sequence created by the default constructor.
  2. sequence2.C: The implementation file for the new sequence class. You will write all of this file, which will have the implementations of all the sequence's member functions.
Other files that you may find helpful:
  1. sequence_test.C: This is the same interactive test program that you used with the earlier sequence. If you want to use it with the new list, then copy it to your directory and open it with your editor. Then change the statement
    #include "sequence1.h"
    to
    #include "sequence2.h"
    and change the namespace from main_savitch_3 to main_savitch_4.
  2. sequence_ex2.C: A non-interactive test program that will be used to grade the correctness of your new sequence class.

The Sequence Class Using a Dynamic Array
Discussion of the Assignment

Your sequence class for this assignment will differ from the your previous sequence in the following ways:

Start by declaring the new sequence's private member variables in sequence2.h. This should include the dynamic array (which is declared as a pointer to a value_type). You will also need two size_type variables to keep track of the number of items in the sequence and the total size of the dynamic array. After you've declared your member variables, write an invariant for the top of sequence2.C.

Once again, do your work in small pieces. For example, my first version of the sequence had only a constructor, start, insert, advance, and current. My other member functions started out as stubs.

Use the interactive test program and the debugger to track down errors in your implementation. If you have an error, do not start making changes until you have identified the cause of the error.

When a member functions needs to increase the size of the dynamic array, it is a good idea to increase that size by at least 10% (rather than by just one item).


Michael Main (main@colorado.edu)