第四章第五题
来源:互联网 发布:淘宝高仿nike鞋店推荐 编辑:程序博客网 时间:2024/04/30 13:26
#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()
{for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
mat[i][j]=0;
}
Matrix operator+(Matrix &a,Matrix &b)
{Matrix c;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
{c.mat[i][j]=a.mat[i][j]+b.mat[i][j];
}
return c;
}
istream& operator>>(istream &in,Matrix &m)
{cout<<"input value of matrix:"<<endl;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
in>>m.mat[i][j];
return in;
}
ostream& operator<<(ostream &out,Matrix &m)
{for (int i=0;i<2;i++)
{for(int j=0;j<3;j++)
{out<<m.mat[i][j]<<" ";}
out<<endl;}
return out;
}
int main()
{ Matrix a,b,c;
cin>>a;
cin>>b;
cout<<endl<<"Matrix a:"<<endl<<a<<endl;
cout<<endl<<"Matrix b:"<<endl<<b<<endl;
c=a+b;
cout<<endl<<"Matrix c = Matrix a + Matrix b :"<<endl<<c<<endl;
return 0;
}
- 第四章第五题
- 第四章第五题
- 学习OpenCV第四章第五题答案
- 《学习opencv》第四章第五题
- 第五周作业(第四章)
- 计算机网络第三第四第五章
- 《学习OpenCV》练习题第四章第五题a
- 改为公用继承方式 第五章第四题
- 陈国君java第五版第四章课后习题第五题
- 《C++primer》第五版 第四章 第五章 笔记
- Thinking in Java 第四章、第五章
- 数据库第四章第五章总结
- 第四章第五章学习总结
- [第五章] 第四节、throw和throws
- 谢希仁《计算机网络》第五版---第四章
- C++ Primer 【第四版】第五章 表达式
- 思科CCNA第四学期第五章答案
- 第五章第四节-bean的关系
- ATM自动取款机系统的功能需求分析
- 陈华:我是如何走上互联网这条路的
- 安装第三方库rsa遇到的问题
- 陈华:新手程序员快速成长之道
- 陈华:淘宝同学左侧导航栏div鼠标上浮边框变色无遮挡处理方法
- 第四章第五题
- mysql和hibernate的基本操作
- 关于Python中的“ if__name__ == ‘__main__”
- c语言中关于/的一个细节
- 校赛 (离散化 + 并查集)
- float 网络字节序转主机字节序
- MAC安装JDeveloper
- No Data, There was no data available. Possible reasons include inaccessible Ganglia service
- 第四章第六题