CS 2005, B Term 1999
Data Structures and Programming Techniques
HW1 (due Nov. 5)
This page is located at http://www.cs.wpi.edu/~alvarez/CS2005/B99/HW1/
Introduction
Your task for this assignment is to implement an
abstract data type that represents polynomials, using arrays
as the internal representation (in the private part of the
class definition).
Polynomials are among the most commonly used functions in
symbolic algebra systems. A polynomial is a finite sum of
constant multiples of powers of a variable x, for example
f(x) = 3x2 + 5x   or   g(x) = -9x4 + x - 5.
The multipliers in front of the powers of x are called
coefficients. The highest power for which the
associated coefficient is nonzero is called the degree
of the polynomial. The above examples have degrees 2 and 4
respectively.
Polynomials may be added and multiplied according to the
usual rules for numbers. The sum of the two polynomials
given above is
f(x) + g(x) = -9x4 + 3x2 + 6x - 5.
The product of the two polynomials has degree 6; it is
f(x)*g(x) =
-27 x6
-45 x5
+ 3 x3
-10 x2
-25 x
One can represent a polynomial as an array containing the
coefficients of the polynomial. For example, if arrays of
length 7 are used, then f and g would be represented by the
arrays [0,5,3,0,0,0,0] and [-5,1,0,0,-9,0,0]) respectively,
where the convention is that the coefficient of the k-th power
is stored in the k-th position of the array.
Since the degrees of different polynomials may be different,
the arrays used should have a size that's larger than the
highest degree needed.
Instructions
- Fill in the private part of the class definition for SPoly
that appears in the header file spoly.h,
using fixed-size arrays to store the coefficients.
-
In a separate file called spoly.cxx,
implement the public member functions whose specifications
appear in the header file. Such member functions include a
constructor and a constant member function that returns the
coefficient of a specified power for a given polynomial.
You should also provide overloaded + and * operators that
return the usual sum and product of two polynomials. These
two operators are declared to be either friend functions
of the SPoly class or ordinary non-member functions as
shown in the header file.
- Write a test program spolytest.cxx that lets the user invoke
each of the public member functions of the Polynomial class by
selecting from a menu of clearly explained options displayed on
the console output.
For each menu option, the test program should prompt the user
to input the desired values of the arguments for the member
function corresponding to that option. For example, the test
program should allow the user to input a polynomial by giving
its coefficients using the standard console input stream.
The function should then be invoked, and the result of its
invocation should be displayed on the console output in some way.
Details of the interface design are left to the discretion
of the programmer / designer.
- Provide documentation for your code following the WPI CS
documentation standard. Detailed g++ compiler command lines
should be included. Your code must compile and link correctly
using g++ on the CCC Unix machines when these command lines are used.
- Write a brief discussion of the merits and drawbacks
of the array implementation of the SPoly class. Does the
implementation successfully achieve the desired functionality
as specified in the header file? What limitations does the
fixed-size array representation impose on the resulting
implementation?
- Use turnin to electronically submit all of your files
addressing the above items before 5 pm on Friday Nov. 5, 1999.