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

Hello, I need this program to work in Visual C++, Visual Studios 2015 please, Cr

ID: 3839364 • Letter: H

Question

Hello, I need this program to work in Visual C++, Visual Studios 2015 please,

Create a program to solve the integral of a function using Simpsons rule. The upper and lower limits will be positive and the value of n must be even. The user will be requested to select witch function to solve from the following choices:

1)You are given the following three mathematical functions:

a) 1/(1+x2)

b) ex^2

1)The “main” function request the user to select one of the mathematical functions above that they would like to solve. The “main” function will also request the upper and lower limits along with the value of n.

2) You must have a separate function that calculates (delta x)/3.

3) You must have a separate function that calculates the series in Simpsons rule

(f0 + 4 f1 ……….+4fn-1 +fn)

4) You will need a function that completes the overall calculation and prints out the solution. It should also print which function was solved, the upper and lower limits along with the value of n . Provided that n is large enough the answer to the integral of the function should be accurate to three decimal places.

This is what i have for the begining

#include <iostream>
#include <cmath>

using namespace std;
double function(int, int, int);        //Declaring functions outside of the main(global)
int main() {
int a, b, n;
cout << "Enter upper limit, b= ";
cin >> b;
cout << "Enter lower limit, a= ";
cin >> a;                     //Setting boundaries of the area
cout << " Enter number of rectangles, n (even number only)= ";
cin >> n;         //Setting number of rectangles
function(b, a, n);
system("pause");
return 0;
}

please do this in C++ format,

Thank you

Explanation / Answer

#include<iostream>
#include<cmath>
using namespace std;
double eqn1(double x)
{
double a=1/(1+x*2); //write the function whose definite integral is to be calcuated here
return a;
}
double eqn2(double x)
{
double t=x*x;
double p=exp(t);
return (p);
}
void calc(double a1,double b1,int n1,int ch)
{
if(ch==1) //choice of eqution
{
int i,n;
double a,b,c,h,s=0,inte;
a=a1;
b=b1;
n=n1;
double x[n+1],y[n+1];
h=(b-a)/n;
for (i=0;i<n+1;i++) //calcultaing the series
{
x[i]=a+i*h; //store in arrays
y[i]=eqn1(x[i]);
}
for (i=1;i<n;i+=2)
{
s=s+4.0*y[i];
}
for (i=2;i<n-1;i+=2)
{
s=s+2.0*y[i];   
}
inte=h/3.0*(y[0]+y[n]+s); //printing the result
cout<<" The definite integral is "<<inte<<" "<<endl;
}
else
{
int i,n;
double a,b,c,h,s=0,inte;
a=a1;
b=b1;
n=n1;
double x[n+1],y[n+1];
h=(b-a)/n;
for (i=0;i<n+1;i++)
{ //calculate the series
x[i]=a+i*h; //store in arrays
y[i]=eqn2(x[i]);
}
for (i=1;i<n;i+=2)
{
s=s+4.0*y[i];
}
for (i=2;i<n-1;i+=2)
{
s=s+2.0*y[i];
}
inte=h/3.0*(y[0]+y[n]+s);
cout<<" The definite integral is "<<inte<<" "<<endl;
}
}

int main()
{ cout.precision(3); //set the precision
cout.setf(ios::fixed);
int n,ch;
double a,b;
cout<<"Enter 1 to calculate for 1/(1+x*2) ";
cout<<"Enter 2 to calculate for ex^2 ";
cout<<"Enter your choice "; //choice of equation
cin>>ch;
cout << "Enter upper limit, b= "; //taking the boundaries
cin >> b;
cout << "Enter lower limit, a= ";
cin >> a;
cout << " Enter number of rectangles, n (even number only)= ";
cin >> n;   
calc(a,b,n,ch);   
return 0;
}

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