Explore BrainMass

C++ - polynomials implementation

Design and implement a class for dealing with polynomials. The polynomial
a(n)x^n + a(n-1)x^(n-1) + . . . + a0

will be implemented as a linked list. Each node will contain and int value for the power of x and an int value for the corresponding coefficient. The polynomial operations should include addition, multiplication, and evaluation of polynomials. Overload the operators + and *. Evaluation of a polynomial is implemented as a member function with one argument of type int.

Include four constructors: a default one, a copy constructor, a constructor with a single argument of type int that produces a polynomial that has only one constant term a0, and a constructor with two arguments of type int produces a polynomial whose coefficient and the exponent are given as parameters. Include a suitable destructor.

Include member functions to input and output polynomials. When the user inputs a polynomial, the user types in the following:
a(n)x^n + a(n-1)x^(n-1) + . . . + a0

For example, the polynomial -2x4 + 5x2 - 3 can be input as - 2x^4 + 5x^2 - 3 with spaces around each + or - sign. You can assume that polynomials are always entered one per line.

© BrainMass Inc. brainmass.com July 16, 2018, 8:14 am ad1c9bdddf

Solution Summary

C++ polynomial implementations are examined.