Question: In this assignment you will implement and test a C++ class called Polynom from a given definition, to represent and use polynomials. A polynomial function
In this assignment you will implement and test a C++ class called Polynom from a given definition, to represent and use polynomials. A polynomial function of independent variable x can be written as p(x)=anxn +an1xn1 +...+a1x+a0 The highest power of variable x that occurs in the polynomial with nonzero coefficient (in this case n with an = 0) is called the degree of the polynomial. The quantities an, . . . , a0 are constants known as coefficients. In this assignment coefficients are int type and can be positive, negative, or 0. A basic operation for polynomials is to evaluate it at a specific value of x where x is a real number. For example, we can evaluate the quadratic polynomial q(x), q(x)=x2 +5x+6 for x = 2, by considering the polynomial in the following nested form, q(x) = ((x + 5)x + 6) and then substituting x = 2 to obtain, q(2) = ((2 + 5)2 + 6) = ((7)2 + 6) = (14 + 6) = 20 Notice that the method shown above to evaluate a polynomial is much more efficient than the method in which each term of type xk in the polynomial is explicitly computed by using for example cmath power function double pow(double base, double exponent) which is shown below, pow(2, 2) + 5 pow(2, 1) + 6 = 20Your implementation to evaluate a polynomial at given x should use the method nested form as explained above. We can add two polynomials and subtract one from the other. Examples are shown below. p(x)=3x3 +2x2 +x+16, q(x)=x2 +5x+6 p(x)+q(x)=(3+0)x3 +(2+1)x2 +(1+5)x+(16+6) = 3x3 +3x2 +6x+22 p(x)q(x)=(30)x3 +(21)x2 +(15)x+(166) = 3x3 +x2 +(4)x+10 A simple way to represent a polynomial object of degree n is to use a vector of length n + 1 to store the coefficients. For example, the polynomials p and q can be represented by vectors of length 4 and 3, respectively. p:[32116], q:[156] It is possible that some of the coefficients in a polynomial are 0. Consider the polynomial r(x) = 5x9 +2x4 +19 where the largest power of x is 9 so that we need a vector of length 10 to store the polynomial: r : [5 0 0 0 0 2 0 0 0 19] The definition of a polynomial class is provided in the file Polynom.h. This assignment asks you to implement the member functions in a file named Polynom.cc according to the specification provided in Polynom.h and the description given above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
