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), which initializes all elements in the matrix to 0's.
  2. 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.
  3. A destructor.
  4. A print function which prints each row of elements in a single line, with each element preceded by 4 spaces.
  5. 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.
  6. 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<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;

class Matrix{
private:
	int rows;
	int columns;
	double * values[1000];
public:
    Matrix(int r,int col)
    {
        rows=r;
		columns=col;
    }
	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++)
				cout<<"    "<<*values[j+i*columns];
			cout<<endl;
		}
	}
    void set(int rr,int cc,double vv)
    {
		rr--;
		cc--;
        values[cc+rr*columns]=&vv;
    }
};

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