CS 2005, B Term 1999
Data Structures and Programming Techniques
HW2 (due Nov. 12)
This page is located at http://www.cs.wpi.edu/~alvarez/CS2005/B99/HW2/
In this assignment you will provide a second implementation of
a class whose objects represent polynomials (as in HW1), this
time using dynamic arrays for the internal representation
(in the private part of the class definition). This representation
eliminates the limitations on the maximum degree of the polynomials
imposed by the static array version.
The name DPoly will be used for the new class implementation
to prevent confusion with the static SPoly version from HW1.
The main changes in the DPoly class definition relative to
that for SPoly are summarized below.
Because the DPoly class uses dynamic memory, additional public
member functions are required beyond those needed for SPoly,
namely a copy constructor, a destructor, and an overloaded
assignment operator. Also, the member constant MAX_DEGREE
has been replaced by DEFAULT_SIZE. The latter indicates the
maximum degree initially allowed for a DPoly object;
higher degrees are handled by using dynamic memory allocation
I've included a private pointer variable named data.
Given a DPoly object p, the pointer member p.data should point
to a dynamic array for the coefficients of the polynomial p.
A private helper function named resize has also been included.
This function is used by other member functions to change the
size of the data array when necessary. Compare with the use of
the resize function for the dynamic Bag class described in
section 4.3 of Main and Savitch.
Examine the class definition for DPoly that appears in the header
file dpoly.h, available in
Changes have been made in both the public and private parts of the
class definition relative to that of the SPoly class used in HW1 as
summarized above. Do not make any changes in the header file.
In a separate file called dpoly.cxx, implement the functions
whose specifications appear in dpoly.h.
You must use dynamic arrays to store the coefficients.
In this connection you may find it helpful to carefully review
chapter 4 of Main and Savitch, and in particular to study the
dynamic array implementation of the Bag class presented in
A simple test program polytest.cxx will be available in
/cs/cs2005/samples/hw2/polytest.cxx. Link polytest.cxx
to your DPoly class implementation using the Makefile
provided in /cs/cs2005/samples/hw2/Makefile. Perform
multiple sample runs to debug your implementation.
Although you may of course use any platform to initially
develop your code, your submitted HW2 files must compile
and link correctly under g++ on the CCC Unix machines when
the Makefile in /cs/cs2005/samples/hw2/Makefile is used.
The source code for your implementation in dpoly.cxx
should be carefully commented. Provide additional documentation
for your code in a file named README, following the WPI CS
documentation standard. You do not need to include the actual
source code in the documentation file, just the names of the
appropriate source files. Include screen views of several
sample runs of your program. Your README file should also
include a brief discussion of the merits and drawbacks of
the dynamic array implementation of the DPoly class.
Can you suggest an improved implementation? Justify your claims.
Use turnin to submit the following files (and no other files),
fully addressing the items listed above, before 5 pm on Friday
Nov. 12, 1999.