Posted by: kaloVale February 11, 2009
Login in to Rate this Post:
0
?
maverick, there are two cases I and E.. I gave here just E case cause E is the last case and after it read data from the file for case ' E' it should reach to the end of file. Ok here is my whole code in main()
void main()
{
int aROW, bROW, num ;
char ch;
string fileName;
ifstream input;
cout << "Enter the file name : ";
cin >> fileName;
// Attempt to open a disk file
input.open(fileName.data());
if (!input.is_open())
{
cout << "\nFile could not be opened!\n" << endl;
exit(1); // abort execution
}
do
{
input >> ch;
switch (ch)
{
case 'I': // find the inverse of the given matrix, if it is ivertible
input >> aROW;
if ( aROW > MAX && aROW <= 0)
YesNo();
ClearIMat(aROW);
for(int i = 0; i < aROW; i++)
{
for(int j = 0; j < aROW; j++)
{
input >> num;
aTable[i][j] = num;
}
}
OriginalToInverse(aROW);
//identity matrix
for(int i = 0; i < aROW; i++)
{
for(int j = 0; j < aROW; j++)
{
if ( i == j)
bTable[i][j] = 1;
else
bTable[i][j] = 0;
}
}
FindInverse(aROW);
InverseMatrix(aROW);
break;
case 'E': // find the solution of the linear equations
input >> bROW;
if ( bROW > MAX && bROW <= 0)
YesNo();
ClearSMat(bROW);
for(int i = 0; i < bROW; i++)
{
for(int j = 0; j <= bROW; j++)
{
input >> num;
//if (num == 0)
// break;
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
input.close();
} // end of main
void main()
{
int aROW, bROW, num ;
char ch;
string fileName;
ifstream input;
cout << "Enter the file name : ";
cin >> fileName;
// Attempt to open a disk file
input.open(fileName.data());
if (!input.is_open())
{
cout << "\nFile could not be opened!\n" << endl;
exit(1); // abort execution
}
do
{
input >> ch;
switch (ch)
{
case 'I': // find the inverse of the given matrix, if it is ivertible
input >> aROW;
if ( aROW > MAX && aROW <= 0)
YesNo();
ClearIMat(aROW);
for(int i = 0; i < aROW; i++)
{
for(int j = 0; j < aROW; j++)
{
input >> num;
aTable[i][j] = num;
}
}
OriginalToInverse(aROW);
//identity matrix
for(int i = 0; i < aROW; i++)
{
for(int j = 0; j < aROW; j++)
{
if ( i == j)
bTable[i][j] = 1;
else
bTable[i][j] = 0;
}
}
FindInverse(aROW);
InverseMatrix(aROW);
break;
case 'E': // find the solution of the linear equations
input >> bROW;
if ( bROW > MAX && bROW <= 0)
YesNo();
ClearSMat(bROW);
for(int i = 0; i < bROW; i++)
{
for(int j = 0; j <= bROW; j++)
{
input >> num;
//if (num == 0)
// break;
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
input.close();
} // end of main