Problem

Create a class Polynomial that is used to evaluate a polynomial function of x:P(x) = a0 +...

Create a class Polynomial that is used to evaluate a polynomial function of x:

P(x) = a0 + a1 x + a2 x + … + an-1 xn-1 + an xn

The coefficients a1are floating-point numbers, the exponents ofx are integers, and the largest exponentn—called thedegree of the polynomial—is greaterthan or equal to 0. The class has the attributes

• degree—the value of the largest exponentn

• coefficients—an array of the coefficients a1

and the following methods:

• Polynomial(max)—a constructor that creates a polynomial of degree max whose coefficients are all 0

• setConstant(i, value)—sets the coefficient a1 to value

• evaluate(x)—returns the value of the polynomial for the given value x

For example, the polynomial

P(x) = 3 + 5x + 2x3

is of degree 3 and has coefficients a0 = 3, a1 = 5, a2 = 0, and a3 = 2. The invocation evaluate(7) computes 3 + 5 x 7 + 0 x 7 + 2 x 73, which is 3 + 35 + 0 + 686, and returns the result 724.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT