#include<iostream.h>
#include<conio.h>
int i,j;
class Mat
{
int a[3][3],m,n;
public:
Mat(int a , int b)
{
m=a;
n=b;
}
Mat(){}
void show()
{
cout<<"Result:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<endl;
}
}
void input()
{
cout<<"Enter the matrix elements"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"The matrix is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<'\n';
}
}
Mat operator +(Mat);
};
Mat Mat :: operator + (Mat p)
{
Mat temp(m,n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
temp.a[i][j]=a[i][j]+p.a[i][j];
return(temp);
}
void main()
{
int m,n;
cout<<"Enter the size of row";
cin>>m;
cout<<"Enter the size of coloum";
cin>>n;
Mat a(m,n),b(m,n),c;
clrscr();
a.input();
b.input();
c=a+b;
c.show();
getch();
}
#include<conio.h>
int i,j;
class Mat
{
int a[3][3],m,n;
public:
Mat(int a , int b)
{
m=a;
n=b;
}
Mat(){}
void show()
{
cout<<"Result:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<endl;
}
}
void input()
{
cout<<"Enter the matrix elements"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"The matrix is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<'\n';
}
}
Mat operator +(Mat);
};
Mat Mat :: operator + (Mat p)
{
Mat temp(m,n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
temp.a[i][j]=a[i][j]+p.a[i][j];
return(temp);
}
void main()
{
int m,n;
cout<<"Enter the size of row";
cin>>m;
cout<<"Enter the size of coloum";
cin>>n;
Mat a(m,n),b(m,n),c;
clrscr();
a.input();
b.input();
c=a+b;
c.show();
getch();
}
OUTPUT
No comments:
Post a Comment