#include
#include
const char * file_name="shuju.txt";
class LineEqt
{
private:
int n; //方程组的维数
double **A; //系数矩阵A
double *b; //常数向量b
double *x; //方程组的解x
public:
LineEqt();
~LineEqt();
void Input(int); //输入方程组
//void Show(); //显示方程组
//void ShowRoot();//显示方程组的根
//void GetRoot(); //选择合适的算法求解
//void Gauss(char file_name[]); //高斯求解(将保存结果的文件名作为形参)
//void LU(char file_name[]); //LU 分解求解(将保存结果的文件名作为形参)
};
/*const double ep = 1e-8;
const char* Error[] =
{
"Error_0:\n Failed to open file for getting values, Check to make sure to Be correct !",
"Error_1:\n Failed to open file for outputing, Check to make sure to Be correct !",
"Error_2:\n No root! Coefficient matrix is Singular matrix.",
//后面的字符串与Gauss 和LU 法关系不大,故不再列举
};*/
LineEqt::LineEqt():A(0),b(0)
{
A=0;
b=0;
}
LineEqt::~LineEqt()
{
delete [] b;
for(int i=0;i
delete[] A;
}
void LineEqt::Input(int number)
{
n = number;
ifstream input_file;
ofstream output_file;
int i,j;
b = new double[n];
A = new double*[n];
for(i = 0;i != n; i++)
A[i] = new double[n];
output_file.open(file_name);
if(!output_file)
{
cout<<"Can not open file_name!"<
for(i=0;i
for(j=0;j
cout<<"kkkkk";
output_file< }
output_file<
for(i=0;i
output_file< }
output_file.close();
}
void main(){
LineEqt o;
int n;
cout<<"请输入方程组维数:"<
o.Input(n);
}
指针动态内存分配问题!
改动主要是Input函数的动态分配内存给A和b,析构函数释放动态分配的内存!