Explore BrainMass
Share

C++ - polynomials implementation

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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.

https://brainmass.com/math/number-theory/polynomials-implementation-245157

Solution Summary

C++ polynomial implementations are examined.

\$2.19

Software Engineering

Do this exercise in C++ language, prefer use Visual C++ or DevC to compile.

Exercise 6.3: A polynomial of degree n has the form

Where are numeric constants called the coefficients of the polynomial and #0.

For example:

is a polynomial of degree 4 with integer coefficients 1, 3, 0, -7 and 5. One common implementation of a polynomial stores the degree of the polynomial and the list of coefficients. This is the implementation to be used in the exercises that follow. As you add the various operations to the Polynomial class you are building, you should also write a program to test your class.

1. Write a declaration for a Polynomial class whose data members are an integer for the degree and an array for the list of coefficients and with basic operations of input and output.
2. Implement the input operation in Question 1
3. Implement the output operation in Question 1. Display the polynomial in the usual mathematical format with displayed as x^n.
4. Add an evaluate operation to your Polynomial class that allows the user to enter a value for x and that calculates the value of the polynomial for that value.