#include <iostream>
using namespace std;

class M {
private:
    int data[2][3];

public:
    // 重载输入运算符 >>
    friend istream& operator>>(istream& in, M& m) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                in >> m.data[i][j];
            }
        }
        return in;
    }

    // 重载输出运算符 <<
    friend ostream& operator<<(ostream& out, const M& m) {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                out << m.data[i][j];
                if (j != 2) out << " ";
            }
            if (i != 1) out << endl;
        }
        return out;
    }

    // 重载加法运算符 +
    M operator+(const M& other) const {
        M result;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                result.data[i][j] = this->data[i][j] + other.data[i][j];
            }
        }
        return result;
    }
};

int main() {
    M a, b, c;
    cin >> a;
    cin >> b;
    c = a + b;
    cout << c << endl;
    return 0;
}

标签: none

已有 2 条评论

  1. eee

    #include
    using namespace std;
    class height{
    double h;
    public:
    height(double x){
    h=x;
    }
    double getheight(){
    return h;
    }
    };
    class banjin{
    double r;
    public:
    banjin(double y){
    r=y;
    }
    double getbanjin(){
    return r;
    }
    };
    class ti : public height,public banjin{
    public:
    void tiji(){
    cout

  2. eee

    #include
    using namespace std;
    class height{
    double h;
    public:
    height(double x){
    h=x;
    }
    double getheight(){
    return h;
    }
    };
    class bian1{
    double a;
    public:
    bian1(double y){
    a=y;
    }
    double getbian1(){
    return a;
    }
    };
    class bian2{
    double b;
    public:
    bian2(double z){
    b=z;
    }
    double getbian2(){
    return b;
    }
    };
    class ti : public height,public bian1,public bian2{
    public:
    void tiji(){
    cout

添加新评论