this below represents the main of my class Matrix source code.from my main i want to do mathemetical operations such as add ,subtract, multiple, IF the operation was any of the previous mention then 2 or more matrices are needed, if i am doing inverse or determinant, then only i matrix is needed.My question is , how may i restructure this code to request the user to determine operation then request size and elements of the needed matrix??
as is it will request the matrix dimention request elements and crash
I tried to prompt the user to enter the dimention of the matrix to be worked on, and thereafter enter the specific elements,
what happend next it BOOM!!!! it crashes, WHY?
IF I compiles and run my main independent of my "class Matrix" it executes, would some error in my class contribute?
cout<<"\nTHIS ASSIGNMENT IS TO COVER THE FOLLOWING: "<<endl;
cout<<"\n > Find and displaying Determinant"<<endl;
cout<<"\n > Find and displaying the Inverse"<<endl;
cout<<"\n matrix"<<endl;
cout<<"\n > Carrying out row transformation"<<endl;
cout<<"\n > Addition & Subtraction"<<endl;
cout<<"\n > Multiplicationn & division"<<endl;
cout<<"\n"<<endl;
cout<<"\n1.Add matrices\n2.Subtract matrices\n3.Multiplymatrices\n4.Find determinant\n5.Find INverse"<<endl;
cout<<"Select any one above , then hit ENTER"<<endl;
cin>>x;
if(x==1)
{
cout<<"enter the dimension of matrix A:";
Matrix A = Matrix(rows,cols);
cin>>rows ;
cout<<"enter cols:";
cin>>cols ;
cout<<"enter the elements of matrix A:";
for (int r = 0; r < rows; r++)
{ for (int c = 0; c < cols; c++)
{
cin>>A(r,c);
}
}
cout<<"enter the dimension of matrix B:";
Matrix B = Matrix(cols, rows);
cout<<"enter the elements of matrix B:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>B(r,c);
}
}
Matrix C;
C = A + B;
printf("A + B = \n");
C.Print();
printf("\n");
}
else if(x==2)
{ cout<<"enter the dimension of matrix A:";
cin>>rows>>cols;
Matrix A = Matrix(cols, rows);
cout<<"enter the elements of matrix A:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>A(r,c);
}
}
Matrix B = Matrix(cols, rows);
cout<<"enter the elements of matrix B:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>B(r,c);
}
}
Matrix C;
C = A - B;
printf("A - B = \n");
C.Print();
printf("\n");
}
else if (x==3)
{
cout<<"enter the dimension of matrix A:";
cin>>rows>>cols;
Matrix A = Matrix(cols, rows);
cout<<"enter the elements of matrix A:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>A(r,c);
}
}
Matrix B = Matrix(cols, rows);
cout<<"enter the elements of matrix B:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>B(r,c);
}
}
Matrix C;
C = A * B;
printf("A * B2 = \n");
C.Print();
printf("\n");
}
else if (x==4)
{
cout<<"enter the dimension of matrix for which you want to find its det:";
cin>>rows>>cols;
Matrix A = Matrix(cols, rows);
cout<<"enter the elements of matrix A:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>A(r,c);
}
}
printf("A = \n");
A.Print();
printf("Det(A) = %f\n\n", Det(A));
}
else if(x==5)
{
cout<<"enter the dimension of matrix A:";
cin>>rows>>cols;
Matrix A = Matrix(cols, rows);
cout<<"enter the elements of matrix A:";
for (int r=0;r<rows;r++)
{ for (int c=0;c<cols;c++)
{
cin>>A(r,c);
}
}
Matrix A_inv = Inv(A);
printf("Inv(A) = \n");
A_inv.Print();
printf("\n");
}
else
cout<<"wrong choice";
cout<<"\nContinue(y/n)";
cin>>ch;
} while (ch=='y'||ch=='Y');
cin.get();
PAUSE;
getch ();
}