Last active
July 17, 2017 12:47
-
-
Save larsXYZ/9466a23515fdcf7020542e10e50af066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "matrix.h" | |
int main(){ | |
matrixObject A(10,10, 0); | |
std::cout << A.matrix[5][5] << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "matrix.h" | |
#include <iostream> | |
matrixObject::matrixObject(int h1, int w1){ | |
//Sets size | |
height = h1; | |
width = w1; | |
//Creates number matrix | |
double** matrix = new double*[width]; | |
for (int i = 0; i < width; i++) matrix[i] = new double[height]; | |
} | |
matrixObject::matrixObject(int h1, int w1, double k){ | |
//Sets size | |
height = h1; | |
width = w1; | |
//Creates number matrix | |
double** matrix = new double*[width]; | |
for (int i = 0; i < width; i++) matrix[i] = new double[height]; | |
//Initializes numbers | |
for(int i = 0; i < width; i++){ | |
for (int q = 0; q < height; q++){ | |
matrix[i][q] = k; | |
} | |
} | |
} | |
matrixObject::~matrixObject(){ | |
for (int i = 0; i < width; i++) delete[] matrix[i]; | |
delete[] matrix; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct matrixObject{ | |
//Data | |
int height; | |
int width; | |
double** matrix; | |
//Constructors | |
matrixObject(int h1, int w1); | |
matrixObject(int h1, int w1, double k); | |
//Destructor | |
~matrixObject(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment