#include <iostream>
#include <math.h>
using namespace std;
class Simpsons1b3
{
public:
Simpsons1b3()
{
k = 2;
}
void askInterval();
void solve();
double f(double x);
void findH();
void findX1();
private:
double I,h,xn,x0,k,x1;
};
void Simpsons1b3::askInterval()
{
cout << "Enter Xn: ";
cin >> xn;
cout << "Enter X0: ";
cin >> x0;
}
void Simpsons1b3::findH()
{
h= (xn - x0)/k;
}
void Simpsons1b3::findX1()
{
x1 = x0 + h;
}
double Simpsons1b3::f(double x)
{
return exp(x);
}
void Simpsons1b3::solve()
{
askInterval();
findH();
findX1();
I = h / 3.0 * ( f(x0) +4 * f(x1) + f(xn) );
cout << endl << "The required answer is : " << I << endl;
}
int main()
{
Simpsons1b3 s1;
s1.solve();
return 0;
}
C and C++ programs, games, softwares. Easy programming guide. Learn to code and enjoy coding in CoderNepal
Home » T.U.2073 » C++ code for Simpson's 1/3 Rule
Monday, April 17, 2017
C++ code for Simpson's 1/3 Rule
This is the solution for finding Integration using Simpson's 1/3 Rule
Labels:
Cplusplus,
Integration,
Numerical Method,
T.U.2073
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment