Homework 4 - Class defintion with several overloaded operators

Reading: Budd, Chapters 6&7.

Due Tuesday February 5th, at 10pm.

Program Description - A class that implements the type Polynomial

You must create a class that allows the polyTest.cpp program to execute producing the following output:
p1(x) = 4*x^3 + 3*x^2 + 2*x + 1
p2(x) = 4*x^3 + 3*x^2 + 2*x + 1
p3(x) = 8*x^3 + 6*x^2 + 4*x + 2
p3(0) = 2
p3(1) = 20
p3(2) = 98
funcTest: 8*x^3 + 6*x^2 + 4*x + 2
As can be deduced from examining polyTest.cpp, your "poly" class must include overloaded =, +, <<, and () operators, as well as a default constructor and a constructor that takes a degree (note this is NOTE the number of coefficients but the DEGREE - one less than the number of coefficients). The first element in the array of coefficients is the coefficient for x^degree and the last element is the constant coefficient.

Implementation Details

Your program should be free of memory leaks, and must be able to handle polynomials of ANY degree. Do not create a fixed size array for the coefficients, regardless of degree. Also, do not simply have the polynomial point to the array that is passed to the construtor. You will need to allocate a new array in the polyomial to hold the coefficients. In addition, notice that the assignment operator may need to release one array if an array of a different size is needed to accomodate the newly assigned value.

You should implement proper data hiding, and there should be no way to modify a polynomial value other than through assignment of a complete new value. Specifically you should not be able to modify individual polynomials. As a consequence, if you properly implement sharing of the coefficient array between 2 or more identical polynomials resulting from assignment, and there are no memory leaks, then you will receive a 10 point bonus.

Your must separate the class specification from the implementation. As mentioned in a webct posting, you must put the descriptive block comments on the implementations in the .cpp. You may optionally repeat those comments in the .h file.

For this assignment do NOT inline any methods or constructors. Put all method and constructor implementations in the .cpp file.

Design

25 - proper data hiding and separation of .h and .cpp

Correctness Points

5 - default constructor
5 - array constructor allocates proper array for coefficients in the poly object
5 - proper copy constructor
5 - operator= works
5 - operator+ works
10 - operator() works and is efficent
5 - operator<< works

5 - no memory leaks
5 - misc