有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载<< >>
2011-03-20 18:52
1376 查看
有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载运算符“+”,使之能用于矩阵相加,如:c=a+b,重载流插入运算符<< 和流提取运算符>>,使之能用于矩阵的输入输出。
本文出自 “Chaos代码空间” 博客,请务必保留此出处http://flzt5354.blog.51cto.com/1568074/520770
#include<iostream> using namespace std; class Arrary { public: Arrary(); int a[2][3]; }; Arrary::Arrary() { int i,j; for(i=0;i<2;i++) for(j=0;j<3;j++) a[i][j]=0; } istream & operator >>(istream &input,Arrary &c1) { cout<<"请输入数组:"; int i,j; for(i=0;i<2;i++) for(j=0;j<3;j++) input>>c1.a[i][j]; return input; } ostream & operator <<(ostream &output,Arrary &c1) { int i,j; for(i=0;i<2;i++) { for(j=0;j<3;j++) output<<c1.a[i][j]<<" "; output<<endl; } return output; } Arrary operator +(Arrary c1,Arrary c2) { Arrary c3; int i,j; for(i=0;i<2;i++) for(j=0;j<3;j++) { c3.a[i][j]=c1.a[i][j]+c2.a[i][j]; } return c3; } int main() { Arrary a,b,c; cin>>a; cin>>b; c=a+b; cout<<c; }
本文出自 “Chaos代码空间” 博客,请务必保留此出处http://flzt5354.blog.51cto.com/1568074/520770
相关文章推荐
- 有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载运载符“+”,使之能用于矩阵相加。如:c=a+b。
- 有两个矩阵a和b 均为2行3列 求两个矩阵之和第四题
- Chapter10——有两个矩阵a和b,均为2行3列。求两个矩阵之和。重载运算符“+”,使之能用于矩阵相加
- 有两个矩阵a和b,均为2行3列。求两个矩阵之和
- 在java代码里写Map<String, ?>和Map<String, Object>都是可以用的,他们两个有什么区别?
- 利用CUDA的矩阵乘法1 <利用 Kahan's Summation Formula 来提高CUDA 的浮点数运算精确度>
- 在jsp中用<s:if test />比较两个变量
- Html 5:如何在两个 <div> 元素之间拖放图像
- 使用了两个<context:property-placeholder>出现后面的加载不到properties或者报错的问题
- Muli3D <3> qQuaternionRotationMatrix 函数 (矩阵转四元数)
- 两个List<Map<String, Object>>之间的数值交换
- <c:if test />来判定两个字符串是否相等
- [ --> C Language<-- ] 产生随机数矩阵并排序
- <script>中text/javascript和application/javascript两个不同属性的区别
- Linq连接两个List<T>列表 实例详解(Linq inner join,left join)
- sql语句判断两个时间段是否有交集 <非原创>
- 【SpringMVC】<context:include-filter>和<context:exclude-filter>使用时要注意的地方 在Spring MVC中的配置中一般会遇到这两个标签,作为<
- <c:if test />来判定两个字符串是否相等
- Unity手游之路<四>3d旋转-四元数,欧拉角和变幻矩阵
- [读书笔记]<游戏引擎架构>|仿射矩阵