-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.cpp
91 lines (50 loc) · 1.46 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by Kevin Aguilar on 5/6/20.
// used to control the matrix used to keep track of the similarity
// between documents in this program
//
#include "matrix.h"
Matrix::Matrix() {
int rows = 3; //creates a standard matrix
int cols = 3;
mat = new int* [rows]();
for(int i = 0; i<rows; i++){
mat[i] = new int [cols]();
}
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
mat[i][j] = 0;
}
}
}
Matrix::Matrix(int numOfFiles) {
int rows = numOfFiles;
int cols = numOfFiles;//same code as above but actually makes the matrix for the correct dimensions
mat = new int* [rows]();//creates the rows
for(int i = 0; i<rows; i++){
mat[i] = new int [cols]();//goes through each row and allocates enough memory for the columns
}
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
mat[i][j] = 0; //seting every value to 0
}
}
}
Matrix::~Matrix() {
for(int i = 0; i < row; i++){
delete [] mat[i];
}
delete [] mat;
}
void Matrix::incramentVal(int row, int col) {
if(col > row){
mat[row][col] += 1; //set the top half of the matrix to increment on a given coordinate
}
}
int Matrix::getval(int row, int col) {
int val;
if(col > row){
val = mat[row][col]; //retrieves the value at a certain location to see if it is above the threshold
}
return val;
}