Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // class DoubleMatrix: Defining a simple Matrix class
- class DoubleMatrix {
- // Hidden
- private:
- double ** doubleMatrix;
- int dimensionWidth;
- int dimensionHeight;
- // Visible
- public:
- DoubleMatrix(int dimensionWidth, int dimensionHeight) {
- // Dimensions assignment
- this->dimensionWidth = dimensionWidth;
- this->dimensionHeight = dimensionHeight;
- // Matrix initialization
- this->doubleMatrix = new double*[dimensionWidth];
- // For each array contained in the first array
- for (int heightInitializer = 0; heightInitializer < dimensionWidth; heightInitializer++) {
- doubleMatrix[heightInitializer] = new double[dimensionHeight];
- }
- }
- // Function getMatrix: Returns the matrix as a pointer to pointer object
- double** getMatrix() {
- return this->doubleMatrix;
- }
- // Function getMatrix @overload(int, int): Returns a specified element for the intended matrix
- double getMatrix(int dimensionWidth, int dimensionHeight) {
- return this->doubleMatrix[dimensionWidth][dimensionHeight];
- }
- // Function setMatrix: Defines the matrix to be the specified matrix
- void setMatrix(double** matrix) {
- this->doubleMatrix = matrix;
- }
- // Function setMatrix @overload(int, int, double): Defines a particular element in the matrix to be the specified value
- void setMatrix(int dimensionWidth, int dimensionHeight, double value) {
- this->doubleMatrix[dimensionWidth][dimensionHeight] = value;
- }
- };
- int main()
- {
- using namespace std;
- DoubleMatrix* dm = new DoubleMatrix(3, 2);
- dm->setMatrix(0, 0, 1.618);
- cout << dm->getMatrix(0, 0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement