Question: Design a C++ class for polynomials. Your class should implement a constructor that accepts a vector of numbers and initializes the polynomial using it. The
Design a C++ class for polynomials. Your class should implement a constructor that accepts a vector of numbers and initializes the polynomial using it. The array contains the constants a0, a1, ...ak, in that specific order. In addition, your class should implement the following methods:
add(p) which adds another polynomial p and returns the resultant polynomial subtract(p) which subtracts another polynomial p and returns the resultant polynomial multiply(p) which multiplies the polynomial by another polynomial p, and returns the resultant polynomial
display() which displays the polynomial
evaluate(double x) which evaluates the polynomial given a value for x, and returns the result findRoots() which, if the polynomial is of degree 2 or less, finds and prints the roots.
Your main () should be a test for your polynomial. I will test your program using my own main, which might look like:
int main (){
vector
newP.display(); P2.findRoots();
cout << the value of the polynomial is" << newP.evaluate(5) << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
