Description
Question In this lab, you are going to implement2 an Polynomial class that represents polynomials of the form P(x) = c0 + c1x + c2x + … + cnx
The class should do the following:
- Polynomial class should contain its coefficients in an array. Use double type for
- Include a constructor that takes an integer, d , and a double, c , to construct polynomials of the form P(x) = cx d.
Include a default constructor that takes no argument and constructs a zero polynomial (P(x) = 0 ).
- Include another constructor that takes an array of coefficients and produces a polynomial with these coefficients.
- Add a getter method for a coefficient which takes degree and returns the coefficient of the term with that degree.
- Include getDegree() method that returns the degree of the polynomial. Degree of a polynomial is the degree of highest non-zero term in a polynomial. For example, the degree of polynomial P(x) = 4 – 5x 2 + 12x3 is 3. You can assume that the degree of zero polynomial is 0.
- Add toString() method that returns String representation of the polynomial. Zero terms in the polynomial should not be included in the string.
For instance, for the polynomial P(x) = 4 – 5x2 + 2x3, toString() method should return “4.0 – 5.0x^2 + 2.0x^3” .
- Add eval( double x ) method that evaluates the polynomial at x and returns the result.
- Use pow( double a, double b ) method to evaluate each term individually and the polynomial as a sum of the terms.
- Implement another method, eval2( double x ) that evaluates the polynomial using Horner’s method. Horner’s method is an efficient way of evaluating polynomials at a given point. A polynomial P(x) = c 0 + c 1x + c2x 2 + … + cnx n can be evaluated at x 0 by rearranging computation as
P(x0) = (( … ( (cn) x0 + c n-1) x0 … + c 4 ) x 0 + c 3) x0 + c 1) x0 + c 0 and computing the result from the innermost parentheses to outwards.
- Implement a class called PolynomialTester to test your Polynomial




