-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.cpp
47 lines (39 loc) · 848 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
#include"matrix.hpp"
Matrix::Matrix(std::vector<std::vector<double>> m){
this->m_matrix= m;
}
std::vector<std::vector<double>> Matrix::getMatrix(){
return this->m_matrix;
}
void Matrix::add_to_matrix(std::vector<double> m){
this->m_matrix.push_back(m);
}
std::ostream& operator<<(std::ostream& out, Matrix m){
out << "Matrix:" << std::endl;
std::vector<std::vector<double>> p = m.getMatrix();
unsigned n, k, i, j;
n = p.size();
k = p[0].size();
out << '[';
for (i = 0; i<n-1; ++i){
// if is for aligning every column
if (i==0){
out << '[';
}else{
out << " [";
}
for (j = 0; j<k-1; ++j){
out << p[i][j] << ", ";
}
out << p[i][j] << ']';
out << std::endl;
if (i == n-2) out << ' ';
}
out << '[';
for (j = 0; j<k-1; ++j){
out << p[i][j] << ", ";
}
out << p[i][j] << ']';
out << ']';
return out;
}