Skip to content

Instantly share code, notes, and snippets.

@larsXYZ
Last active July 17, 2017 12:47
Show Gist options
  • Save larsXYZ/9466a23515fdcf7020542e10e50af066 to your computer and use it in GitHub Desktop.
Save larsXYZ/9466a23515fdcf7020542e10e50af066 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "matrix.h"
int main(){
matrixObject A(10,10, 0);
std::cout << A.matrix[5][5] << std::endl;
}
#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;
}
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