按着书本弄的,编译找不到msinoracle 函数编译错误,我很迷茫,求助

当前位置:
&【求助】为什么我编译了一个书本上的无错误的C++程序,却有这么多的错误?
【求助】为什么我编译了一个书本上的无错误的C++程序,却有这么多的错误?
作者 zyj8119
CODE:#include&iostream&
#include&fstream&
#include&cmath&
class bint
& & & & double **a,*b,*x,
& & & & double **p,*r,*e;
& & & & bint(int nn)
& & & & & & & &
& & & & & & & & n=
& & & & & & & & a=new double*[n];
& & & & & & & & for(i=0;i&n;i++)a[i]=new double[n];
& & & & & & & & p=new double*[n];
& & & & & & & & for(i=0;i&n;i++)p[i]=new double[n];
& & & & & & & & r=new double[n];
& & & & & & & & e=new double[n];
& & & & & & & & b=new double[n];
& & & & & & & & x=new double[n];
& & & & void input();
& & & & void a_bint();
& & & & void gauss();
& & & & void output();
& & & & bint()
& & & & & & & &
& & & & & & & & for(i=0;i&n;i++){delete[] a[i];}
& & & & & & & & delete[]
& & & & & & & & for(i=0;i&n;i++){delete[] p[i];}
& & & & & & & & delete[]
& & & & & & & & delete[] r,e,b,x;
void bint::input()
& & & & int i,j;
& & & & char str1[20];
& & & & cout&&&\n输入文件名:&;
& & & & cin&&str1;
& & & & ifstream fin(str1);
& & & & if(!fin)
& & & & {cout&&&\n不能打开这个文件&&&str1&&exit(1);}
& & & & for(i=0;i&n;i++)
& & & & & & & & for(j=0;j&n;j++)fin&&a[i][j];
& & & & & & & & for(i=0;i&n;i++)fin&&b[i];
& & & & & & & & fin.close();
void bint::a_bint()
& & & & int i,j,k;
& & & & double q,
& & & & i=100;
& & & & for(k=0;k&=n-1;k++)
& & & & & & & & for(j=0;j&=n-1;j++)p[k][j]=a[k][j];
& & & & & & & & for(k=0;k&=n-1;k++)r[k]=b[k];
& & & & & & & & gauss();
& & & & & & & & for(k=0;k&n;k++)x[k]=r[k];
& & & & & & & & q=1.0+
& & & & & & & & while(q&=eps)
& & & & & & & & {
& & & & & & & & & & & & if(i==0)
& & & & & & & & & & & & i=i-1;
& & & & & & & & & & & & for(k=0;k&n;k++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & e[k]=0.0;
& & & & & & & & & & & & & & & & for(j=0;j&n;j++)
& & & & & & & & & & & & & & & & & & & & e[k]=e[k]+a[k][j]*x[j];
& & & & & & & & & & & & }
& & & & & & & & & & & & for(k=0;k&=n-1;k++)r[k]=b[k]-e[k];
& & & & & & & & & & & & & & & & for(k=0;k&=n-1;k++)
& & & & & & & & & & & & & & & & & & & & for(j=0;j&=n-1;j++)p[k][j]=a[k][j];
& & & & & & & & & & & & & & & & & & & & gauss();
& & & & & & & & & & & & & & & & & & & & q=0.0;
& & & & & & & & & & & & & & & & & & & & for(k=0;k&=n-1;k++)
& & & & & & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & & & & & qq=fabs(r[k])/(1.0+fabs(x[k]+r[k]));
& & & & & & & & & & & & & & & & & & & & & & & & if(qq&q)q=
& & & & & & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & & & & & for(k=0;k&=n-1;k++)x[k]=x[k]+r[k];
& & & & & & & & }
void bint::gauss()
& & & & int *js,l,k,i,j,
& & & & double d,t;
& & & & js=new int[n];
& & & & l=1;
& & & & for(k=0;k&=n-2;k++)
& & & & & & & & d=0.0;
& & & & & & & & for(i=k;i&=n-1;i++)
& & & & & & & & & & & & for(j=k;j&=n-1;j++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & t=fabs(p[i][j]);
& & & & & & & & & & & & & & & & if(t&d){d=t;js[k]=j;is=i;}
& & & & & & & & & & & & }
& & & & & & & & & & & & if(d+1.0==1.0)l=0;
& & & & & & & & & & & & else
& & & & & & & & & & & & {if(js[k]!=k)
& & & & & & & & & & & & for(i=0;i&=n-1;i++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & t=p[i][k];
& & & & & & & & & & & & & & & & p[i][k]=p[i][js[k]];
& & & & & & & & & & & & & & & & p[i][js[k]]=t;
& & & & & & & & & & & & }
& & & & & & & & & & & & if(is!=k)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & for(j=k;j&=n-1;j++)
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & t=p[k][j];
& & & & & & & & & & & & & & & & & & & & p[k][j]=p[is][j];
& & & & & & & & & & & & & & & & & & & & p[is][j]=t;
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & && &&&t=r[k];r[k]=r[is];r[is]=t;
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & & & & & if(l==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & delete[]
& & & & & & & & & & & & & & & & cout&&&\n系数矩阵奇异!无解.&&&endl
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & & & & & d=p[k][k];
& & & & & & & & & & & & for(j=k+1;j&=n-1;j++)
& & & & & & & & & & & & & & & & p[k][j]=p[k][j]/d;
& & & & & & & & & & & & r[k]=r[k]/d;
& & & & & & & & & & & & for(i=k+1;i&=n-1;i++)
& & & & & & & & & & & & & & & & p[i][j]=p[i][j]-p[i][k]*p[k][j];
& & & & & & & & & & & & r[i]=r[i]-p[i][k]*r[k];
& && && && &d=p[n-1][n-1];
& && && && &if(fabs(d)+1.0==1.0)
& & & & & & & & & & & & {
& && && && && & delete[]
& & & & & & & & & & & & & & & & cout&&&\n系数矩阵奇异!无解.&&&endl
& & & & & & & & & & & && &&&
& & & & & & & & & & & & }
& && && && &r[n-1]=r[n-1]/d;
& && && && &for(i=n-2;i&=0;i--)
& & & & & & & & & & & & {
& & & && && && &t=0.0;
& & & && && && &for(j=i+1;j&=n-1;j++)
& & & & & & & && && &&&t=t+p[i][j]*r[j];
& & & && && && &&&r[i]=r[i]-t;
& & & & & & & & & & & & }
& && && && &js[n-1]=n-1;
& && && & for(k=n-1;k&=0;k--)
& && && & if(js[k]!=k)
& & & & & & & && &{
& & & && && &&&t=r[k];r[k]=r[js[k]];r[js[k]]=t;
& & & & & & & && &}
& && & delete[]
void bint:utput()
& & & & char str2[20];
& & & & cout&&&\n输出文件名:&;
& & & & cin&&str2;
& & & & ofstream fout(str2);
& & & & if(!fout)
& & & & {cout&&&\n不能打开这个文件&&&str2&&exit(1);}
& & & & fout&&cout&&
& & & & for(i=0;i&n;i++)
& & & & & & & & fout&&x[i]&&& &;
& & & & & & & & & & & & cout&&x[i]&&& &;
& & & & fout&&cout&&
& & & & fout.close();
void main()
& & & & bint c(4);
& & & & c.input();
& & & & c.a_bint();
& & & & c.output();
}[ Last edited by zyj8119 on
at 01:57 ]
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
bingtai.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(128) : error C2143: syntax error : missing ';' before 'return'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(139) : error C2501: 'd' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(139) : error C2065: 'p' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(139) : error C2065: 'n' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(139) : error C2109: subscript requires array or pointer type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(139) : error C2109: subscript requires array or pointer type
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(140) : error C2143: syntax error : missing ';' before 'if'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(141) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(141) : error C2447: missing function header (old-style formal list?)
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(146) : error C2057: expected constant expression
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(146) : error C2466: cannot allocate an array of constant size 0
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(146) : error C2501: 'r' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(146) : error C2440: 'initializing' : cannot convert from 'int' to 'int []'
& && &&&There are no conversions to array types, although there are conversions to references or pointers to arrays
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ';' before 'for'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ';' before '&='
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2501: 'i' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ';' before '&='
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ';' before '--'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2501: 'i' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2086: 'i' : redefinition
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2143: syntax error : missing ';' before '--'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(147) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(148) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(148) : error C2447: missing function header (old-style formal list?)
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(154) : error C2057: expected constant expression
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(154) : error C2466: cannot allocate an array of constant size 0
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(154) : error C2501: 'js' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(154) : error C2440: 'initializing' : cannot convert from 'int' to 'int []'
& && &&&There are no conversions to array types, although there are conversions to references or pointers to arrays
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ';' before 'for'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ';' before '&='
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2501: 'k' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ';' before '&='
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ';' before '--'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2501: 'k' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2086: 'k' : redefinition
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2143: syntax error : missing ';' before '--'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(155) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(157) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(157) : error C2447: missing function header (old-style formal list?)
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(160) : error C2143: syntax error : missing ';' before 'delete'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(161) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(161) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(161) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(164) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(164) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
bingtai.obj - 47 error(s), 0 warning(s)
引用回帖:Originally posted by zyj8119 at
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
bingtai.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\1\bingtai.cpp(128) : error C2143: sy ... 用VC++6.0编译。
是你直接抄写的吗?遗漏了很多符号,还有可能是你的编译环境不对,好好看看书上介绍的运行环境吧
里面有些错误是连带的,可以参考下面的修改CODE:#include&iostream&
#include&fstream&
#include&cmath&
class bint
& & & & double **a,*b,*x,
& & & & double **p,*r,*e;
& & & & bint(int nn)
& & & & & & & &
& & & & & & & & n=
& & & & & & & & a=new double*[n];
& & & & & & & & for(i=0;i&n;i++)a[i]=new double[n];
& & & & & & & & p=new double*[n];
& & & & & & & & for(i=0;i&n;i++)p[i]=new double[n];
& & & & & & & & r=new double[n];
& & & & & & & & e=new double[n];
& & & & & & & & b=new double[n];
& & & & & & & & x=new double[n];
& & & & void input();
& & & & void a_bint();
& & & & void gauss();
& & & & void output();
& & & & ~bint()
& & & & & & & &
& & & & & & & & for(i=0;i&n;i++){delete[] a[i];}
& & & & & & & & delete[]
& & & & & & & & for(i=0;i&n;i++){delete[] p[i];}
& & & & & & & & delete[]
& & & & & & & & delete[] r,e,b,x;
void bint::input()
& & & & int i,j;
& & & & char str1[20];
& & & & cout&&&\n输入文件名:&;
& & & & cin&&str1;
& & & & ifstream fin(str1);
& & & & if(!fin)
& & & & {cout&&&\n不能打开这个文件&&&str1&&exit(1);}
& & & & for(i=0;i&n;i++)
& & & & & & & & for(j=0;j&n;j++)fin&&a[i][j];
& & & & for(i=0;i&n;i++)fin&&b[i];
& & & & fin.close();
void bint::a_bint()
& & & & int i,j,k;
& & & & double q,
& & & & i=100;
& & & & for(k=0;k&=n-1;k++)
& & & & & & & & for(j=0;j&=n-1;j++)p[k][j]=a[k][j];
& & & & for(k=0;k&=n-1;k++)r[k]=b[k];
& & & & gauss();
& & & & for(k=0;k&n;k++)x[k]=r[k];
& & & & q=1.0+
& & & & while(q&=eps)
& & & & & & & & if(i==0)
& & & & & & & & i=i-1;
& & & & & & & & for(k=0;k&n;k++)
& & & & & & & & {
& & & & & & & & & & & & e[k]=0.0;
& & & & & & & & & & & & for(j=0;j&n;j++)
& & & & & & & & & & & & & & & & e[k]=e[k]+a[k][j]*x[j];
& & & & & & & & }
& & & & & & & & for(k=0;k&=n-1;k++)r[k]=b[k]-e[k];
& & & & & & & & for(k=0;k&=n-1;k++)
& & & & & & & & & & & & for(j=0;j&=n-1;j++)p[k][j]=a[k][j];
& & & & & & & & gauss();
& & & & & & & & q=0.0;
& & & & & & & & for(k=0;k&=n-1;k++)
& & & & & & & & {
& & & & & & & & & & & & qq=fabs(r[k])/(1.0+fabs(x[k]+r[k]));
& & & & & & & & & & & & if(qq&q)q=
& & & & & & & & }
& & & & & & & & for(k=0;k&=n-1;k++)x[k]=x[k]+r[k];
void bint::gauss()
& & & & int *js,l,k,i,j,
& & & & double d,t;
& & & & js=new int[n];
& & & & l=1;
& & & & for(k=0;k&=n-2;k++)
& & & & & & & & d=0.0;
& & & & & & & & for(i=k;i&=n-1;i++)
& & & & & & & & & & & & for(j=k;j&=n-1;j++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & t=fabs(p[i][j]);
& & & & & & & & & & & & & & & & if(t&d){d=t;js[k]=j;is=i;}
& & & & & & & & & & & & }
& & & & & & & & if(d+1.0==1.0)l=0;
& & & & & & & & else
& & & & & & & & {
& & & & & & & & & & & & if(js[k]!=k)
& & & & & & & & & & & & for(i=0;i&=n-1;i++)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & t=p[i][k];
& & & & & & & & & & & & & & & & p[i][k]=p[i][js[k]];
& & & & & & & & & & & & & & & & p[i][js[k]]=t;
& & & & & & & & & & & & }
& & & & & & & & & & & & if(is!=k)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & for(j=k;j&=n-1;j++)
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & t=p[k][j];
& & & & & & & & & & & & & & & & & & & & p[k][j]=p[is][j];
& & & & & & & & & & & & & & & & & & & & p[is][j]=t;
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & t=r[k];r[k]=r[is];r[is]=t;
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & & & & & if(l==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & delete[]
& & & & & & & & & & & & & & & & cout&&&\n系数矩阵奇异!无解.&&&
& & & & & & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & & & & & d=p[k][k];
& & & & & & & & & & & & for(j=k+1;j&=n-1;j++)
& & & & & & & & & & & & & & & & p[k][j]=p[k][j]/d;
& & & & & & & & & & & & r[k]=r[k]/d;
& & & & & & & & & & & & for(i=k+1;i&=n-1;i++)
& & & & & & & & & & & & & & & & p[i][j]=p[i][j]-p[i][k]*p[k][j];
& & & & & & & & & & & & r[i]=r[i]-p[i][k]*r[k];
d=p[n-1][n-1];
if(fabs(d)+1.0==1.0)
& & & & delete[]
& & & & cout&&&\n系数矩阵奇异!无解.&&&
& & & & & & & &
r[n-1]=r[n-1]/d;
for(i=n-2;i&=0;i--)
& & & & t=0.0;
& & & & for(j=i+1;j&=n-1;j++)
& & & & & & & & t=t+p[i][j]*r[j];
& & & & r[i]=r[i]-t;
js[n-1]=n-1;
for(k=n-1;k&=0;k--)
if(js[k]!=k)
& & & & t=r[k];r[k]=r[js[k]];r[js[k]]=t;
& & & & void bint:utput()
& & & & & & & &
& & & & & & & & char str2[20];
& & & & & & & & cout&&&\n输出文件名:&;
& & & & & & & & cin&&str2;
& & & & & & & & ofstream fout(str2);
& & & & & & & & if(!fout)
& & & & & & & & {cout&&&\n不能打开这个文件&&&str2&&exit(1);}
& & & & & & & & fout&&cout&&
& & & & & & & & for(i=0;i&n;i++)
& & & & & & & & {
& & & & & & & & & & & & fout&&x[i]&&& &;
& & & & & & & & & & & & cout&&x[i]&&& &;
& & & & & & & & }
& & & & & & & & fout&&cout&&
& & & & & & & & fout.close();
& & & & void main()
& & & & & & & & bint c(4);
& & & & & & & & c.input();
& & & & & & & & c.a_bint();
& & & & & & & & c.output();
是徐士良书上的吧CODE:&&//3BINT.CPP
&&//求解病态方程组
&&#include&&&iostream&
&&#include&&&fstream&
&&#include&&&cmath&
&&class&&bint
&&private:
& && && &&&
& & & & & & & && & double&&**a, *b, *x,
& & & & & & & && & double&&**p, *r, *e;
& & & && && &&&bint (int nn)
& & & & & & & && & {
& & & & & & & & & & & && &
& & & & & & & & & & & && & n =
& & & && && && && &a = new double*[n];& &//动态分配内存空间
& & & && && && && &for (i=0; i&n; i++) a[i] = new double[n];
& && && && && &p = new double*[n];
& & & && && && && &for (i=0; i&n; i++) p[i] = new double[n];
& && && && && &r = new double[n];
& && && && && &e = new double[n];
& & & && && && && &b = new double[n];
& & & && && && && &x = new double[n];
& & & & & & & && & }
& & & && && &&&void input ();&&//从文件读入系数矩阵A以及常数向量B与eps
& & & & & & & && & void a_bint ();& & //执行求解病态方程组的步骤
& & & & & & & && & void gauss ();& &&&//全选主元Gauss消去法
& && && &&&void output ();& &//输出结果到文件并显示
& & & & & & & && & ~bint ()
& & & & & & & && & {
& & & & & & & & & & & && &
& & & & & & & & & & & && & for (i=0; i&n; i++) { delete [] a[i]; }
& & & & & & & & & & & && & delete []
& & & & & & & & & & & && & for (i=0; i&n; i++) { delete [] p[i]; }
& & & & & & & & & & & && & delete []
& & & & & & & & & & & && & delete [] r, e, b,
& & & & & & & && & }
&&void bint::input ()& & //从文件读入系数矩阵A以及常数向量B与eps
& & & && &int&&i,
& & & && &char str1[20];
& & & && &cout &&&\n输入文件名:&&&;
& & & && &cin &&str1;
& & & && &ifstream&&fin (str1);
& & & && &if (!fin)
& & & && &{ cout &&&\n不能打开这个文件 & &&str1 && exit(1); }
& & & && &for (i=0; i&n; i++)& && && && && && && &&&//读入矩阵A
& & & & & & & && &for (j=0; j&n; j++)&&fin &&a[i][j];
& & & && &for (i=0; i&n; i++)&&fin &&b[i];& && && &&&//读入常数向量B
& & & && &fin.close ();
&&void bint::a_bint ()& && & //执行求解病态方程组的步骤
& & & && &int i,j,k;
& && &double q,
& && &i=100;
& && &for (k=0; k&=n-1; k++)
& && &for (j=0; j&=n-1; j++)&&p[k][j]=a[k][j];
& && &for (k=0; k&=n-1; k++)&&r[k]=b[k];
& && &gauss ();
& && &for (k=0; k&n; k++)&&x[k] = r[k];
& && &q=1.0+
& && &while (q&=eps)
& & & & & & & && &if (i==0)&&
& && && & i=i-1;
& & & & & & & && &for (k=0; k&n; k++)
& & & & & & & && &{
& & & & & & & & & & & && &e[k] = 0.0;
& & & & & & & & & & & && &for (j=0; j&n; j++)&&
& & & & & & & & & & & & & & & && &e[k] = e[k] + a[k][j]*x[j];
& & & & & & & && &}
& && && & for ( k=0; k&=n-1; k++)&&r[k]=b[k]-e[k];
& && && & for ( k=0; k&=n-1; k++)
& && && & for ( j=0; j&=n-1; j++)&&p[k][j]=a[k][j];
& && && & gauss ();
& && && & q=0.0;
& && && & for ( k=0; k&=n-1; k++)
& && && & {
& & & & & & & & & & & && &qq=fabs(r[k])/(1.0+fabs(x[k]+r[k]));
& && && && &&&if (qq&q) q=
& && && & }
& && && & for ( k=0; k&=n-1; k++)&&x[k]=x[k]+r[k];
&&void bint::gauss ()& && && &//执行全选主元Gauss消去法
& & & && &int *js,l,k,i,j,
& && &double d,t;
& && &js = new int[n];
& && &l=1;
& && &for (k=0; k&=n-2; k++)
& & & & & & & && &d=0.0;
& && && & for (i=k;i&=n-1;i++)
& && && & for (j=k;j&=n-1;j++)
& && && & {
& & & & & & & & & & & && &t=fabs(p[i][j]);
& && && && &&&if (t&d) { d=t; js[k]=j; is=i;}
& && && & }
& && && & if (d+1.0==1.0) l=0;
& && && & else
& && && & { if (js[k]!=k)
& && && && &&&for (i=0;i&=n-1;i++)
& && && && &&&{
& && && && && && &t=p[i][k];
& & & & & & & & & & & & & & & && &p[i][k]=p[i][js[k]];
& & & & & & & & & & & & & & & && &p[i][js[k]]=t;
& && && && &&&}
& && && && &&&if (is!=k)
& && && && &&&{
& & & & & & & & & & & & & & & && &for (j=k;j&=n-1;j++)
& && && && && && &{
& && && && && && && & t=p[k][j];
& & & & & & & & & & & & & & & & & & & && &p[k][j]=p[is][j];
& & & & & & & & & & & & & & & & & & & && &p[is][j]=t;
& && && && && && &}
& && && && && && &t=r[k]; r[k]=r[is]; r[is]=t;
& && && && &&&}
& && && & }
& && && & if (l==0)
& && && & {
& & & & & & & & & & & && &delete []
& & & & & & & & & & & && &cout &&&\n系数矩阵奇异!无解.& &&
& && && && &&&
& && && & }
& && && & d=p[k][k];
& && && & for (j=k+1;j&=n-1;j++)
& && && && &&&p[k][j]=p[k][j]/d;
& && && & r[k]=r[k]/d;
& && && & for (i=k+1;i&=n-1;i++)
& && && & {
& & & & & & & & & & & && &for (j=k+1;j&=n-1;j++)
& && && && && && &p[i][j]=p[i][j]-p[i][k]*p[k][j];
& && && && &&&r[i]=r[i]-p[i][k]*r[k];
& && && & }
& && &d=p[n-1][n-1];
& && &if (fabs(d)+1.0==1.0)
& & & & & & & && &delete []
& & & & & & & && &cout &&&\n系数矩阵奇异!无解.& &&
& && &r[n-1]=r[n-1]/d;
& && &for (i=n-2;i&=0;i--)
& & & & & & & && &t=0.0;
& && && & for (j=i+1;j&=n-1;j++)
& && && && &&&t=t+p[i][j]*r[j];
& && && & r[i]=r[i]-t;
& && &js[n-1]=n-1;
& && &for (k=n-1;k&=0;k--)
& && &&&if (js[k]!=k)
& & & & & & & & & & & & t=r[k]; r[k]=r[js[k]]; r[js[k]]=t;
& & & & & & & & }
& & delete []
&&void bint:utput ()& && & //输出结果到文件并显示
& & & && &int&&i;
& & & && &char str2[20];
& & & && &cout &&&\n输出文件名:&&&;
& & & && &cin &&str2;
& & & && &ofstream fout (str2);
& & & && &if (!fout)
& & & && &{ cout &&&\n不能打开这个文件 & &&str2 && exit(1); }
& & & && &fout &&&&cout &&
& & & && &for (i=0; i&n; i++)
& & & && &{
& & & & & & & && &fout &&x[i] &&&& &&;
& & & & & & & && &cout &&x[i] &&&& &&;
& & & && &}
& & & && &fout &&&&cout &&
& & & && &fout.close ();
&&void main ()& && &//主函数
& & & && &bint&&c(4);
& & & && &c.input ();& && && &//从文件读入系数矩阵A以及常数向量B与eps
& & & && &c.a_bint ();& && && &//求解病态方程组
& & & && &c.output ();& && &&&//输出结果到文件并显示
引用回帖:Originally posted by joy4210 at
是徐士良书上的吧
&&//3BINT.CPP
&&//求解病态方程组
&&#include&&&iostream&
&&#include&&&fstream&
&&#include&&&cmath&
&&class&&bint
&&priv ... 是的,是徐士良的常用算法程序集(C++语言描述)
引用回帖:Originally posted by ajian04 at
是你直接抄写的吗?遗漏了很多符号,还有可能是你的编译环境不对,好好看看书上介绍的运行环境吧 是直接抄写的,是不是大括号的位置也是有要求的?????
24小时热帖
下载小木虫APP
与700万科研达人随时交流

我要回帖

更多关于 内联函数 编译 的文章

 

随机推荐