#include <iostream>
#include <math.h>
using namespace std;
class integ{ //建一个类integ
public:
float Integral(int a, int b, float(*fun)(float)) //定义成员函数,fun为用来求积分值的通用被积函数
{
float t = (b - a) / 100.0; //将梯形分为100份,每份小梯形的高为t
float integral = 0; //初始化函数值
for (int i = 0;i < 100;i++)
{
integral += t*(fun(a + i*t)+ fun(a + (i + 1)*t))/2 ;//函数值为小梯形面积之和
}
return integral; //返回函数值
}
static float fun1(float x)
{
return pow(x, 2); //定义一个静态成员函数fun1,返回值为x*x
}
static float fun2(float x)
{
return 2*x + 1; //定义一个静态成员函数fun2,返回值为2*x+1
}
};
int main()
{
integ itg; //建一个对象itg
int a,b;
cout<<"请任意输入函数x^2的上下限a,b:"<<endl;
cin>>a>>b; //输入上下限
cout<<"积分值为:"<<itg.Integral(a,b , itg.fun1)<<endl; //输出fun1的积分值
cout<<"请任意输入函数2x+1的上下限a,b:"<<endl;
cin>>a>>b; //输入上下限
cout<<"积分值为:"<<itg.Integral(a, b, itg.fun2)<<endl; //输出fun2的积分值
system("pause");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
aaa.rar_Fun_ Fun_ Fun
共19个文件
tlog:10个
lastbuildstate:2个
filters:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 129 浏览量
2022-09-21
19:58:04
上传
评论
收藏 120KB RAR 举报
温馨提示
该函数返回值为积分结果,形参a,b分别为积分上下限,fun是被积函数。该函数用来求积分值。
资源推荐
资源详情
资源评论
收起资源包目录
aaa.rar (19个子文件)
积分计算
aaa.cpp 1KB
积分计算.vcxproj 4KB
积分计算.vcxproj.filters 941B
Debug
vc110.idb 259KB
CL.write.1.tlog 432B
CL.read.1.tlog 12KB
积分计算.lastbuildstate 79B
cl.command.1.tlog 670B
link-cvtres.read.1.tlog 2B
积分函数.log 2KB
link.write.1.tlog 496B
link-rc.write.1.tlog 2B
积分函数.lastbuildstate 111B
link-cvtres.write.1.tlog 2B
link.command.1.tlog 1KB
link-rc.read.1.tlog 2B
link.read.1.tlog 3KB
vc110.pdb 332KB
源.obj 151KB
共 19 条
- 1
资源评论
周楷雯
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功