Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions