4.cpp
来源:互联网 发布:淘宝店铺的公告怎么写 编辑:程序博客网 时间:2024/05/14 17:34
#include <iostream> using namespace std; class Matrix { public: Matrix(); friend Matrix operator+(Matrix &,Matrix &); void input(); void display(); 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; } void Matrix::input() { cout<<"input value of matrix:"<<endl; for(int i=0;i<2;i++) for(int j=0;j<3;j++) cin>>mat[i][j];} void Matrix::display() {for (int i=0;i<2;i++) {for(int j=0;j<3;j++) {cout<<mat[i][j]<<" ";} cout<<endl;} } int main() {Matrix a,b,c; a.input(); b.input(); cout<<endl<<"Matrix a:"<<endl; a.display(); cout<<endl<<"Matrix b:"<<endl; b.display(); c=a+b; cout<<endl<<"Matrix c = Matrix a + Matrix b :"<<endl; c.display(); return 0;}
0 0
- 4.cpp
- 4.cpp
- example11.4.cpp
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- 第七周4.main.cpp:测试函数
- 装箱问题POJ1017 program2.4.cpp
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- algo1-4.cpp 说明exit()函数作用的程序
- Leetcode 4. Median of Two Sorted Arrays (Hard) (cpp)
- 排序算法
- 广州日报 中国模式再次让西方傻眼
- 广州日报 中国模式再次让西方傻眼
- 广州日报 中国模式再次让西方傻眼
- <转>广州日报 中国模式再次…
- 4.cpp
- 人民网 汉语即将“无家可归” 倡导经…
- Android No active compatible AVD's or devices found Exception
- 人民网 汉语即将“无家可归” 倡导经…
- 人民网 汉语即将“无家可归” 倡导经…
- <转>人民网 汉语即将“无家可…
- 联合早报 科学发展观下的超级…
- 联合早报 科学发展观下的超级大国…
- <转> 联合早报 科学发展…