2.4 (C++)

Design a class Matrix that has the following private member variables:
int rows
int columns
double * values
Besides, it has the following public functions:
A constructor Matrix(int rows, int column), which initializes all elements in the matrix to 0's.
A constructor Matrix(int rows, int column, double values[]), which initializes all elements in the matrix to the given values. Note that the given values are in one-dimension, you need to fill them into the two-dimensional matrix correctly.
A destructor.
A print function which prints each row of elements in a single line, with each element preceded by 4 spaces.
A function set(int row, int column, double value) that sets a value of an element in the matrix. Note that indexes in Matrix starts from 1 instead of 0.
The operator =.
EXAMPLE INPUT
4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2 3
1.5
EXAMPLE OUTPUT

1    2    3    4    5
6    7    1.5    9    10
11    12    13    14    15
16    17    18    19    20

主程序 (不能修改)

#include "source.cpp"

int main() {
    int rows;
    int columns;
    double values[1000];
    cin >> rows >> columns;
    for (int i = 0; i < rows * columns; ++ i) {
        cin >> values[i];
    }
    Matrix matrix1(rows, columns, values);

    int row;
    int column;
    double value;
    cin >> row >> column >> value;
    Matrix matrix2(0, 0);
    matrix2 = matrix1;
    matrix2.set(row, column, value);
    matrix2.print();
    
}

我的答案

Mitee的答案
3-9构造函数/4

上一篇: 2.5 (C++) 下一篇: 2.3 (C++)
支持 makedown语法