频道栏目
首页 > 资讯 > 其他 > 正文

M: 类重载实现矩阵加法

17-05-20        来源:[db:作者]  
收藏   我要投稿

题目描述 编写矩阵类Matrix,实现两个2x3矩阵相加。主函数已给定。 输入 两个矩阵的元素值 输出 两个矩阵相加的结果 样例输入 1 2 3 4 5 6 1 2 3 4 5 6 样例输出 2 4 6 8 10 12

#include 
using namespace std;
class Matrix
{
public:
	Matrix();
	void input();
	void display();
	Matrix operator+(Matrix &);
private:
	double array[2][3];
};
Matrix::Matrix()
{
	int i,j;
	for(i=0;i<2;i++)
		for(j=0;j<3;j++)
			array[i][j]=0;
}
void Matrix::input()
{
	int i,j;
	for(i=0;i<2;i++)
		for(j=0;j<3;j++)
			cin>>array[i][j];
}
Matrix Matrix:: operator+(Matrix &b)
{
	Matrix A;
	int i,j;
	for(i=0;i<2;i++)
		for(j=0;j<3;j++)
			A.array[i][j]=array[i][j]+b.array[i][j];
		return A;
}
void Matrix::display()
{
	int i,j;
	for(i=0;i<2;i++)
		for(j=0;j<2;j++)
		{
			cout<
相关TAG标签
上一篇:jQuery选择器之id选择器
下一篇:maven java.lang.NoClassDefFoundError: org/codehaus/plexus/util/cli/CommandLineException
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站