Friday 11 July 2014

Addition of Two matrices using oop



#include<iostream.h>
#include<conio.h>
class matrix
{
public:
int i,j,row,col,a[10][10],b[10][10],c[10][10];
void getdata();
void sumdata();
void putdata();
};
void matrix::getdata()
{
cout<<"Enter the size of row and column of Matrices:";
cin>>row>>col;
cout<<"Enter the elements for Ist"<<row<<"x"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>a[i][j];
}}
cout<<"Enter the elements for IInd"<<row<<"X"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>b[i][j];
}}}
void matrix::sumdata()
{
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}}
void matrix::putdata()
{
cout<<"the sum of matrix is:";
for(i=0;i<row;i++)
{
cout<<"\n";
for(j=0;j<col;j++)
{
cout<<"\t"<<c[i][j];
}}}
void main()
{
clrscr();
matrix obj;
obj.getdata();
obj.sumdata();
obj.putdata();
getch();
}

No comments:

Post a Comment