新手学编程C++ 寻人指导
偶一个没任何编程基础的人``想学C++``好心人帮帮忙``怎么学``先学哪些``在下先谢谢了
开始的时候编些简单的输出问题,然后再函数,叔祖,指针什么的
#include<iostream>#include<cmath>
using namespace std;
double integration(double a, double b, double (*fun)(double));
double f(double);
double g(double);
double h(double);
int main(){
double PI=3.14159;
double half_PI=PI/2;
cout<<"函数f(x)在[1,3]上的积分为:"<<integration(1,3,f)<<endl;
cout<<"函数g(x)在[0,1]上的积分为:"<<integration(0,1,g)<<endl;
cout<<"函数h(x)在[0,half_PI]上的积分为:"<<integration(0,half_PI,h)<<endl;
}
double integration(double a, double b, double (*fun)(double x)){
double p=0.000001,s=0,s_m=s,l;
for(int m=1;fabs(s-s_m)<p;m++){
for(int i=0;i<=m;i++){
l=(b-a)/m;
s=s+((*fun)(i*l+a)+(*fun)((i+1)*l+a))*0.5;
}
return s;
}
}
double f(double x){
return 1/x;
}
double g(double x){
return exp(x)/(1+exp(x));
}