开发者社区> 问答> 正文

这段程序代码怎么改??????

#include "iostream"
using namespace std;
class Gelr
{
public:
void gelr1(double t,double y[] ,int n,double h,int k,double z[][11]);
void gelrf(double t,double y[],int n,double d[]);
//void display();
protected:
double t;
double y[3];
int n;
double h;
int k;

double z[3][11];
double d[3];
};
void Gelr::gelr1(double t,double y[],int n,double h,int k, double x[])
{
int i,j;
double x,*d;
d=static_cast(malloc(n*sizeof(double)));
for (i=0; i<=n-1; i++) z[i*k]=y[i];
for (j=1; j<=k-1; j++)
{ x=t+(j-1)*h;
gelrf(x,y,n,d);
for (i=0; i<=n-1; i++)
y[i]=z[i*k+j-1]+h*d[i];
x=t+j*h;
gelrf(x,y,n,d);
for (i=0; i<=n-1; i++)
d[i]=z[i*k+j-1]+h*d[i];
for (i=0; i<=n-1; i++)
{ y[i]=(y[i]+d[i])/2.0;
z[i*k+j]=y[i];
}
}
free(d); return;
}
void Gelr::gelrf(double t,double y[],int n,double d[])
{
t=t;
n=n;
d[0]=y[1];
d[1]=-y[0];
d[2]=-y[2];
return;
}
int main()
{
int i,j;
double y[3],z[3][11],t,h,x;
y[0]=-1.0; y[1]=0.0; y[2]=1.0;
t=0.0; h=0.01;
Gelr g;
g.gelr1(t,y,3,h,11,z);
cout<<"\n"<<endl;
for (i=0; i<=10; i++)
{ x=i*h;
cout<<"t:"<<x<<endl;
for (j=0; j<=2; j++)
cout<<"y("<<j<<")=%"<<z[j][i]<<endl;
cout<<"\n"<<endl;
}
cout<<"\n"<<endl;
return 0;
}

--------------------Configuration: sdt - Win32 Debug--------------------
Compiling...
sdt.cpp
D:防灾C++程序设计电子教案微分方程stdsdt.cpp(19) : error C2511: 'gelr1' : overloaded member function 'void (double,double [],int,double,int,double [])' not found in 'Gelr'
D:防灾C++程序设计电子教案微分方程stdsdt.cpp(4) : see declaration of 'Gelr'
执行 cl.exe 时出错.
sdt.exe - 1 error(s), 0 warning(s)

展开
收起
a123456678 2016-03-04 18:28:11 1906 0
1 条回答
写回答
取消 提交回答
  • 在这段代码中,有以下问题:
    1.gelr1函数前没有类的作用域运算符,那么它就不是类的成员函数,g.gelr1(t,y,3,h,11,z)这样的调用要出错;
    2.gelr1中数组z的类型不匹配;
    3.static_cast的用法错了;
    你把代码改成这样:

    void Gelr::gelr1(double t,double y[],int n,double h,int k, double z[][11])
    {
    int i,j;
    double x,*d;
    d=static_cast(malloc(n*sizeof(double)));
    for (i=0; i<=n-1; i++) 
    z[i][0]=y[i];
    for (j=1; j<=k-1; j++)
    { x=t+(j-1)*h;
    gelrf(x,y,n,d);
    for (i=0; i<=n-1; i++)
    y[i]=z[i][j-1]+h*d[i];
    x=t+j*h;
    gelrf(x,y,n,d);
    for (i=0; i<=n-1; i++)
    d[i]=z[i][j-1]+h*d[i];
    z[i][j]=y[i];
    for (i=0; i<=n-1; i++)
    { y[i]=(y[i]+d[i])/2.0;
    }
    }
    free(d); 
    return;
    }
    2019-07-17 18:52:43
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
15分钟打造你自己的小程序 立即下载
小程序 大世界 立即下载
《15分钟打造你自己的小程序》 立即下载