Description

有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载运算符“+”,使之能用于矩阵相加(如c=a+b)。

重载流插入运算符“<<”和流提取运算符“>>”。使之能用于该矩阵的输入和输出。

Input

两个2行3列矩阵

Output

矩阵之和

Sample Input

1 2 3
4 5 6 7 8 9
1 2 3

Sample Output

8 10 12
5 7 9
/* All rights reserved.
* 文件名:test.cpp
* 作者:陈丹妮
* 完毕日期:2015年 6 月 21 日
* 版 本 号:v1.0
*/
#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
friend ostream& operator<<(ostream&,Matrix&);
friend istream& operator>>(istream&,Matrix&);
private:
int mat[2][3];
};
Matrix::Matrix()
{int i=0,j=0;
for(;i<2;i++)
for(;j<3;j++)
mat[i][j]=0;
} Matrix operator+(Matrix &m1,Matrix &m2)
{
Matrix m;
int i,j;
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
m.mat[i][j]=m1.mat[i][j]+m2.mat[i][j];
}
return m;
}
ostream& operator<<(ostream&out,Matrix&m)
{
int i,j;
for(i=0; i<2; i++)
{for(j=0; j<3; j++)
out<<m.mat[i][j]<<" ";
cout<<endl;}
return out;
}
istream& operator>>(istream&in,Matrix&m)
{
int i,j;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
in>>m.mat[i][j];
return in;
}
int main()
{
Matrix a,b,c;
cin>>a;
cin>>b;
c=a+b;
cout<<c<<endl;
return 0;
}

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbnVmYW5nZG9uZ2Rl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

学习心得:继续加油,重载非常好用的,得要总结一下了!

!!!


最新文章

  1. Meta标签中的viewport属性及含义
  2. jquery mobile 登陆后页面验证
  3. Oracle死锁处理
  4. 制作linux内核安装包
  5. [原创]自定义控件之AndroidSegmentControlView,仿IOS平台UISegmentControlView,继承自View
  6. ArcMap自定义脚本工具制作
  7. (转)9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
  8. CentOS7配置Nodejs环境安装记录
  9. 一分钟告诉你究竟DevOps是什么鬼?
  10. 在vue 里使用腾讯ditu
  11. 【LOJ#3095】[SNOI2019]字符串(后缀数组)
  12. c博客作业--分支、顺序结构
  13. Coprime Arrays CodeForces - 915G (数论水题)
  14. adb command
  15. sscanf 解析字符串
  16. HDU3693 Math Teacher&#39;s Homework ---- 数位DP
  17. Delphi XE开发 Android 开机自动启动
  18. Java Web应用开发工具
  19. 【BZOJ 2946】 2946: [Poi2000]公共串 (SAM)
  20. android.app.FragmentManager 与 android.support.v4.app.FragmentManager带来的若干Error

热门文章

  1. [转].net cookie版购物车
  2. 初识mybatis之入门案例
  3. Spring.Net学习笔记(3)-创建对象
  4. 【转】rpm包和源码包安装的区别
  5. MyElipse如何添加Emmet插件
  6. npm install的时候报错 npm err code 1
  7. js this 和 event 的区别
  8. Angular——内置过滤器
  9. Farseer.net轻量级开源框架 中级篇:事务的使用
  10. 牛客多校Round 2