2.2 (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-dimensional, you need to fill then into the two-dimensional matrix correctly.
A destructor.
A print function which prints each row of elements in a single line, with each element using 5 character 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);
    matrix1.print();
}

我的答案

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

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