SlideShare a Scribd company logo
1 of 23
Download to read offline
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
QUESTION 1 
Write a C++ program to evaluate∫ 
using Trapezoidal rule up 
to three significant figures. 
#include <cmath> 
#include <iostream> 
#include <iomanip> 
using namespace std; 
float f(float x) 
{ 
float func; 
func = exp(x); 
return func; 
} 
void main() 
{ 
float a,b,h,sum=0, Trap; 
int i, n; 
cout <<"Enter the lower limit a : "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals n: "; 
cin >> n; 
h=(b-a)/n;
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
for(i=1;i<n;i++) 
/*or we can can write for(i=a+h;i<=b-h;i=i+h) { sum+=f(i);*/ 
{ 
sum= sum + f(a+i*h); 
} 
Trap= (h/2)*(f(a) + f(b) +2 *sum); 
cout <<"nThe value of the integral is: " << setprecision(3) << Trap <<endl ; 
} 
//Output: 
Enter the lower limit a : 0 
Enter the upper limit b: 1.2 
Enter the number of subintervals n: 8 
The value of the integral is: 2.32 
//Alternative way for question 1 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double trapezoidal(double a,double b,int n) 
{
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
double h= (b-a)/n; 
double z[9],I; 
double x[9]= {0.0, 0.15, 0.3,0.45,0.6,0.75,0.9,1.05,1.2 }; 
for (int i=0; i<9 ; i++) 
z[i]= exp(x[i]); //the function is exp(x) 
I=h/2*( z[0]+z[8] + 2*(z[1]+z[2]+z[3]+z[4]+z[5]+z[6]+z[7]) ); 
return (I); 
} 
int main() 
{ 
double J; 
J=trapezoidal(0,1.2,8); 
cout<< "The integral value is " << setprecision(3) << J << "nn"; 
return 0; 
} 
//Output: 
The integral value is 2.32 
QUESTION 2 
Write a C++ function sub-program to evaluate ∫ 
using 
Trapezoidal rule correct to four decimal places. Compare the 
result with the exact solution 1.48766
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
#include <cmath> 
#include <iostream> 
#include <iomanip> 
using namespace std; 
float f(float x) 
{ 
float func; 
func = 1/(1+(x*x)); 
return func; 
} 
void main() 
{ 
double a,b,h,sum=0, Trap, exact=1.48766; 
// we can find the exact value by using the formula exact= atan(b) - atan(a); 
int i, n; 
cout <<"Enter the lower limit a : "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals n: "; 
cin >> n; 
h=(b-a)/n; 
for(i=1;i<n;i++)
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
/*or we can can write for(i=a+h;i<=b-h;i=i+h) { sum+=f(i);*/ 
{ 
sum= sum + f(a+i*h); 
} 
Trap= (h/2)*(f(a) + f(b) +2 *sum); 
cout <<"nThe value of the integral is: " << setprecision(4) <<fixed << Trap <<endl ; 
cout<<"The difference in Trapezoidal method = "<<setprecision(4) << fixed <<fabs(exact- 
Trap)<<endl; 
} 
//Output: 
Output 1: 
Enter the lower limit a : 0 
Enter the upper limit b: 12 
Enter the number of subintervals n: 8 
The value of the integral is: 1.5358 
The difference in Trapezoidal method = 0.0482 
Output 2: 
Enter the lower limit a : 0 
Enter the upper limit b: 12 
Enter the number of subintervals n: 1000 
The value of the integral is: 1.4877 
The difference in Trapezoidal method = 0.0000
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
QUESTION 3 
Write a C++ program to evaluate ∫ √ 
using Simpson’s 
1/3 rule. 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double f(double x) 
{ 
double function; 
function= pow(sin(x)+cos(x), 0.5); 
return function; 
} 
void main() 
{ 
double a,b, h,sum_even=0,sum_odd=0,Simpson_13; 
int i,n; 
cout << "Enter the lower limit a: "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals: "; 
cin >> n; 
h=(b-a)/n; 
for(i=1;i<n;i=i++) 
{ 
if(i%2==0)
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
sum_even= sum_even+ f(a+i*h); 
if(i%2!=0) 
sum_odd= sum_odd+ f(a+i*h); 
} 
Simpson_13=(h/3)*(f(a)+f(b)+ 4*sum_odd +2*sum_even); 
cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_13 << 
"nn"; 
} 
//Output: 
Enter the lower limit a: 0 
Enter the upper limit b: 1 
Enter the number of subintervals: 8 
The value of the integral is 1.1394 
//Alternative way for question 3 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double simpson13(double a,double b,int n) 
{ 
double z[9],Simp,h=(b-a)/n; 
double x[9]={0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0}; 
for (int i=0; i<9 ; i++) 
z[i]= pow(sin(x[i])+cos(x[i]),0.5);
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
Simp=(h/3)*((z[0]+z[8]) + 2*(z[2]+z[4]+z[6]) + 4*(z[1]+z[3]+z[5]+z[7]) ); 
return Simp; 
} 
int main() 
{ 
double J; 
J=simpson13(0,1,8); 
cout<< "The integral value is: "<< setprecision(4) <<fixed << J<<endl; 
return 0; 
} 
//Output: 
The integral value is: 1.1394 
QUESTION 4 
Write a C++ function sub-program to evaluate∫ 
using 
Simpson’s 1/3 correct to four decimal places. 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double f(double x) 
{ 
float function; 
function= 1/(1+pow(x,2)); 
return function; 
}
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
void main() 
{ 
double a,b, h,sum_even=0,sum_odd=0,Simpson_13; 
int i,n; 
cout << "Enter the lower limit a: "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals: "; 
cin >> n; 
h=(b-a)/n; 
for(i=1;i<n;i=i++) 
{ 
if(i%2==0) 
sum_even= sum_even+ f(a+i*h); 
if(i%2!=0) 
sum_odd= sum_odd+ f(a+i*h); 
} 
Simpson_13=(h/3)*(f(a)+f(b)+ 4*sum_odd +2*sum_even); 
cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_13 << "nn"; 
} 
//Output: 
Enter the lower limit a: 0 
Enter the upper limit b: 12 
Enter the number of subintervals: 6 
The value of the integral is 1.4020
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
//Alternative way for question 4 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double simpson13(double a,double b,int n) 
{ 
double z[7],Simp,h=(b-a)/n; 
double x[7]={0,2,4,6,8,10,12}; 
for (int i=0; i<7 ; i++) 
z[i]= 1/(1+pow(x[i],2)); 
Simp=(h/3)*((z[0]+z[6]) + 2*(z[2]+z[4]) + 4*(z[1]+z[3]+z[5]) ); 
return Simp; 
} 
int main() 
{ 
double J; 
J=simpson13(0,12,6); 
cout<< "The integral value is: "<< setprecision(4) <<fixed << J<<endl; 
return 0; 
} 
//Output 
The integral value is: 1.4020
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
QUESTION 5 
Write a C++ program to evaluate∫ 
using Simpson’s 3/8 
rule. 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
double f(double x) 
{ 
double function; 
function=exp(sin(x)); 
return function; 
} 
void main() 
{ 
double a,b, h,sum_miss=0,sum_triple=0,Simpson_38; 
int i,n; 
cout << "Enter the lower limit a: "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals: "; 
//should be taken as multiples of 3 
cin >> n; 
h=(b-a)/n;
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
for (i=1;i<n;i++) 
{ 
if ( i%3 != 0 ) 
sum_miss = sum_miss + f(a+i*h); 
if(i%3==0) 
sum_triple =sum_triple+ f(a+i*h); 
} 
Simpson_38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple); 
cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_38 << "nn"; 
} 
//Output: 
Enter the lower limit a: 0 
Enter the upper limit b: 1.570796 
Enter the number of subintervals: 8 
The value of the integral is 3.0381 
QUESTION 6 
Write a C++ program to evaluate∫ 
using Simpson’s 3/8 
rule. 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std;
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
double f(double x) 
{ 
double function; 
function=log10(x); 
return function; 
} 
void main() 
{ 
double a,b, h,sum_miss=0,sum_triple=0,Simpson_38; 
int i,n; 
cout << "Enter the lower limit a: "; 
cin >> a; 
cout << "Enter the upper limit b: "; 
cin >> b; 
cout << "Enter the number of subintervals: "; 
//should be taken as multiples of 3 
cin >> n; 
h=(b-a)/n; 
for (i=1;i<n;i++) 
{ 
if ( i%3 != 0 ) 
sum_miss = sum_miss + f(a+i*h); 
if(i%3==0) 
sum_triple =sum_triple+ f(a+i*h); 
} 
Simpson_38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple);
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_38 << "nn"; 
} 
//Output: 
Enter the lower limit a: 2 
Enter the upper limit b: 6 
Enter the number of subintervals: 8 
The value of the integral is 2.2833 
QUESTION 7 
Write a C++ function program to evaluate∫ 
using 
Trapezoidal, Simpson’s 1/3 and Simpson’s 3/8 rules. Compare the 
results with the exact solution 2.32012 
#include <iostream> 
#include <iomanip> 
#include <cmath> 
using namespace std; 
double f(double x) 
{ 
return exp(x) ; 
} 
double simpson_38(double a,double b,double n) 
{ 
double h=(b-a)/n, sum_miss=0,sum_triple=0,Simp38; 
for (int i=1;i<n;i++) 
{ 
if ( i%3 != 0 ) 
sum_miss = sum_miss + f(a+i*h); 
if(i%3==0) 
sum_triple =sum_triple+ f(a+i*h); 
}
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
Simp38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple); 
return Simp38; 
} 
double simpson_13(double a,double b,double n) 
{ 
double h=(b-a)/n, sum_odd=0,sum_even=0,Simp13; 
for(int i=1; i<n; i++) 
{ 
if(i%2==0) 
sum_even =sum_even + f(a+i*h); 
else 
sum_odd=sum_odd + f(a+i*h); 
} 
Simp13 = (h/3)*( (f(a) + f(b)) + 4*sum_odd + 2*sum_even ); 
return Simp13; 
} 
double trapezoidal(double a,double b,double n) 
{ 
double sum=0, Trap, h=(b-a)/n; 
for(int i=1;i<n;i++) 
sum = sum+f(a+i*h); 
Trap = (h/2)*( f(a) + f(b) + 2*sum); 
return Trap ; 
} 
int main() 
{ 
double a,b,n, exact= 2.32012; 
int ans; 
char choice; 
Pilihan: 
cout << "1. Trapezoidaln2. Simpson's 1/3 rulen3. Simpson's 3/8 rulenn"; 
cout << "Which number you wanna choose : "; 
cin >> ans; 
cout << endl;
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
switch(ans) 
{ 
case 1 : cout << "Please input a,b and n : "; 
cin >> a >> b >> n; 
cout<<"The Exact value = "<< setprecision(6) <<exact<<endl; 
cout<<"The result for Trapezoidal method = " 
<<setprecision(6)<<trapezoidal(a,b,n)<<endl; 
cout<<"The difference in Trapezoidal method = "<<setprecision(6)<< 
fabs(exact - trapezoidal(a,b,n))<<endl; 
break; 
case 2 : cout << "Please input a,b and n : "; 
cin >> a >> b >> n; 
cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; 
cout<<"The result for Simpson's 1/3 method = "<<setprecision(6)<< 
simpson_13(a,b,n)<<endl; 
cout<<"The difference in Simpson's 1/3 
method="<<setprecision(6)<<fabs(exact- simpson_13(a,b,n))<<endl; 
break; 
case 3 : cout << "Please input a,b and n : "; 
cin >> a >> b >> n; 
cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; 
cout<<"The result for Simpson's 3/8 method = "<< setprecision(6)<< 
simpson_38(a,b,n)<<endl; 
cout<<"The difference in Simpson's 3/8 method 
="<<setprecision(6)<<fabs(exact- simpson_38(a,b,n))<<endl; 
break; 
default: cout << "Invalid number. Try again : "; 
cin >> ans; 
goto Pilihan; 
break; 
} 
if(fabs(exact-simpson_38(a,b,n)) <fabs(exact-simpson_13(a,b,n)) && 
fabs(exact-simpson_38(a,b,n))<fabs(exact-trapezoidal(a,b,n)))
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
cout<<"Simpson's 3/8 is better"<<endl; 
else if(fabs(exact-simpson_13(a,b,n))<fabs(exact-simpson_38(a,b,n)) && 
fabs(exact-simpson_13(a,b,n))<fabs(exact-trapezoidal(a,b,n))) 
cout<<"Simpson's 1/3 is better"<<endl; 
else 
cout<<"Trapezoidal rule is better"<<endl; 
check: 
cout << "Do u want to try again (Y/N): "; 
cin >> choice; 
if ( choice == 'N' || choice == 'n') 
cout << "Thank You." << endl; 
else if ( choice == 'Y' || choice == 'y') 
{ 
goto Pilihan; 
} 
else goto check; 
return 0; 
} 
//Output: 
1. Trapezoidal 
2. Simpson's 1/3 rule 
3. Simpson's 3/8 rule 
Which number you wanna choose : 1 
Please input a,b and n : 0 1.2 8 
The Exact value = 2.32012 
The result for Trapezoidal method = 2.32447 
The difference in Trapezoidal method = 0.00434551 
Simpson's 1/3 is better 
Do u want to try again (Y/N): y 
1. Trapezoidal 
2. Simpson's 1/3 rule 
3. Simpson's 3/8 rule 
Which number you wanna choose : 2 
Please input a,b and n : 0 1.2 8
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
The Exact value = 2.32012 
The result for Simpson's 1/3 method = 2.32012 
The difference in Simpson's 1/3 method=3.43063e-006 
Simpson's 1/3 is better 
Do u want to try again (Y/N): y 
1. Trapezoidal 
2. Simpson's 1/3 rule 
3. Simpson's 3/8 rule 
Which number you wanna choose : 3 
Please input a,b and n : 0 1.2 8 
The Exact value = 2.32012 
The result for Simpson's 3/8 method = 2.26695 
The difference in Simpson's 3/8 method =0.0531698 
Simpson's 1/3 is better 
Do u want to try again (Y/N): n 
Thank You. 
//Alternative for question 7 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
using namespace std; 
#define f(x) exp(x) 
double trap(double a,double b,double h,double n) 
{ 
int i; 
double x1,sumA=0,resultA; 
x1=a; 
for(i=1;i<n;i++) 
{ 
x1=x1+h; 
sumA=sumA+f(x1); 
} 
resultA=(h/2)*(f(a)+2*sumA+f(b)); 
return resultA; 
} 
double simp13(double a,double b,double h,double n) 
{ 
int j; 
double x2,sumB1=0,sumB2=0,resultB; 
x2=a; 
for(j=1;j<n;j++)
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
{ 
x2=x2+h; 
if(j%2==0) 
sumB1=sumB1+2*f(x2); 
else 
sumB2=sumB2+4*f(x2); 
} 
resultB=(h/3)*(f(a)+sumB1+sumB2+f(b)); 
return resultB; 
} 
double simp38(double a,double b,double h,double n) 
{ 
double sum_miss=0,sum_triple=0,Simp38; 
for (int i=1;i<n;i++) 
{ 
if ( i%3 != 0 ) 
sum_miss = sum_miss + f(a+i*h); 
if(i%3==0) 
sum_triple =sum_triple+ f(a+i*h); 
} 
Simp38= (3*h/8)*(f(a)+f(b)+ 3*sum_miss +2*sum_triple); 
return Simp38; 
} 
int main() 
{ 
int n; 
double a=0,b=1.2,h,exact= 2.32012; 
cout<<"Enter the value of n: "; 
cin>>n; 
h=(b-a)/n; 
cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; 
cout<<"The result for Trapezoidal method = "<<setprecision(6)<<trap(a,b,h,n)<<endl; 
cout<<"The result for Simpson 1/3 method = "<<setprecision(6)<<simp13(a,b,h,n)<<endl; 
cout<<"The result for Simpson 3/8 method = "<<setprecision(6)<<simp38(a,b,h,n)<<endl; 
cout<<"The difference in Trapezoidal method = "<<setprecision(6) <<fabs(exact-trap( 
a,b,h,n))<<endl; 
cout<<"The difference in Simpson 1/3 method = "<<setprecision(6)<<fabs(exact-simp13( 
a,b,h,n))<<endl;
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
cout<<"The difference in Simpson 3/8 method = "<<setprecision(6)<<fabs(exact-simp38( 
a,b,h,n))<<endl; 
if(fabs(exact-simp38(a,b,h,n)) <fabs(exact-simp13(a,b,h,n)) && 
fabs(exact-simp38(a,b,h,n))<fabs(exact-trap(a,b,h,n))) 
cout<<"Simpson's 3/8 is better"<<endl; 
else if(fabs(exact-simp13(a,b,h,n))<fabs(exact-simp38(a,b,h,n)) && 
fabs(exact-simp13(a,b,h,n))<fabs(exact-trap(a,b,h,n))) 
cout<<"Simpson's 1/3 is better"<<endl; 
else 
cout<<"Trapezoidal rule is better"<<endl; 
return 0; 
} 
//Output: 
Enter the value of n: 8 
The Exact value = 2.32012 
The result for Trapezoidal method = 2.32447 
The result for Simpson 1/3 method = 2.32012 
The result for Simpson 3/8 method = 2.26695 
The difference in Trapezoidal method = 0.00434551 
The difference in Simpson 1/3 method = 3.43063e-006 
The difference in Simpson 3/8 method = 0.0531698 
Simpson's 1/3 is better 
//Alternative for question 7 
#include<iostream> 
#include<cmath> 
using namespace std; 
double f(double a) 
{ 
return (double) exp(a); 
} 
int main()
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
{ 
double a=0,b=1.2,n,h,Exact,sum3=0,sum=0,sumE=0,sumO=0; 
double sumT=0,simps3per8,simp1per3,trapzoid; 
cout<<"Enter the number of subintervals,n: "; 
cin>>n; 
h=(b-a)/n; 
Exact=exp(b)-exp(a); 
cout<<"Exact value="<<Exact<<endl; 
for(int i=1; i<n; i++) //Simpson 3/8 
{ 
if(i%3==0) 
sum3=sum3 + f(a+i*h); 
else 
sum=sum + f(a+i*h);} 
simps3per8=((3*h)/8)*(f(a)+f(b)+3*sum+2*sum3); 
cout<<"Simpson's 3/8 ="<<simps3per8<<endl; 
for(i=1; i<n; i++) //Simpson's 1/3 
{ 
if(i%2==0) 
sumE=sumE + f(a+i*h); 
else
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
sumO=sumO + f(a+i*h);} 
simp1per3=(h/3)*(f(a)+f(b)+4*sumO+2*sumE); 
cout<<"Simpson's 1/3 ="<<simp1per3<<endl; 
for(i=1;i<n;i++) //Trapezoidal 
sumT=sumT+f(a+i*h); 
trapzoid=(h/2)*(f(a)+f(b)+2*sumT); 
cout<<"Trapezoidal= "<<trapzoid<<endl; 
if(fabs(Exact-simps3per8)<fabs(Exact-simp1per3) && 
fabs(Exact-simps3per8)<fabs(Exact-trapzoid)) 
cout<<"Simpson's 3/8 is better"<<endl; 
else if(fabs(Exact-simp1per3)<fabs(Exact-simps3per8) && 
fabs(Exact-simp1per3)<fabs(Exact-trapzoid)) 
cout<<"Simpson's 1/3 is better"<<endl; 
else 
cout<<"Trapezoidal rule is better"<<endl; 
return 0; 
}
SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 
//Output: 
Enter the number of subintervals,n: 8 
Exact value=2.32012 
Simpson's 3/8 =2.26695 
Simpson's 1/3 =2.32012 
Trapezoidal= 2.32447 
Simpson's 1/3 is better

