Design a class Matrix that has the following private member variables:

  1. int rows
  2. int columns
  3. double * values

Besides, it has the following public functions:

  1. 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.
  2. A copy constructor Matrix(const Matrix & matrix2).
  3. A destructor.
  4. 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<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;

class Matrix{
private:
	int rows;
	int columns;
	double * values[1000];
public:
	Matrix(int r,int col,double val[])
	{
        
		rows=r;
		columns=col;
        for(int i=0;i<rows*columns;i++)
		{
			values[i]=&val[i];
		}
	}
	void print()
	{
		for(int i=0;i<rows;i++)
		{
			for(int j=0;j<columns;j++)
			{
				if(*values[j+i*columns]<10)
					cout<<" ";
			    cout<<"   "<<*values[j+i*columns];
			}
			cout<<endl;
		}
	}
};

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();
}