#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<dos.h>
class maltrix
{
int **arr;
int sh;
int sc;
public:
void nhap();
void xuat();
maltrix(){arr=NULL;};
maltrix(int& ,int& );
maltrix operator +(maltrix& k);
maltrix (maltrix& k);
maltrix operator -(maltrix& k);
maltrix operator *(const maltrix& k);
~maltrix();
};
maltrix::maltrix(int& a,int& b)
{
sh=a;
sc=b;
arr= new int*[sh];
for(int i=0;i<sh;i++)
arr[i]= new int[sc];
}
maltrix::~maltrix()
{
for(int i=0;i<sh;i++)
delete []arr[i];
delete[]arr;
sh=sc=0;
}
maltrix maltrix:: operator +( maltrix& k)
{
if(sh!=k.sh||sc!=k.sc)
{
cout<<"khong cong duoc";
delay(2000);
exit(1);
}

maltrix tam(*this);
for (int i=0;i<sh;i++)
for(int j=0;j<sc;j++)
tam.arr[i][j]=arr[i][j]+k.arr[i][j];
tam.xuat();
return tam;

}
void maltrix :: nhap()
{
for (int i=0;i<sh;i++)
for(int j=0;j<sc;j++)
cin>>arr[i][j];
}
void maltrix::xuat()
{
for (int i=0;i<sh;i++)
{ cout<<endl;
for(int j=0;j<sc;j++)
cout<<&arr[i][j]<<"+";
}
}
maltrix::maltrix(maltrix & k)
{
sh=k.sh;
sc=k.sc;
for (int i=0;i<sh;i++)
for(int j=0;j<sc;j++)
arr[i][j]=k.arr[i][j];
}

/*maltrix maltrix::operator -(maltrix& k)
{
if(sh!=k.sh||sc!=k.sc)
{
cout<<"khong cong duoc";
delay(2000);
exit(1);
}
maltrix tam2(sh,sc);
for (int i=0;i<sh;i++)
for(int j=0;j<sc;j++)
tam2.arr[i][j]=arr[i][j]-k.arr[i][j];
return tam2;

} */





void main()
{
clrscr();
int s1,s2;
cout<<"so hang mt 1: ";cin>>s1;
cout<<endl<<"so cot mt 2: ";cin>>s2;
maltrix m1(s1,s2);
m1.nhap();
cout<<endl;
cout<<endl<<"so hang mt 2: ";cin>>s1;
cout<<endl<<"so cot mt 2: ";cin>>s2;
maltrix m2(s1,s2);
m2.nhap();
maltrix tam;
tam=m1+m2;
tam.xuat();
//(m1-m2).xuat();
getch();
}