using namespace std;
#define row 10
#define col 10
int row1,row2,col1,col2;
class matrix
{
int a[row][col];
int b[row][col];
int c[row][col];
public :
void input();
void addtion();
void subtraction();
void multiply();
void show();
};
void matrix::input()
{
int i,j;
cout<<"enter the number of row of first matrix\n";
cin>>row1;
cout<<"enter the number of coloumn of first matrix\n";
cout<<"enter the elements of first matrix";
for loop from i=0 upto row1;
{
for loop from j=0 upto col1;
{
cin>>a[i][j];
}
}
cout<<"enter the number of row & coloumn of second matrix";
cin>>row2>>col2;
cout<<"enter the elements of second matrix";
for loop from i=0 upto row2;
{
for loop from j=0 upto col2;
{
cin>>b[i][j];
}
}
}
void matrix::addtion()
{
int i,j;
for loop from i=0 upto row1;
{
for loop from j=0 upto col2;
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void matrix::subtraction()
{
int i,j;
for loop from i=0 upto row1;
{
for loop from j=0 upto col1;
{
c[i][j]=a[i][j]-b[i][j];
}
}
}
void matrix::multiply()
{
int i,j,k,sum=0;
for loop from k=0 upto col2;
{
for loop from i=0 upto row1;
{
sum=0;
for loop from j=0 upto col1;
{
sum=sum+a[i][j]*b[j][k];
}
c[i][k]=sum;
}
}
}
void matrix::show()
{
int i,j;
for loop from i=0 upto row1;
{
for loop from j=0 upto col1;
{
print two dimension array c according to i and j<<' ';
}
cout<<"\n";
}
}
int main()
{
matrix m;
int ch;
m.input();
while(1)
{
cout<<"options:-\npress 1 for addition\npress 2 for subtraction\npress 3 for multiplication\npress any other key for exit\n";
cin>>ch;
switch(ch)
{
case 1:
if(row1!=row2 ||col1!=col2)
cout<<"addition is not possible\n";
else
{
m.addtion();
m.show();
}
break;
case 2:
if(row1!=row2 ||col1!=col2)
cout<<"subtraction is not possible\n";
else
{
m.subtraction();
m.show();
}
break;
case 3:
if(col1!=row2)
cout<<"multiplicaton is not possible\n";
else
{
m.multiply();
m.show();
}
break;
default:
exit(1);
}
}
}
if you don't want to talk, then why you say that "for any kind of help, you can contact me">>
ReplyDeleteIT SHOULD BE LIKE THIS
DON'T CALL ME I AM VERY BUSY PERSON CANT HELP YOU...