#include <iostream> using namespace std; //请在begin和end间完成Matrix类的编写,重载>>及<<运算符,建议重载为友元函数 /*********begin**********/ class Matrix { private: int mat[2][3]; public: friend istream& operator>>(istream& in, Matrix& m); friend ostream& operator<<(ostream& out, const Matrix& m); }; istream& operator>>(istream& in, Matrix& m) { 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, const 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; } /*********end*********/ int main() { Matrix m1; cin>>m1; cout<<"output matrix"<<endl; cout<<m1; }补全代码
时间: 2023-08-06 19:08:24 浏览: 115
完整的代码如下:
```
#include <iostream>
using namespace std;
//请在begin和end间完成Matrix类的编写,重载>>及<<运算符,建议重载为友元函数
/*********begin**********/
class Matrix {
private:
int mat[2][3];
public:
friend istream& operator>>(istream& in, Matrix& m);
friend ostream& operator<<(ostream& out, const Matrix& m);
};
istream& operator>>(istream& in, Matrix& m) {
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, const 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;
}
/*********end*********/
int main() {
Matrix m1;
cin >> m1;
cout << "output matrix" << endl;
cout << m1;
}
```
阅读全文
相关推荐
















