C++实验题---填空(运算符重载A)#include <iostream.h>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 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];}_____________ { 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;}输入输入只有一组测试数据。输出根据程序代码输出相应的信息。样例输入1 2 34 5 62 3 45 6 7样例输出input value of matrix:input value of matrix:Matrix a:1 2 3 4 5 6 Matrix b:2 3 4 5 6 7 Matrix c = Matrix a + Matrix b :3 5 79 11 13
1 回答
- 1 回答
- 0 关注
- 1149 浏览
添加回答
举报
0/150
提交
取消