#include <iostream.h>
#include <math.h>
class Base{
public:
double result,a,b,step;
int n;
virtual double fun(double x) (1) ;
virtual void Integerate(){
cout<<"这里是积分函数"<<endl;
}
Base(double ra=0,double rb=0,int nn=2000){
a=ra; b=rb; n=nn; result=0;
}
void Print(){
cout.precision(15);
cout<<"积分值="<<result<<endl;
}
};
class Simpson:public Base{
public:
void Integerate(){
int i;
step=(b-a)/n;
result= (2) ;
for(i=1;i<n;i+=2) result= (3) ;
for(i=2;i<n;i+=2) result= (4) ;
result= (5) ;
}
Simpson(double ra,double rb,int nn): (6) {}
};
class sinS:public Simpson{
public:
sinS(double ra,double rb,int nn): (7) {}
double fun(double x){return sin(x);}
};
class expS: public sinS {
public:
expS(double ra,double rb,int nn): (8) {}
double fun(double x){return exp(x);}
};
void main(){
Base *bp;
sinS ss(0.0,3.1415926535/2.0,100);
bp= (9) ;
bp->Integerate();
bp->Print();
expS es(0.0,1.0,100);
bp= (10) ;
bp->Integerate();
bp->Print();
}
(1) 【 正确答案: 1=0】 (2)【 正确答案: fun(a)+fun(b)】 (3)【 正确答案: result+4fun(istep+a)】 (4)【 正确答案: result+2fun(istep+a)】 (5)【 正确答案: result*step/3】 (6)【 正确答案: Base(ra,rb,nn)】 (7)【 正确答案: Simpson(ra,rb,nn)】 (8)【 正确答案: sinS(ra,rb,nn)】 (9)【 正确答案: &ss】 (10)【 正确答案: &es】
|