below :
=========================================
#include<iostream>
#include<stdio.h>
#include<string.h>
#define max 10
using namespace std;
bool plus_minus;
class MatrixOperation
{ private:
int i,j,k,Ar,Ac,Br,Bc,MA[max][max],MB[max][max],MC[max][max];
char NameMatrix;
public:
//---------------------------------------
void InputDimention(void)
{ loop:
cout<<"====Multiply of Matrix <<Maxinum (10x10)>>====\nInput Demintion of Matrix A :\n";
cout<<"row : ";cin>>Ar;
cout<<"column : ";cin>>Ac;
cout<<"\nInput Demintion of Matrix B :\n";
cout<<"row : ";cin>>Br;
cout<<"column : ";cin>>Bc;
if(Ac!=Br)
{ cout<<"\n***Can't multiply Matrix , Please try again ! >\n\a\n";
goto loop;
}
if((Ar==Ac)&&(Br==Bc))
{ cout<<"\n***Can plus or minu Matrix A & B !\n\a\n";
plus_minus=true;
}
else
cout<<"\n***Can't plus or minu Matrix A & B !\n***But can multiply Matrix A*B\a\n";
}
//-------------------------------------
void InputMatrix(void)
{ cout<<"Input Matrix A ("<<Ar<<"x"<<Ac<<") : \n"<<endl;
for(i=1;i<=Ar;i++)
for(j=1;j<=Ac;j++)
{ cout<<"MA["<<i<<"]["<<j<<"]: ";
cin>>MA[i][j];
}
cout<<"Input Matrix B ("<<Br<<"x"<<Bc<<") : \n"<<endl;
for(j=1;j<=Br;j++)
for(k=1;k<=Bc;k++)
{ cout<<"MA["<<j<<"]["<<k<<"]: ";
cin>>MB[j][k];
}
cout<<"\nMatrix A :\n";
for(i=1;i<=Ar;i++)
{ cout<<"\t";
for(j=1;j<=Ac;j++)
cout<<MA[i][j]<<"\t";
cout<<"\n";
}
cout<<"\nMatrix B :\n";
for(j=1;j<=Br;j++)
{ cout<<"\t";
for(k=1;k<=Bc;k++)
cout<<MB[j][k]<<"\t";
cout<<"\n";
}
}
//---------------------------------------
void MultiplyMatrix(void)
{ for(i=1;i<=Ar;i++)
for(k=1;k<=Bc;k++)
{ MC[i][k]=0;
for(j=1;j<=Ac;j++)
MC[i][k]+=(MA[i][j]*MB[j][k]);
}
}
//------------------------------------
void DisplayMulti(void)
{ cout<<"\n=========Result of Multiply Matrix A*B===========\nAxB : \n";
for(i=1;i<=Ar;i++)
{ cout<<"\t";
for(k=1;k<=Bc;k++)
cout<<MC[i][k]<<"\t";
cout<<endl;
}
}
//-----------------------------------------
void PlusMinusMatrix(void)
{ cout<<"\n=======Result of Plus and Minus A+B & A-B ========\n";
cout<<"A + B :\n\n";
for(i=1;i<=Ar;i++)
{ cout<<"\t";
for(j=1;j<=Ac;j++)
cout<<MA[i][j]+MB[i][j]<<"\t";
cout<<endl;
}
cout<<"\n=================================================\nA - B :\n\n";
for(i=1;i<=Ar;i++)
{ cout<<"\t";
for(j=1;j<=Ac;j++)
cout<<MA[i][j]-MB[i][j]<<"\t";
cout<<endl;
}
cout<<"\n=================================================";
}
};
int main()
{ MatrixOperation Obj;
Obj.InputDimention();
Obj.InputMatrix();
Obj.MultiplyMatrix();
Obj.DisplayMulti();
if(plus_minus==true)
Obj.PlusMinusMatrix();
return 0;
}
No comments:
Post a Comment