Exp18_动态内存分配(一).docVIP

  • 9
  • 0
  • 约2.65千字
  • 约 4页
  • 2020-09-23 发布于广东
  • 举报
实验十八 动态内存分配(一) 一、实验目的 1. 掌握使用模板函数利用矩形法求积分 1. 联系使用动态内存分配方式实现字符串类mystring 实验内容 设计梯形积分法函数模板,求函数fx #includeiostream using namespace std; class F{ public: double fun(double x){ return (x*x*x*x*x+6*x*x*x+x*x+9); } }; templatetypename Tdouble integer(T f,double a,double b,int n){ double result,step; step=(b-a)/n; result=(f.fun(a)+f.fun(b))/2; for(int i=1;in;i++) result+=f.fun(a+i*step); result*=step; return result; } int main(){ F f; double result0; int n=1000; result0=integer(f,0.1,3.4,n); cout函数f(x)=x*x*x*x*x+6*x*x*x+x*x+9在区间[0.1, 3.4]的积分为result0endl; return 0; } 2、仿照标准字符串类string

文档评论(0)

1亿VIP精品文档

相关文档