Search This Blog

Monday, August 16, 2010

C++ program to add two matrices using classes and objects


#include  stdio.h 
#include 
  conio.h 
#include    math.h 
class matrix
{
int a[4][4],b[4][4],i,j,x,y;
public:
void getvalues();
void displaysum();
};
void matrix::getvalues()
{
cout<<"Enter the size of the row and column ";
cin>>x>>y;
if(x!=y)
{
cout<<"The size of the row and column should be equal";
getch();
exit(0);
}
cout<<"Enter values for the matrix A\n";
for(i=0;i
for(j=0;j
cin>>a[i][j];
cout<<"Enter the values for matrix b\n";
for(i=0;i
for(j=0;j
cin>>b[i][j];
}
void matrix::displaysum()
{
cout<<"The sum of matrix A and B is\n";
for(i=0;i
{
for(j=0;j
cout<<<"\t";
cout<
}
}
int main()
{
clrscr();
matrix m;
m.getvalues();
m.displaysum();
getch();
}