您的位置:首页 > 其它

第七单元 7.10

2015-06-30 14:11 211 查看
#include<iostream.h>
class base
{

public:
base(int a,int b,int c,int d);
base(){}
friend base operator+(base &x,base &y);
friend base operator-(base &x,base &y);
void input();
void show();

private:
int a[2][2];

};
void base::show()
{  for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
cout<<a[i][j]<<endl;
}
base::base(int i,int b,int c,int d)
{
int* p=a[0];
*p=i;    p++;
*p=b;    p++;
*p=c;    p++;
*p=d;
}

void base::input()
{
cin>>a[0][0]>>a[0][1]>>a[1][0]>>a[1][1];
cout<<endl;
}

base operator+(base &x,base &y)
{
base co;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
co.a[i][j]=y.a[i][j]+x.a[i][j];
return co;
}

base operator-(base &x,base &y)
{
base co;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
co.a[i][j]=x.a[i][j]-y.a[i][j];
return co;
}

int main()
{
base i(15,6,13,21),j,z;
cout<<"please input 4  number:"<<endl;
j.input();
z=i+j;
cout<<"i+j="<<endl;
z.show();
z=i-j;
cout<<"i-j="<<endl;
z.show();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: