-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.cpp
60 lines (46 loc) · 1013 Bytes
/
matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef MATRIX_H
#define MATRIX_H
#include <bits/stdc++.h>
#include "matrix.h"
using namespace std;
Matrix::Matrix(int row, int col){
this->set_col(col);
this->set_row(row);
this->m = (double**) malloc (this->get_row() * sizeof(double*));
for (int i = 0; i < this->get_row(); i++) {
this->m[i] = (double*) malloc (this->get_col() * sizeof(double));
}
}
Matrix::~Matrix(){
for (int i = 0; i < this->get_row(); i++) {
free(this->m[i]);
}
free(this->m);
}
void Matrix::set_value(int i, int j,double value){
this->m[i][j] = value;
}
double Matrix::get_value(int i, int j){
return this->m[i][j];
}
int Matrix::get_col(){
return this->col;
}
int Matrix::get_row(){
return this->row;
}
void Matrix::set_col(int col){
this->col = col;
}
void Matrix::set_row(int row){
this->row = row;
}
void Matrix::print_matrix(){
for (int i = 0; i < this->row; i++) {
for (int j = 0; j < this->col; j++) {
cout << this->m[i][j] << " ";
}
cout << endl;
}
}
#endif