第七单元 7.10

来源:互联网 发布:大数据产业链包括 编辑:程序博客网 时间:2024/04/30 15:13
#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;  } 

0 0
原创粉丝点击