二维数组+-运算符重载

编写一个程序,用成员函数重载运算符“+”和“-”,将两个二维数组相加和相减,要求第一个二维数组的值由构造函数设置,另一个二维数组的值由键盘输入

#include 
using namespace std;
#define m  2
#define n  3
class complex{
	public:
		complex ();
		complex (int a[m][n]);
		complex operator+(int b[m][n]);
		complex operator-(int b[m][n]);
		void show();
	private :
		int p[m][n];
}; 

complex::complex ()
{
	for(int i=0;i>x[j][i];
		}
	aa=d+x;
	aa.show();
	cout<<"\n";
	aa=d-x;
	aa.show();
	return 0;
}

友元函数完成二维数组加减重载

#include 
using namespace std;
#define m  2
#define n  3
class complex{
	public:
		complex ();
		complex (int a[m][n]);
		friend complex operator+(complex a ,int b[m][n]);
		friend complex operator-(complex a,int b[m][n]);
		void show();
	private :
		int p[m][n];
}; 

complex::complex ()
{
	for(int i=0;i>x[j][i];
		}
	aa=d+x;
	aa.show();
	cout<<"\n";
	aa=d-x;
	aa.show();
	return 0;
}

你可能感兴趣的:(作业)