Question: DesignProject - 2 - In this design project, you will write a program that calculates the area under the curve of a polynomial function. The

DesignProject-2-In this design project, you will write a program that calculates the area under the curve of
a polynomial function. The user provides the polynomials coefficients, and the program
returns the (approximate) value of the area.
#include
#include
#include
#include
#include
using namespace std;
const double XMIN =-2.0;
const double XMAX =2.0;
const double TOL =0.00001;
// pretty-print polynomial
void print_polynomial(vector c){
double ci;
bool flag = true;
cout <<"p(x)=";
for(unsigned long int i = c.size()-1; i >=0; i--){
ci = c.at(i); // current coefficient
if (c.size()==1) cout << ci; // always print at least one coefficient
if (ci !=0){
// Print signs. Only print first sign if it is negative.
if (flag){
// handle first minus sign
flag = false;
if (ci <0) cout <<"-";
} else {
if (ci <0) cout <<"-";
else cout <<"+";
}
// Print coefficient
if (i ==0)
cout << abs(ci); // always print last coefficient
else if (abs(ci)!=1)
cout << abs(ci); // don't print ones
// Print x, except for last coefficient
if (i !=0)
cout <<"x";
// Print exponent, except for last two coefficients
if (i >1)
cout <<"^"<< i;
}
}
cout << endl;
}
// evaluate polynomial given by coefficients c at x
double eval(double x, vector c){
// your code here
}
// exact (theoretical) area
double exact(vector c){
vector c_int; // coefficients of integral
c_int.push_back(0.0); // integral of polynomial has no zero-degree term
for (unsigned long int i =0; i < c.size(); i++){
c_int.push_back(c.at(i)/(i+1)); // integrate term-by-term
}
return eval(XMAX, c_int)- eval(XMIN, c_int); // fundamental theorem of calculus
}
// read coefficients from cin, until empty newline
vector read_coefficients(void){
// your code here
}
double estimate(double step, vector c){
// your code here
}
int main(void){
// your code here
return 0;
}
ie if the Input is:
-4
-4
10
-1
the output will be
Solution:
p(x)=-x^3+10x^2-4x -4
Estimate =37.33334707
Exact =37.33333333
Error =0.00001373
Iterations =20
Step =0.00000038

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!