2.3 (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, 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 copy constructor Matrix(const Matrix & matrix2).
A destructor.
A print function which prints each row of elements in a single line, with each element preceded with 4 spaces.
EXAMPLE INPUT
4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
EXAMPLE OUTPUT

1    2    3    4    5
6    7    8    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);
    Matrix matrix2(matrix1);
    matrix2.print();
}

我的答案

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

上一篇: 2.4 (C++) 下一篇: 2.2 (C++)
支持 makedown语法