Posted by: kaloVale February 11, 2009
Login in to Rate this Post:
0
?
Here is my piece of code which is bothering me really hard.
Basically what this does is read string from of data file.This piece which some how does not read the end of file after all the date in the file are being read. it goes round again and fill the matrix (actually vector) with the last 'num' variable it had read in the loop it had gone through last time. cTable and dTable are filled with same num variable it had read in the previous loop cycle.
for example, if 5 is the last integer 'num' read than it comes round and fill the vectores with 5s.
Case 'E' is the last case in this switch statement and of course 'ch' still has 'E' in it.
do
{
input >> ch;
switch (ch)
{
case 'E': // To read the cofficient of linear equations and find the solutions.
input >> bROW;
if ( bROW > MAX && bROW <= 0)
YesNo(); // if out of bound, asks if want to do it again with another test file.
ClearSMat(bROW); // clears the vectors for next use
for(int i = 0; i < bROW; i++)
{
for(int j = 0; j <= bROW; j++)
{
input >> num;
if (j == bROW)
dTable[i] = num;
else
cTable[i][j] = num;
}
}
SystemOfEqMatrix(bROW);// print the system of linear equations in matrix form
FindSolution(bROW); // find the solution of the linear equations
SolutionMatrix(bROW); // print the solutions
//cin.ignore(1, '/n');
break;
}//end of switch
} while (!input.eof());//end of do - while
Basically what this does is read string from of data file.This piece which some how does not read the end of file after all the date in the file are being read. it goes round again and fill the matrix (actually vector) with the last 'num' variable it had read in the loop it had gone through last time. cTable and dTable are filled with same num variable it had read in the previous loop cycle.
for example, if 5 is the last integer 'num' read than it comes round and fill the vectores with 5s.
Case 'E' is the last case in this switch statement and of course 'ch' still has 'E' in it.
do
{
input >> ch;
switch (ch)
{
case 'E': // To read the cofficient of linear equations and find the solutions.
input >> bROW;
if ( bROW > MAX && bROW <= 0)
YesNo(); // if out of bound, asks if want to do it again with another test file.
ClearSMat(bROW); // clears the vectors for next use
for(int i = 0; i < bROW; i++)
{
for(int j = 0; j <= bROW; j++)
{
input >> num;
if (j == bROW)
dTable[i] = num;
else
cTable[i][j] = num;
}
}
SystemOfEqMatrix(bROW);// print the system of linear equations in matrix form
FindSolution(bROW); // find the solution of the linear equations
SolutionMatrix(bROW); // print the solutions
//cin.ignore(1, '/n');
break;
}//end of switch
} while (!input.eof());//end of do - while