-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathareaFun.cpp
More file actions
40 lines (31 loc) · 882 Bytes
/
areaFun.cpp
File metadata and controls
40 lines (31 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//========================================================
//areaFun.cpp
//Code to compute the area under a number of functions
//=========================================================
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
double trapArea(double f(double), double a, double b, int N);
//===========================>> cosSin <<====================
double cosSin(double x)
{
return cos(x)*sin(x);
}
//=======================>> main <<===========================
int main()
{
cout<<"Please specify the interval [a, b] :> ";
double a;
cin>>a;
double b;
cin>>b;
cout<<"Please specify the number of intervals :> ";
int N;
cin>>N;
cout<<"Area under cos: "<<trapArea(cos, a, b, N)<<endl;
cout<<"Area under sin: "<<trapArea(sin, a, b, N)<<endl;
cout<<"Area under cos*sin: "<<trapArea(cosSin, a, b, N)
<<endl;
return 0;
}