Question: Static array representation is convenient for representing polynomials if the degree of the polynomial is known in advance (before running the program), and thus we

Static array representation is convenient for representing polynomials if the degree of the polynomial is known in advance (before running the program), and thus we know how many terms we have to store and how many elements in the array must be allocated.

Otherwise, if the degree of the polynomial is known only dynamically (when we run the program), we have to allocate this memory dynamically with the new operator.

Write a function

double * getPoly(int °ree) 

that asks the user to enters the degree of the polynomial followed by its coefficients:

Enter the degree: 6 Enter the coefficient at x^6: 0.1 Enter the coefficient at x^5: 0 Enter the coefficient at x^4: 0 Enter the coefficient at x^3: 0 Enter the coefficient at x^2: 7.23 Enter the coefficient at x^1: 6 Enter the coefficient at x^0: 125 

The function should

return a dynamically allocated array (a pointer to its first element) containing the coefficients of the polynomial, and

update the variable degree that was passed by reference with the degree of the input polynomial.

All user interaction (including asking for the degree of the polynomial) and all memory allocation should be performed inside the function. None of these operations should be done inside main.

Write a program that uses the above function to read a polynomial from the keyboard, then asks the user to provide the value of the variable x where the polynomial has to be evaluated, then it prints the answer.

All dynamically allocated memory must be released by the end of the program. Use the delete[] operator to do that.

Write a simple main function as well to test your function eval, and the write function to print it.

//c++ recursion

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!