Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction Arrays can be used to represent polynomials. The simplest approach

ID: 3848408 • Letter: I

Question

Introduction Arrays can be used to represent polynomials. The simplest approach is to store the coefficient for x at array position 0, the coefficient for x at array position 1, and so on. This approach is illustrated below. polynomial 6x3-4x2+ x-5 (can also be written as 6x 4x 1x1 5xo) array representation: The derivative of a polynomial is also a polynomial (and can be stored in the same way). polynomial: 6x 4x x-5 derivative: 18x 8x 1 If a polynomial is of order "N", its derivative will be of order "N-1". Part 1: Modify the starting point given (lab10start.cpp by writing the two missing functions. You do not need to change the main program in part l. The prototypes forthese functions should be: int read Polynomial (int maxOrder, double polynomialO), void displayPolynomial (int order, double polynomialO), Function readPolynomial should return the order of the polynomial read. It is similar to the read Array function in the notes. You will find details of what this function should do in the comments for the function, and also run the sample executable for part 1.

Explanation / Answer

Below are the functions needed for the question. Since you have not given the starter code, I could not include these functions into it.

Please #include <cmath> and then use the following code. Please post comment if you have any issues. I shall respond to your comment. Please don't forget to rate the answer if it helped. Thank you very much.

int readPolynomial(int maxOrder, double polynomial[])
{
int order;
cout << "Enter the order of the polynomial: ";
cin >> order;
cout << "Enter the co-efficients starting with the constant (x^0) term : " << endl;
for(int i = 0 ; i <= n; i++)
cin >> polynomial[i];

return order;
}

void displayPolynomial(int order, double polynomial[])
{
for(int i = order; i >= 0; --i)
{
if(polynomial[i] > 0)
cout << " + " << polynomial[i] ;
else
cout << " - " <<fabs(polynomial[i]);

(if i !=0 )
cout <<" x^" << i ;
}
}

double evaluatePolynomial(int order, double polynomial[], double x)
{
double value = 0;
for(int i = 0 ; i <= order; i++)
value = value + polynomial[i] * pow(x, i);
return value;
}


int differentiate(int order, double polynomial[], double derivative[])
{

for(int i = 1; i <= order; i++)
{
derivative[i-1] = polynomial[i] * i;
}

return order-1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote