//==============================================
#include<iostream>
#include<stdio.h>
#define max 10
using namespace std;
class Matrix
{ private:
int r,c,i,j,MA[max][max],MB[max][max],MC[max][max];
public:
void InputDimention (void)
{ cout<<"Summation of Matrix\nInput your Matrix's Demintion\n";
cout<<"Number of row : ";cin>>r;
cout<<"Number of column : ";cin>>c;
cout<<"\n->The Dimention of Matrix is ("<<r<<"x"<<c<<")\n";
}
void InputMatrix(void)
{ char NameMatrix;
cout<<"\nSelect Matrix A or B : ";
cin>>NameMatrix;
cout<<endl;
if (( NameMatrix =='A')||(NameMatrix=='a'))
{for (i=1;i<=r;i++)
for(j=1;j<=c;j++)
{ cout<<"A["<<i<<"]["<<j<<"] : ";
cin>>MA[i][j];
}
cout<<"Matrix "<<NameMatrix<<" is :\n";
for (i=1;i<=r;i++)
{ cout<<"|\t";
for(j=1;j<=c;j++)
{ cout<<MA[i][j]<<"\t"; }
cout<<"|\n\n";
}
}
else
{for (i=1;i<=r;i++)
for(j=1;j<=c;j++)
{ cout<<"B["<<i<<"]["<<j<<"] : ";
cin>>MB[i][j];
}
cout<<"Matrix "<<NameMatrix<<" is :\n";
for (i=1;i<=r;i++)
{ cout<<"|\t";
for(j=1;j<=c;j++)
{ cout<<MB[i][j]<<"\t"; }
cout<<"|\n\n";
}
}
}
void OutputSumMatrix(void)
{ cout<<"-----Summation of Matrix A & B :----- \n\n";
for (i=1;i<=r;i++)
{ cout<<"|\t";
for(j=1;j<=c;j++)
{
MC[i][j]=MA[i][j]+MB[i][j];
cout<<MC[i][j]<<"\t";
}
cout<<"|\n\n";
}
}
};
int main()
{ Matrix Obj;
Obj.InputDimention();
Obj.InputMatrix();
Obj.InputMatrix();
Obj.OutputSumMatrix();
return 0;
}
No comments:
Post a Comment