Question
This programming assignment exercises dynamic memory allocation, pointer operations, and copy constructor design through designing a doubly-linked circular list with a dummy header. Using such
This programming assignment exercises dynamic memory allocation, pointer operations, and copy constructor design through designing a doubly-linked circular list with a dummy header. Using such a list, you will implement an ADT polynomial.
I need help implementing the function
class Polynomial {
// Overloaded <<: prints Cn * x^n + Cn-1 * X^n-1 + ... C1 * X + C0
friend ostream& operator<<( ostream &output, const Polynomial& p );
// Constructor: the default is a 0-degree polynomial with 0.0 coefficient
public:
// Member functions
Polynomial( );
Polynomial( const Polynomial& p );
~Polynomial( );
int degree( ) const; // returns the degree of a polynomial
double coefficient( const int power ) const;
// returns the coefficient of the x^power term.
bool changeCoefficient( const double newCoefficient, const int power );
// replaces the coefficient of the x^power term
// Arithmetic operators
Polynomial operator+( const Polynomial& p ) const;
Polynomial operator-( const Polynomial& p ) const;
// Boolean comparison operators
bool operator==( const Polynomial& p ) const;
bool operator!=( const Polynomial& p ) const;
// Assignment operators
Polynomial& operator=( const Polynomial& p );
Polynomial& operator+=( const Polynomial& p );
Polynomial& operator-=( const Polynomial& p );
private:
struct Term { // a term on the sparce polynomial
double coeff; // the coefficient of each term
int power; // the degree of each term
Term *prev; // a pointer to the previous higher term
Term *next; // a pointer to the next lower term
};
int size; // # terms in the sparce polynomial
Term *head; // a pointer to the doubly-linked circular list of
// sparce polynomial
bool insert( Term* prev, const double newCoefficient, const int power );
bool remove( Term* pos );
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started