Given below is an implemention of polynomial as described in the question. Also a sample program to create and add polynomials is shown. Please do rate . the answer if it helped. Thank you very much.

**polynomial.h**

#ifndef polynomial_h

#define polynomial_h

struct term

{

int coeff;

int power;

struct term* next;

};

class polynomial

{

private:

struct term* headPtr;

int degree;

public:

polynomial();

void addTerm(int coeff, int power); //stores terms in decreasing order of power

polynomial addPolynomial(const polynomial &other);

int getDegree() const;

int getCoeff(int power) const;

void display();

};

#endif /* polynomial_h */

**polynomial.cpp**

#include “polynomial.h”

#include <iostream>

using namespace std;

polynomial::polynomial()

{

headPtr = 0;

degree = 0;

}

//adds terms in sorted decreasing order of power. If a term with same power exists, then the coeffs are added together

void polynomial::addTerm(int coeff, int power)

{

struct term* prev = 0;

struct term* curr = headPtr;

while(curr != 0 )

{

if(power > curr->power)

break;

else if(curr->power == power) //already a term with given power exists, add the coeff

{

curr->coeff += coeff;

return;

}

else

{

prev = curr;

curr = curr->next;

}

}

struct term* t = new term;

t->coeff = coeff;

t->power = power;

t->next = 0;

if(prev == 0) //adding as 1st term

{

degree = power;

t->next = headPtr;

headPtr = t;

}

else

{

prev->next = t;

t->next = curr;

}

}

polynomial polynomial::addPolynomial(const polynomial &other)

{

polynomial result;

struct term* poly1 = headPtr;

struct term* poly2 = other.headPtr;

while(poly1 != 0 && poly2 != 0)

{

if(poly1->power > poly2->power)

{

result.addTerm(poly1->coeff, poly1->power);

poly1 = poly1->next;

}

else if(poly2->power > poly1->power)

{

result.addTerm(poly2->coeff, poly2->power);

poly2 = poly2->next;

}

else

{

int sum = poly1->coeff + poly2->coeff;

if(sum != 0)

result.addTerm(sum, poly1->power);

poly1 = poly1->next;

poly2 = poly2->next;

}

}

//add any left out terms from poly1 and poly2

while(poly1 != 0)

{

result.addTerm(poly1->coeff, poly1->power);

poly1 = poly1->next;

}

while(poly2 != 0)

{

result.addTerm(poly2->coeff, poly2->power);

poly2 = poly2->next;

}

return result;

}

int polynomial::getDegree() const

{

return degree;

}

int polynomial::getCoeff(int power) const

{

struct term* curr = headPtr;

if(power > degree)

return 0;

while(curr != 0)

{

if(curr->power == power)

return curr->coeff;

else if(curr->power < power) //no need to search further since we have come to lower powers

break;

else

curr = curr->next;

}

return 0;

}

void polynomial::display()

{

struct term* curr = headPtr;

if(headPtr == 0)

cout << “0”;

else

{

//display 1st term

cout << curr->coeff << “x^” << curr->power ;

curr = curr->next;

while(curr != 0)

{

if(curr->coeff > 0)

cout << ” + ” << curr->coeff << “x^” << curr->power ;

else

cout << ” – ” << -(curr->coeff) << “x^” << curr->power ;

curr = curr->next;

}

}

cout << endl;

}

**polymain.cpp**

#include “polynomial.h”

#include <iostream>

using namespace std;

int main()

{

polynomial p1;

polynomial p2;

//p1 = 3x^4 – 2x^2 + 5

p1.addTerm(3, 4);

p1.addTerm(-2,2);

p1.addTerm(5, 0);

//p2 = 8x^5 + 3x^4 + x^2 -2

p2.addTerm(8, 5);

p2.addTerm(3, 4);

p2.addTerm(1, 2);

p2.addTerm(-2, 0);

cout << “p1 = ” ; p1.display();

cout << “p2 = ” ; p2.display();

polynomial p3 = p1.addPolynomial(p2);

cout << “p3 = p1 + p2 = ” ; p3.display();

}

**output**

p1 = 3x^4 – 2x^2 + 5x^0

p2 = 8x^5 + 3x^4 + 1x^2 – 2x^0

p3 = p1 + p2 = 8x^5 + 6x^4 – 1x^2 + 3x^0