Please can anyone tell me why that program crashes when I enter the first matrix?
#include<iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
void menu()
{
cout<<" \t\t\t\t*-*-UNIATIVE Matrix calculator-*-*\t\t\t\t "<<"\n";
cout<<" "<<(char)1<<" NNNN MMMM AAAA "<<(char)1<<" "<<"\n";
system ("color 08");
_sleep(1000);
cout<<" \t\t\t *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\t\t\t"<<"\n";
cout<<"Ahlan washlan ya user Ya Habibi,Wahashteni Awi Awi"<< (char)1 <<"\n";
cout<<" "<<"\n";
cout<<"Please choosen from the following menu."<<"\n";
cout<<" "<<"\n";
system ("color 05");
cout<<"1. Matrix Addition "<<"\n";
cout<<"2. Matrix subtraction "<<"\n";
cout<<"3. Matrix Multiplication "<<"\n";
cout<<"4. Matrix Transpose "<<"\n";
cout<<"5. check Matrix properties "<<"\n";
cout<<"6. Matrix Inversion "<<"\n";
cout<<"7. Matrix power "<<"\n";
cout<<"8. Exit "<<"\n";
cout<<"please Enter your choice==>"<<"\n"<<"\n";
}
void read( int **matr1,int **matr2,int& rows,int& cols,int& rows2,int& cols2){
cout<<"please enter the dimensions of the matrix one==>"<<"\n";
cin>>rows>>cols;
cout<<"please enter the first matrix"<<"\n";
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
cin>>matr1[i][j];
}
cout<<"please enter the dimensions of the matrix one==>"<<"\n";
cin>>rows2>>cols2;
cout<<"please enter the second matrix"<<"\n";
for(int i=0;i<rows2;i++)
{
for(int j=0;j<cols2;j++)
cin>>matr2[i][j];
}
delete matr1;
delete matr2;
}
void read2 ( int **matr1,int& rows,int& cols){
cout<<"please enter the dimensions of the matrix==>"<<"\n";
cin>>rows>>cols;
cout<<"please enter the matrix"<<"\n";
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
cin>>matr1[i][j];
}
}
void writeMat( int **matr1,int &rows,int &cols)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout<<matr1[i][j]<<" ";
}
cout<<endl;
}
delete matr1;
}
void sumMat(int **matr1 ,int **matr2 ,int &rows,int& cols,int& rows2,int& cols2)
{
int ** result= new int *[rows];
for(int i=0;i<rows;i++)
{
result[i]=new int [cols];
}
read( matr1,matr2,rows,cols,rows2,cols2);
writeMat( matr1,rows,cols);
cout<<endl<<"+"<<endl;
writeMat( matr1,rows,cols);
cout<<endl<<"="<<endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
result[i][j]=matr1[i][j]+matr2[i][j];
}
for(int i=0;i<cols;i++)
{
for(int j=0;j<rows;j++)
{
cout<<result[i][j]<<" ";
}
cout<<"\n";
}
delete result;
delete matr1;
delete matr2;
}
void subtraction(int **matr1,int **matr2,int rows,int cols,int& rows2,int& cols2)
{
int ** result= new int *[rows];
for(int i=0;i<rows;i++)
{
result[i]=new int [cols];
}
read( matr1,matr2,rows,cols,rows2,cols2);
writeMat( matr1,rows,cols);
cout<<endl<<"-"<<endl;
writeMat( matr1,rows,cols);
cout<<endl<<"="<<endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
result[i][j]=matr1[i][j]-matr2[i][j];
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout<<result[i][j]<<" ";
}
cout<<"\n";
}
delete matr1;
delete matr2;
delete result;
}
void transpose(int **matr1,int rows,int cols)
{
read2 ( matr1, rows,cols);
writeMat( matr1,rows,cols);
cout<<"after transposing ";
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
cout<<matr1[j][i]<<" ";
}
cout<<"\n";
delete matr1;
}
void symmCheck(int **matr1,int& rows,int& cols)
{
read2 ( matr1, rows,cols);
if(rows==cols)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if(matr1[i][j]==matr1[j][i]){
cout<<" this matrix is symmetric "<<endl;
}
else if(matr1[i][j]== -matr1[j][i])
{
cout<<" this matrix is antisymmetric "<<endl;
}
}
}
}
else {
cout<<"da5al el rows wel columns zee ba3d ya user ya 7abeby :)"<<endl;
return symmCheck(matr1, rows,cols);
}
delete matr1;
}
void digonalcheck(int **matr1,int& rows,int& cols)
{
read2 ( matr1, rows,cols);
if(rows==cols)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if(matr1[i][j]==0&&matr1[i][i]!=0)
{
cout<<" this matrix is diagonal "<<endl;
}
else {
cout<<" this matrix is not digonal "<<endl;
}
if(matr1[i][j]==0&&matr1[j][j]!=0)
{
cout<<" this matrix is off digonal "<<endl;
}
}
}
}
else {
cout<<"da5al el rows wel columns zee ba3d ya user ya 7abeby :)"<<endl;
return digonalcheck(matr1, rows, cols);
}
delete matr1;
}
void identityCheck(int **matr1,int& rows,int& cols)
{
read2 ( matr1, rows,cols);
if(rows==cols)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if(matr1[i][j]==0&&matr1[i][i]==1)
{
cout<<" this matrix is Identity " <<endl;
}
else {
cout<<" this matrix is not Identity " <<endl;
}
}
}
}
}
void tringLower( int **matr1,int& cols, int& rows)
{
int count=0;
if (cols==rows)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if((j>i) && (matr1[i][j]==0))
{
count++;
}
}
}
if(count==3)
{
cout<<"\n\tlower Tringular\n";
}
else
{
cout<<"\n\tnot tringular\n";
}
}
else{
cout<<" ya user ya amor da5al el rows wel columns zaee ba3d"<<endl;
tringLower( matr1,cols,rows);
}
}
void tringupper( int **matr1,int& cols, int& rows)
{
int count=0;
if (cols==rows)
{
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
if((j<i) && (matr1[i][j]==0))
{
count++;
}
}
}
if(count==3)
{
cout<<"\n\tUpper Tringular\n";
}
else
{
cout<<"\n\tnot tringular\n";
}
}
else{
cout<<" ya user ya amor da5al el rows wel columns zaee ba3d"<<endl;
tringupper(matr1, cols, rows);
}
cout<<endl;
}
int power1(int** matr1,int** matr2,int& rows,int& cols)
{
int power2;
int **result;
result=new int*[rows];
for(int i=0;i<rows;i++)
{
result[i]=new int[cols];
}
read2( matr1,rows,cols);
cout<<"please enter your power "<<endl;
cin>>power2;
writeMat( matr1,rows,cols);
cout<<endl<<"to the power "<<power2<<endl;
cout<<"="<<endl;
for(int i=0;i<power2;i++)
{
for(int j=0;j<rows;j++)
{
for(int k=0;k<cols;k++)
{
result[j][i]=0;
for(int l=0;l<cols;l++)
{
result[j][i]+=matr1[j][l]*matr2[l][i];
}
cout<<result[j][i]<<"\t";
}
cout<<endl;
}
}
}
int main()
{
int rows ,cols,rows2,cols2;
int **matr1,**matr2;
bool flag1,flag2,flag=true;
int choice;
while(flag==true)
{ int choice;
menu();
cin>>choice;
switch (choice)
{
case 1:
sumMat(matr1 ,matr2 , rows, cols,rows2,cols2);
break;
case 2: subtraction(matr1,matr2,rows,cols,rows2,cols2);
break;
case 3:
break;
case 4:
transpose(matr1,rows,cols);
break;
case 5:digonalcheck(matr1, rows,cols);
identityCheck(matr1,rows,cols);
identityCheck(matr1, rows,cols);
symmCheck(matr1, rows,cols);
tringLower( matr1,cols,rows);
tringupper( matr1,cols, rows);
break;
case 6:
break;
case 7:
power1( matr1, matr2, rows, cols);
break;
case 8:
system ("pause");
return 0;
break;
default :
cout<<" ya abeny homa 8 2odamak ";
}
}
delete matr1;
delete matr2;
system("pause");
return 0;
}