-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.h
56 lines (53 loc) · 1.04 KB
/
matrix.h
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
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
class matrix {
private:
int i, j;
vector<vector<int>> mat;
vector<int> maindiagonal;
public:
matrix(vector<vector<int>>& mat1) {
i = mat1.size();
j = mat1[0].size();
mat.resize(i, vector<int>(j));
data.resize(i, vector<int>(j));
mat = data;
dim1 = i;
dim2 = j;
}
vector <vector<int>> data;
int dim1, dim2;
bool is_square() {
retrun (i==j);
}
int main_diagonal_sum() {
int sum = 0;
if (is_square()) {
int col = 0;
for (int row = 0; row < i; row++) {
sum += mat[row][col];
col++;
}
return sum;
}
//the function must return a value
}
};
bool is_equal(matrix m1, matrix m2) {
//first test
bool checker = 1;
if (m1.dim1 == m2.dim2 && m1.dim2 == m2.dim2) {
// second teste
for (int i = 0; i < m1.dim1; i++) {
for (int j = 0; j < m1.dim2; j++) {
if (m1.data[i][j] != m2.data[i][j]) {
return false;
}
}
}
}
return checker;
}