More Related Content

What's hot

RS Agarwal Quantitative Aptitude - 9 chap
RS Agarwal Quantitative Aptitude - 9 chapRS Agarwal Quantitative Aptitude - 9 chap
RS Agarwal Quantitative Aptitude - 9 chapVinoth Kumar.K
 
Lesson 15: Gradients and level curves
Lesson 15: Gradients and level curvesLesson 15: Gradients and level curves
Lesson 15: Gradients and level curvesMatthew Leingang
 
Project on CFD using MATLAB
Project on CFD using MATLABProject on CFD using MATLAB
Project on CFD using MATLABRohit Avadhani
 
(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2Pamidimukkala Sivani
 
Solution Manual : Chapter - 05 Integration
Solution Manual : Chapter - 05 IntegrationSolution Manual : Chapter - 05 Integration
Solution Manual : Chapter - 05 IntegrationHareem Aslam
 
9 phương pháp giải pt nghiệm nguyên
9 phương pháp giải pt nghiệm nguyên9 phương pháp giải pt nghiệm nguyên
9 phương pháp giải pt nghiệm nguyênCảnh
 
Bài tập nhập môn lập trình
Bài tập nhập môn lập trìnhBài tập nhập môn lập trình
Bài tập nhập môn lập trìnhHuy Rùa
 
Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...vaibhav tailor
 
Bồi dưỡng HSG Tin chuyên đề thuật toán
Bồi dưỡng HSG Tin chuyên đề thuật toánBồi dưỡng HSG Tin chuyên đề thuật toán
Bồi dưỡng HSG Tin chuyên đề thuật toánNguyễn Đức
 
Calculus and Numerical Method =_=
Calculus and Numerical Method =_=Calculus and Numerical Method =_=
Calculus and Numerical Method =_=Fazirah Zyra
 
11. amplitude, phase shift and period of trig formulas-x
11. amplitude, phase shift and period of trig formulas-x11. amplitude, phase shift and period of trig formulas-x
11. amplitude, phase shift and period of trig formulas-xmath260
 
Enhancing students’ understanding of algebra concepts through cooperative com...
Enhancing students’ understanding of algebra concepts through cooperative com...Enhancing students’ understanding of algebra concepts through cooperative com...
Enhancing students’ understanding of algebra concepts through cooperative com...Gambari Isiaka
 
Interpolation In Numerical Methods.
 Interpolation In Numerical Methods. Interpolation In Numerical Methods.
Interpolation In Numerical Methods.Abu Kaisar
 
Class 3 CBSE Maths Sample Paper Term 2 Model 1
Class 3 CBSE Maths Sample Paper Term 2 Model 1Class 3 CBSE Maths Sample Paper Term 2 Model 1
Class 3 CBSE Maths Sample Paper Term 2 Model 1Sunaina Rawat
 
Jacobi iteration method
Jacobi iteration methodJacobi iteration method
Jacobi iteration methodMONIRUL ISLAM
 
Topic: Fourier Series ( Periodic Function to change of interval)
Topic: Fourier Series ( Periodic Function to  change of interval)Topic: Fourier Series ( Periodic Function to  change of interval)
Topic: Fourier Series ( Periodic Function to change of interval)Abhishek Choksi
 
Tailieu.vncty.com bai tap va bai giai phuong phap tinh
Tailieu.vncty.com   bai tap va bai giai phuong phap tinhTailieu.vncty.com   bai tap va bai giai phuong phap tinh
Tailieu.vncty.com bai tap va bai giai phuong phap tinhTrần Đức Anh
 
Lý Thuyết Đồ Thị_Lê Minh Hoàng
Lý Thuyết Đồ Thị_Lê Minh HoàngLý Thuyết Đồ Thị_Lê Minh Hoàng
Lý Thuyết Đồ Thị_Lê Minh HoàngTiêu Cơm
 
Functions
FunctionsFunctions
FunctionsGaditek
 

What's hot (20)

RS Agarwal Quantitative Aptitude - 9 chap
RS Agarwal Quantitative Aptitude - 9 chapRS Agarwal Quantitative Aptitude - 9 chap
RS Agarwal Quantitative Aptitude - 9 chap
 
Lesson 15: Gradients and level curves
Lesson 15: Gradients and level curvesLesson 15: Gradients and level curves
Lesson 15: Gradients and level curves
 
Project on CFD using MATLAB
Project on CFD using MATLABProject on CFD using MATLAB
Project on CFD using MATLAB
 
(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2
 
Solution Manual : Chapter - 05 Integration
Solution Manual : Chapter - 05 IntegrationSolution Manual : Chapter - 05 Integration
Solution Manual : Chapter - 05 Integration
 
9 phương pháp giải pt nghiệm nguyên
9 phương pháp giải pt nghiệm nguyên9 phương pháp giải pt nghiệm nguyên
9 phương pháp giải pt nghiệm nguyên
 
Bài tập nhập môn lập trình
Bài tập nhập môn lập trìnhBài tập nhập môn lập trình
Bài tập nhập môn lập trình
 
Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...
 
Bồi dưỡng HSG Tin chuyên đề thuật toán
Bồi dưỡng HSG Tin chuyên đề thuật toánBồi dưỡng HSG Tin chuyên đề thuật toán
Bồi dưỡng HSG Tin chuyên đề thuật toán
 
Calculus and Numerical Method =_=
Calculus and Numerical Method =_=Calculus and Numerical Method =_=
Calculus and Numerical Method =_=
 
Đề tài: Sử dụng phương pháp đặt ẩn phụ để giải phương trình vô tỉ
Đề tài: Sử dụng phương pháp đặt ẩn phụ để giải phương trình vô tỉĐề tài: Sử dụng phương pháp đặt ẩn phụ để giải phương trình vô tỉ
Đề tài: Sử dụng phương pháp đặt ẩn phụ để giải phương trình vô tỉ
 
11. amplitude, phase shift and period of trig formulas-x
11. amplitude, phase shift and period of trig formulas-x11. amplitude, phase shift and period of trig formulas-x
11. amplitude, phase shift and period of trig formulas-x
 
Enhancing students’ understanding of algebra concepts through cooperative com...
Enhancing students’ understanding of algebra concepts through cooperative com...Enhancing students’ understanding of algebra concepts through cooperative com...
Enhancing students’ understanding of algebra concepts through cooperative com...
 
Interpolation In Numerical Methods.
 Interpolation In Numerical Methods. Interpolation In Numerical Methods.
Interpolation In Numerical Methods.
 
Class 3 CBSE Maths Sample Paper Term 2 Model 1
Class 3 CBSE Maths Sample Paper Term 2 Model 1Class 3 CBSE Maths Sample Paper Term 2 Model 1
Class 3 CBSE Maths Sample Paper Term 2 Model 1
 
Jacobi iteration method
Jacobi iteration methodJacobi iteration method
Jacobi iteration method
 
Topic: Fourier Series ( Periodic Function to change of interval)
Topic: Fourier Series ( Periodic Function to  change of interval)Topic: Fourier Series ( Periodic Function to  change of interval)
Topic: Fourier Series ( Periodic Function to change of interval)
 
Tailieu.vncty.com bai tap va bai giai phuong phap tinh
Tailieu.vncty.com   bai tap va bai giai phuong phap tinhTailieu.vncty.com   bai tap va bai giai phuong phap tinh
Tailieu.vncty.com bai tap va bai giai phuong phap tinh
 
Lý Thuyết Đồ Thị_Lê Minh Hoàng
Lý Thuyết Đồ Thị_Lê Minh HoàngLý Thuyết Đồ Thị_Lê Minh Hoàng
Lý Thuyết Đồ Thị_Lê Minh Hoàng
 
Functions
FunctionsFunctions
Functions
 

Viewers also liked

Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Tomer Gabel
 
Multiple sagement trapezoidal rule
Multiple sagement trapezoidal ruleMultiple sagement trapezoidal rule
Multiple sagement trapezoidal ruleTanmoy Debnath
 
25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuous25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuousJyoti Parange
 
Covering (Rules-based) Algorithm
Covering (Rules-based) AlgorithmCovering (Rules-based) Algorithm
Covering (Rules-based) AlgorithmZHAO Sam
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classificationKrish_ver2
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadraturesTarun Gehlot
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
Data Mining: Concepts and techniques classification _chapter 9 :advanced methods
Data Mining: Concepts and techniques classification _chapter 9 :advanced methodsData Mining: Concepts and techniques classification _chapter 9 :advanced methods
Data Mining: Concepts and techniques classification _chapter 9 :advanced methodsSalah Amean
 
Chapter 4 Classification
Chapter 4 ClassificationChapter 4 Classification
Chapter 4 ClassificationKhalid Elshafie
 
Numerical integration
Numerical integrationNumerical integration
Numerical integrationMohammed_AQ
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration methodshashikant pabari
 

Viewers also liked (20)

Integration
IntegrationIntegration
Integration
 
Data mining
Data miningData mining
Data mining
 
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)
 
Multiple sagement trapezoidal rule
Multiple sagement trapezoidal ruleMultiple sagement trapezoidal rule
Multiple sagement trapezoidal rule
 
25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuous25285 mws gen_int_ppt_trapcontinuous
25285 mws gen_int_ppt_trapcontinuous
 
Calc 4.6
Calc 4.6Calc 4.6
Calc 4.6
 
Covering (Rules-based) Algorithm
Covering (Rules-based) AlgorithmCovering (Rules-based) Algorithm
Covering (Rules-based) Algorithm
 
Data mining notes
Data mining notesData mining notes
Data mining notes
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classification
 
05 classification 1 decision tree and rule based classification
05 classification 1 decision tree and rule based classification05 classification 1 decision tree and rule based classification
05 classification 1 decision tree and rule based classification
 
Trapezoidal rule
Trapezoidal ruleTrapezoidal rule
Trapezoidal rule
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Gaussian quadratures
Gaussian quadraturesGaussian quadratures
Gaussian quadratures
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Es272 ch6
Es272 ch6Es272 ch6
Es272 ch6
 
Data Mining: Concepts and techniques classification _chapter 9 :advanced methods
Data Mining: Concepts and techniques classification _chapter 9 :advanced methodsData Mining: Concepts and techniques classification _chapter 9 :advanced methods
Data Mining: Concepts and techniques classification _chapter 9 :advanced methods
 
Chapter 4 Classification
Chapter 4 ClassificationChapter 4 Classification
Chapter 4 Classification
 
Numerical integration
Numerical integrationNumerical integration
Numerical integration
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 

Similar to C++ TUTORIAL 8

Similar to C++ TUTORIAL 8 (20)

C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
901131 examples
901131 examples901131 examples
901131 examples
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
C++ file
C++ fileC++ file
C++ file
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 

More from Farhan Ab Rahman (10)

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2
 
Notis Surau
Notis SurauNotis Surau
Notis Surau
 
Kitab Bakurah.amani
Kitab Bakurah.amaniKitab Bakurah.amani
Kitab Bakurah.amani
 

Recently uploaded

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

C++ TUTORIAL 8

  • 1. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 QUESTION 1 Write a C++ program to evaluate∫ using Trapezoidal rule up to three significant figures. #include <cmath> #include <iostream> #include <iomanip> using namespace std; float f(float x) { float func; func = exp(x); return func; } void main() { float a,b,h,sum=0, Trap; int i, n; cout <<"Enter the lower limit a : "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals n: "; cin >> n; h=(b-a)/n;
  • 2. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 for(i=1;i<n;i++) /*or we can can write for(i=a+h;i<=b-h;i=i+h) { sum+=f(i);*/ { sum= sum + f(a+i*h); } Trap= (h/2)*(f(a) + f(b) +2 *sum); cout <<"nThe value of the integral is: " << setprecision(3) << Trap <<endl ; } //Output: Enter the lower limit a : 0 Enter the upper limit b: 1.2 Enter the number of subintervals n: 8 The value of the integral is: 2.32 //Alternative way for question 1 #include<iostream> #include<cmath> #include<iomanip> using namespace std; double trapezoidal(double a,double b,int n) {
  • 3. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 double h= (b-a)/n; double z[9],I; double x[9]= {0.0, 0.15, 0.3,0.45,0.6,0.75,0.9,1.05,1.2 }; for (int i=0; i<9 ; i++) z[i]= exp(x[i]); //the function is exp(x) I=h/2*( z[0]+z[8] + 2*(z[1]+z[2]+z[3]+z[4]+z[5]+z[6]+z[7]) ); return (I); } int main() { double J; J=trapezoidal(0,1.2,8); cout<< "The integral value is " << setprecision(3) << J << "nn"; return 0; } //Output: The integral value is 2.32 QUESTION 2 Write a C++ function sub-program to evaluate ∫ using Trapezoidal rule correct to four decimal places. Compare the result with the exact solution 1.48766
  • 4. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 #include <cmath> #include <iostream> #include <iomanip> using namespace std; float f(float x) { float func; func = 1/(1+(x*x)); return func; } void main() { double a,b,h,sum=0, Trap, exact=1.48766; // we can find the exact value by using the formula exact= atan(b) - atan(a); int i, n; cout <<"Enter the lower limit a : "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals n: "; cin >> n; h=(b-a)/n; for(i=1;i<n;i++)
  • 5. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 /*or we can can write for(i=a+h;i<=b-h;i=i+h) { sum+=f(i);*/ { sum= sum + f(a+i*h); } Trap= (h/2)*(f(a) + f(b) +2 *sum); cout <<"nThe value of the integral is: " << setprecision(4) <<fixed << Trap <<endl ; cout<<"The difference in Trapezoidal method = "<<setprecision(4) << fixed <<fabs(exact- Trap)<<endl; } //Output: Output 1: Enter the lower limit a : 0 Enter the upper limit b: 12 Enter the number of subintervals n: 8 The value of the integral is: 1.5358 The difference in Trapezoidal method = 0.0482 Output 2: Enter the lower limit a : 0 Enter the upper limit b: 12 Enter the number of subintervals n: 1000 The value of the integral is: 1.4877 The difference in Trapezoidal method = 0.0000
  • 6. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 QUESTION 3 Write a C++ program to evaluate ∫ √ using Simpson’s 1/3 rule. #include<iostream> #include<cmath> #include<iomanip> using namespace std; double f(double x) { double function; function= pow(sin(x)+cos(x), 0.5); return function; } void main() { double a,b, h,sum_even=0,sum_odd=0,Simpson_13; int i,n; cout << "Enter the lower limit a: "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals: "; cin >> n; h=(b-a)/n; for(i=1;i<n;i=i++) { if(i%2==0)
  • 7. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 sum_even= sum_even+ f(a+i*h); if(i%2!=0) sum_odd= sum_odd+ f(a+i*h); } Simpson_13=(h/3)*(f(a)+f(b)+ 4*sum_odd +2*sum_even); cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_13 << "nn"; } //Output: Enter the lower limit a: 0 Enter the upper limit b: 1 Enter the number of subintervals: 8 The value of the integral is 1.1394 //Alternative way for question 3 #include<iostream> #include<cmath> #include<iomanip> using namespace std; double simpson13(double a,double b,int n) { double z[9],Simp,h=(b-a)/n; double x[9]={0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0}; for (int i=0; i<9 ; i++) z[i]= pow(sin(x[i])+cos(x[i]),0.5);
  • 8. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 Simp=(h/3)*((z[0]+z[8]) + 2*(z[2]+z[4]+z[6]) + 4*(z[1]+z[3]+z[5]+z[7]) ); return Simp; } int main() { double J; J=simpson13(0,1,8); cout<< "The integral value is: "<< setprecision(4) <<fixed << J<<endl; return 0; } //Output: The integral value is: 1.1394 QUESTION 4 Write a C++ function sub-program to evaluate∫ using Simpson’s 1/3 correct to four decimal places. #include<iostream> #include<cmath> #include<iomanip> using namespace std; double f(double x) { float function; function= 1/(1+pow(x,2)); return function; }
  • 9. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 void main() { double a,b, h,sum_even=0,sum_odd=0,Simpson_13; int i,n; cout << "Enter the lower limit a: "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals: "; cin >> n; h=(b-a)/n; for(i=1;i<n;i=i++) { if(i%2==0) sum_even= sum_even+ f(a+i*h); if(i%2!=0) sum_odd= sum_odd+ f(a+i*h); } Simpson_13=(h/3)*(f(a)+f(b)+ 4*sum_odd +2*sum_even); cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_13 << "nn"; } //Output: Enter the lower limit a: 0 Enter the upper limit b: 12 Enter the number of subintervals: 6 The value of the integral is 1.4020
  • 10. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 //Alternative way for question 4 #include<iostream> #include<cmath> #include<iomanip> using namespace std; double simpson13(double a,double b,int n) { double z[7],Simp,h=(b-a)/n; double x[7]={0,2,4,6,8,10,12}; for (int i=0; i<7 ; i++) z[i]= 1/(1+pow(x[i],2)); Simp=(h/3)*((z[0]+z[6]) + 2*(z[2]+z[4]) + 4*(z[1]+z[3]+z[5]) ); return Simp; } int main() { double J; J=simpson13(0,12,6); cout<< "The integral value is: "<< setprecision(4) <<fixed << J<<endl; return 0; } //Output The integral value is: 1.4020
  • 11. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 QUESTION 5 Write a C++ program to evaluate∫ using Simpson’s 3/8 rule. #include<iostream> #include<cmath> #include<iomanip> using namespace std; double f(double x) { double function; function=exp(sin(x)); return function; } void main() { double a,b, h,sum_miss=0,sum_triple=0,Simpson_38; int i,n; cout << "Enter the lower limit a: "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals: "; //should be taken as multiples of 3 cin >> n; h=(b-a)/n;
  • 12. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 for (i=1;i<n;i++) { if ( i%3 != 0 ) sum_miss = sum_miss + f(a+i*h); if(i%3==0) sum_triple =sum_triple+ f(a+i*h); } Simpson_38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple); cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_38 << "nn"; } //Output: Enter the lower limit a: 0 Enter the upper limit b: 1.570796 Enter the number of subintervals: 8 The value of the integral is 3.0381 QUESTION 6 Write a C++ program to evaluate∫ using Simpson’s 3/8 rule. #include<iostream> #include<cmath> #include<iomanip> using namespace std;
  • 13. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 double f(double x) { double function; function=log10(x); return function; } void main() { double a,b, h,sum_miss=0,sum_triple=0,Simpson_38; int i,n; cout << "Enter the lower limit a: "; cin >> a; cout << "Enter the upper limit b: "; cin >> b; cout << "Enter the number of subintervals: "; //should be taken as multiples of 3 cin >> n; h=(b-a)/n; for (i=1;i<n;i++) { if ( i%3 != 0 ) sum_miss = sum_miss + f(a+i*h); if(i%3==0) sum_triple =sum_triple+ f(a+i*h); } Simpson_38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple);
  • 14. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 cout <<"The value of the integral is " << setprecision(4) <<fixed << Simpson_38 << "nn"; } //Output: Enter the lower limit a: 2 Enter the upper limit b: 6 Enter the number of subintervals: 8 The value of the integral is 2.2833 QUESTION 7 Write a C++ function program to evaluate∫ using Trapezoidal, Simpson’s 1/3 and Simpson’s 3/8 rules. Compare the results with the exact solution 2.32012 #include <iostream> #include <iomanip> #include <cmath> using namespace std; double f(double x) { return exp(x) ; } double simpson_38(double a,double b,double n) { double h=(b-a)/n, sum_miss=0,sum_triple=0,Simp38; for (int i=1;i<n;i++) { if ( i%3 != 0 ) sum_miss = sum_miss + f(a+i*h); if(i%3==0) sum_triple =sum_triple+ f(a+i*h); }
  • 15. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 Simp38= (3*h/8)*((f(a)+f(b))+ 3*sum_miss +2*sum_triple); return Simp38; } double simpson_13(double a,double b,double n) { double h=(b-a)/n, sum_odd=0,sum_even=0,Simp13; for(int i=1; i<n; i++) { if(i%2==0) sum_even =sum_even + f(a+i*h); else sum_odd=sum_odd + f(a+i*h); } Simp13 = (h/3)*( (f(a) + f(b)) + 4*sum_odd + 2*sum_even ); return Simp13; } double trapezoidal(double a,double b,double n) { double sum=0, Trap, h=(b-a)/n; for(int i=1;i<n;i++) sum = sum+f(a+i*h); Trap = (h/2)*( f(a) + f(b) + 2*sum); return Trap ; } int main() { double a,b,n, exact= 2.32012; int ans; char choice; Pilihan: cout << "1. Trapezoidaln2. Simpson's 1/3 rulen3. Simpson's 3/8 rulenn"; cout << "Which number you wanna choose : "; cin >> ans; cout << endl;
  • 16. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 switch(ans) { case 1 : cout << "Please input a,b and n : "; cin >> a >> b >> n; cout<<"The Exact value = "<< setprecision(6) <<exact<<endl; cout<<"The result for Trapezoidal method = " <<setprecision(6)<<trapezoidal(a,b,n)<<endl; cout<<"The difference in Trapezoidal method = "<<setprecision(6)<< fabs(exact - trapezoidal(a,b,n))<<endl; break; case 2 : cout << "Please input a,b and n : "; cin >> a >> b >> n; cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; cout<<"The result for Simpson's 1/3 method = "<<setprecision(6)<< simpson_13(a,b,n)<<endl; cout<<"The difference in Simpson's 1/3 method="<<setprecision(6)<<fabs(exact- simpson_13(a,b,n))<<endl; break; case 3 : cout << "Please input a,b and n : "; cin >> a >> b >> n; cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; cout<<"The result for Simpson's 3/8 method = "<< setprecision(6)<< simpson_38(a,b,n)<<endl; cout<<"The difference in Simpson's 3/8 method ="<<setprecision(6)<<fabs(exact- simpson_38(a,b,n))<<endl; break; default: cout << "Invalid number. Try again : "; cin >> ans; goto Pilihan; break; } if(fabs(exact-simpson_38(a,b,n)) <fabs(exact-simpson_13(a,b,n)) && fabs(exact-simpson_38(a,b,n))<fabs(exact-trapezoidal(a,b,n)))
  • 17. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 cout<<"Simpson's 3/8 is better"<<endl; else if(fabs(exact-simpson_13(a,b,n))<fabs(exact-simpson_38(a,b,n)) && fabs(exact-simpson_13(a,b,n))<fabs(exact-trapezoidal(a,b,n))) cout<<"Simpson's 1/3 is better"<<endl; else cout<<"Trapezoidal rule is better"<<endl; check: cout << "Do u want to try again (Y/N): "; cin >> choice; if ( choice == 'N' || choice == 'n') cout << "Thank You." << endl; else if ( choice == 'Y' || choice == 'y') { goto Pilihan; } else goto check; return 0; } //Output: 1. Trapezoidal 2. Simpson's 1/3 rule 3. Simpson's 3/8 rule Which number you wanna choose : 1 Please input a,b and n : 0 1.2 8 The Exact value = 2.32012 The result for Trapezoidal method = 2.32447 The difference in Trapezoidal method = 0.00434551 Simpson's 1/3 is better Do u want to try again (Y/N): y 1. Trapezoidal 2. Simpson's 1/3 rule 3. Simpson's 3/8 rule Which number you wanna choose : 2 Please input a,b and n : 0 1.2 8
  • 18. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 The Exact value = 2.32012 The result for Simpson's 1/3 method = 2.32012 The difference in Simpson's 1/3 method=3.43063e-006 Simpson's 1/3 is better Do u want to try again (Y/N): y 1. Trapezoidal 2. Simpson's 1/3 rule 3. Simpson's 3/8 rule Which number you wanna choose : 3 Please input a,b and n : 0 1.2 8 The Exact value = 2.32012 The result for Simpson's 3/8 method = 2.26695 The difference in Simpson's 3/8 method =0.0531698 Simpson's 1/3 is better Do u want to try again (Y/N): n Thank You. //Alternative for question 7 #include<iostream> #include<cmath> #include<iomanip> using namespace std; #define f(x) exp(x) double trap(double a,double b,double h,double n) { int i; double x1,sumA=0,resultA; x1=a; for(i=1;i<n;i++) { x1=x1+h; sumA=sumA+f(x1); } resultA=(h/2)*(f(a)+2*sumA+f(b)); return resultA; } double simp13(double a,double b,double h,double n) { int j; double x2,sumB1=0,sumB2=0,resultB; x2=a; for(j=1;j<n;j++)
  • 19. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 { x2=x2+h; if(j%2==0) sumB1=sumB1+2*f(x2); else sumB2=sumB2+4*f(x2); } resultB=(h/3)*(f(a)+sumB1+sumB2+f(b)); return resultB; } double simp38(double a,double b,double h,double n) { double sum_miss=0,sum_triple=0,Simp38; for (int i=1;i<n;i++) { if ( i%3 != 0 ) sum_miss = sum_miss + f(a+i*h); if(i%3==0) sum_triple =sum_triple+ f(a+i*h); } Simp38= (3*h/8)*(f(a)+f(b)+ 3*sum_miss +2*sum_triple); return Simp38; } int main() { int n; double a=0,b=1.2,h,exact= 2.32012; cout<<"Enter the value of n: "; cin>>n; h=(b-a)/n; cout<<"The Exact value = "<<setprecision(6)<<exact<<endl; cout<<"The result for Trapezoidal method = "<<setprecision(6)<<trap(a,b,h,n)<<endl; cout<<"The result for Simpson 1/3 method = "<<setprecision(6)<<simp13(a,b,h,n)<<endl; cout<<"The result for Simpson 3/8 method = "<<setprecision(6)<<simp38(a,b,h,n)<<endl; cout<<"The difference in Trapezoidal method = "<<setprecision(6) <<fabs(exact-trap( a,b,h,n))<<endl; cout<<"The difference in Simpson 1/3 method = "<<setprecision(6)<<fabs(exact-simp13( a,b,h,n))<<endl;
  • 20. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 cout<<"The difference in Simpson 3/8 method = "<<setprecision(6)<<fabs(exact-simp38( a,b,h,n))<<endl; if(fabs(exact-simp38(a,b,h,n)) <fabs(exact-simp13(a,b,h,n)) && fabs(exact-simp38(a,b,h,n))<fabs(exact-trap(a,b,h,n))) cout<<"Simpson's 3/8 is better"<<endl; else if(fabs(exact-simp13(a,b,h,n))<fabs(exact-simp38(a,b,h,n)) && fabs(exact-simp13(a,b,h,n))<fabs(exact-trap(a,b,h,n))) cout<<"Simpson's 1/3 is better"<<endl; else cout<<"Trapezoidal rule is better"<<endl; return 0; } //Output: Enter the value of n: 8 The Exact value = 2.32012 The result for Trapezoidal method = 2.32447 The result for Simpson 1/3 method = 2.32012 The result for Simpson 3/8 method = 2.26695 The difference in Trapezoidal method = 0.00434551 The difference in Simpson 1/3 method = 3.43063e-006 The difference in Simpson 3/8 method = 0.0531698 Simpson's 1/3 is better //Alternative for question 7 #include<iostream> #include<cmath> using namespace std; double f(double a) { return (double) exp(a); } int main()
  • 21. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 { double a=0,b=1.2,n,h,Exact,sum3=0,sum=0,sumE=0,sumO=0; double sumT=0,simps3per8,simp1per3,trapzoid; cout<<"Enter the number of subintervals,n: "; cin>>n; h=(b-a)/n; Exact=exp(b)-exp(a); cout<<"Exact value="<<Exact<<endl; for(int i=1; i<n; i++) //Simpson 3/8 { if(i%3==0) sum3=sum3 + f(a+i*h); else sum=sum + f(a+i*h);} simps3per8=((3*h)/8)*(f(a)+f(b)+3*sum+2*sum3); cout<<"Simpson's 3/8 ="<<simps3per8<<endl; for(i=1; i<n; i++) //Simpson's 1/3 { if(i%2==0) sumE=sumE + f(a+i*h); else
  • 22. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 sumO=sumO + f(a+i*h);} simp1per3=(h/3)*(f(a)+f(b)+4*sumO+2*sumE); cout<<"Simpson's 1/3 ="<<simp1per3<<endl; for(i=1;i<n;i++) //Trapezoidal sumT=sumT+f(a+i*h); trapzoid=(h/2)*(f(a)+f(b)+2*sumT); cout<<"Trapezoidal= "<<trapzoid<<endl; if(fabs(Exact-simps3per8)<fabs(Exact-simp1per3) && fabs(Exact-simps3per8)<fabs(Exact-trapzoid)) cout<<"Simpson's 3/8 is better"<<endl; else if(fabs(Exact-simp1per3)<fabs(Exact-simps3per8) && fabs(Exact-simp1per3)<fabs(Exact-trapzoid)) cout<<"Simpson's 1/3 is better"<<endl; else cout<<"Trapezoidal rule is better"<<endl; return 0; }
  • 23. SJEM2231: STRUCTURED PROGRAMMING (C++) TUTORIAL 8 //Output: Enter the number of subintervals,n: 8 Exact value=2.32012 Simpson's 3/8 =2.26695 Simpson's 1/3 =2.32012 Trapezoidal= 2.32447 Simpson's 1/3 is better