September 4, 2012 / IST / Language.

#include<iostream.h>
#include<conio.h>
class promatrix
{
private:
int m1[10][10],m2[10][10],p[10][10];
int r,c,i,j,k;
public:
promatrix(); //constructor
void getmatrix();
void product();
void disprslt();
};
promatrix::promatrix()
{ for(i=0;i<10;i++)
for(j=0;j<10;j++) //external defination of constructor
{
m1[i][j]=m2[i][j]=p[i][j]=0;
}
}
void promatrix::getmatrix()
{
cout<<"\n\nEnter the size of the Matrix you want to Multiply:";
cout<<"\n\nNumber of Rows:";
cin>>r;
cout<<"\n\nNumber of Columns:";
cin>>c;

cout<<"\n\nEnter the Matrices:";
cout<<"\nMATRIX 1:";
for(i=0;i<r;i++)
for(j=0;j<c;j++) //function to get the matrix
{
cin>>m1[i][j];
}

cout<<"\n\nMATRIX 2:";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cin>>m2[i][j];
}

}
void promatrix::product()
{
for(i=0;i<r;i++)
for(j=0;j<c;j++) //function to multiply the matrices
for(k=0;k<r;k++)
p[i][j]+=m1[i][k]*m2[k][j];
}
void promatrix::disprslt()
{
cout<<"\nMatrices You Entered Are:";
cout<<"\n\nMATRIX 1:";
for(i=0;i<r;i++)
{cout<<"\n\t\t";
for(j=0;j<c;j++)
{
cout<<m1[i][j]<<" ";
}
}
cout<<"\nMATRIX 2:"; //function to display the result
for(i=0;i<r;i++)
{cout<<"\n\t\t";
for(j=0;j<c;j++)
{
cout<<m2[i][j]<<" ";
}
}
cout<<"\nProduct of the Given Two Matrices is:";
for(i=0;i<r;i++)
{cout<<"\n\t\t";
for(j=0;j<c;j++)
{
cout<<p[i][j]<<" ";
}
}
}
void main() //main function
{
promatrix ob;
char ch;
do
{clrscr();
cout<<"\n\t\tMATRIX MULTIPLICATION MENU";
cout<<"\n\t\t--------------------------";
ob.getmatrix();
ob.product(); //calling the functions
ob.disprslt();
cout<<"\nDo You Want To Continue(Y/N):";
cin>>ch;
}while(ch=='y' || ch=='Y');

}