zoukankan      html  css  js  c++  java
  • 运算符重载两数组相加

    #include<iostream.h>
    class arry
    {
    	int a[4][4];
    public:
    	arry()
    	{
             for(int i=0;i<4;i++)
    			for(int j=0;j<4;j++)
    				a[i][j]=0;
    	}
    	void intput()
    	{
    		int f[4][4];
    		for(int i=0;i<4;i++)
    		{
    			for(int j=0;j<4;j++)
    			{
    				cin>>f[i][j];
    				a[i][j]=f[i][j];
    			}                                                       		}
    
    	}	
    	void print()
    	{
            for(int i=0;i<4;i++)
    		{
    			for(int j=0;j<4;j++)
    			{
    				cout<<a[i][j]<<"            ";
    			}
    			cout<<'
    ';
    		}
    	}
    	friend arry operator+(arry c,arry d)
        {
    		arry e;
    		for(int i=0;i<4;i++)
    		{
    			for(int j=0;j<4;j++)
    			{
    				e.a[i][j]=c.a[i][j]+d.a[i][j];
    			}
    		}
    			return e;
    	}
    };
    void main()
    {
    	arry n,m,j;
    	cout<<"请输入第一个4*4数组"<<endl;
    	n.intput();
    	cout<<"************************************"<<endl;
        cout<<"请输入第二个4*4数组"<<endl;
        m.intput();
    	cout<<"这两个数组为"<<endl;
    	n.print();
    	cout<<"***********************************"<<endl;
    	m.print();
    	j=n+m;
    	cout<<"两数组相加后为"<<endl;
    	j.print();
    	
    }
    

  • 相关阅读:
    layer弹出层显示在top顶层
    PC上安装多个操作系统
    Windows下DLL查找顺序
    AHCI驱动安装
    Office 多版本共存
    Windows定时器
    Windows菜单
    Windows高精度时间
    VB6.0调用DLL
    时间服务器通讯协议
  • 原文地址:https://www.cnblogs.com/zztong/p/6695323.html
Copyright © 2011-2022 走看看