程式和書上的比對過,應該是一樣的,為什么會死回圈呢?
圖片順序:類的宣告頭函式,函式實作,主函式,書上的范例。





uj5u.com熱心網友回復:
真不愿意再輸入一遍這個程式,最好是您將程式貼出來,然后回答人還可以 COPY 下來除錯一下程式。uj5u.com熱心網友回復:
#ifndef HEAD_H_INCLUDED
#define HEAD_H_INCLUDED
class Function{
public:
virtual double operator()(double x)const=0;
~Function(){}
};
class fun:public Function{
public:
virtual double operator()(double x)const;
};
class integ{
public:
virtual double operator()(double a,double b,double esp)const=0;
~integ(){}
};
class integration:public integ{
public:
integration(const Function& f):f(f){}
virtual double operator()(double a,double b,double esp)const;
private:
const Function &f;
};
#endif // HEAD_H_INCLUDED
#include"head.h"
#include<cmath>
double fun::operator()(double x)const{
return log(1.0+x)/(1.0+x*x);
}
double integration::operator()(double a,double b,double esp)const{
bool io=false;
int n=1;
double t2n=0;
double h=b-a;
double tn=h*(f(a)+f(b))/2;
do{
double sum=0;
for(int i=0;i<n;i++){
sum+=f(a+0.5+i);
}
t2n=(tn+h*sum)/2.0;
if(fabs(t2n-tn)<esp){
io=true;
}else{
tn=t2n;
h/=2;
n*=2;
}
}while(!io);
return t2n;
}
#include <iostream>
#include"head.h"
#include"5.10.cpp"
using namespace std;
int main()
{
fun x;
integration a(x);
cout<<"ê?3??a"<<endl
<<a(0,2,1e-7)<<endl
<<"?£"<<endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/25950.html
標籤:新手樂園
上一篇:求演算法題題解
