-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatrix.h
More file actions
178 lines (114 loc) · 2.45 KB
/
Copy pathMatrix.h
File metadata and controls
178 lines (114 loc) · 2.45 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <iostream>
#include "Array.h"
using namespace std;
template <class T>
class Matrix{
Array<Array<T>> M;
size_t rows;
size_t cols;
public:
//Builder
Matrix();
Matrix(const size_t, const size_t);
Matrix(const Matrix<T> &);
~Matrix();
//Status
size_t getRows() const;
size_t getCols() const;
bool isEmpty() const;
//Modifiers
void empty();
void reSize(size_t, size_t);
//Operators
bool operator==(const Matrix<T> &);
Array<T> & operator[](size_t);
//IO
template <class U>
friend ostream & operator<< (ostream &, Matrix<U> &);
template <class U>
friend istream & operator>> (istream &, Matrix<U> &);
};
//Builder
template <class T>
Matrix<T>::Matrix(){
rows = 0;
cols = 0;
}
template <class T>
Matrix<T>::Matrix(const size_t nRows, const size_t nCols){
(*this).reSize(nRows, nCols);
}
template <class T>
Matrix<T>::Matrix(const Matrix<T> & right){
rows = right.rows;
cols = right.cols;
for(size_t i = 0; i < rows; i++)
M[i] = right.M[i];
}
template<class T>
Matrix<T>::~Matrix(){
}
//Status
template<class T>
size_t Matrix<T>::getRows()const{
return rows;
}
template<class T>
size_t Matrix<T>::getCols()const{
return cols;
}
template<class T>
bool Matrix<T>::isEmpty()const{
if(!rows && !cols)
return true;
return false;
}
template<class T>
void Matrix<T>::empty(){
for(size_t i = 0; i < rows; i++)
M[i].empty();
rows = 0;
cols = 0;
}
//Operators
template<class T>
bool Matrix<T>::operator==(const Matrix<T> & right){
if(this == &right)
return true;
if(rows == right.rows && cols == right.cols)
for(size_t i = 0; i < rows; i++)
if(M[i] != right.M[i])
return false;
return true;
}
template<class T>
Array<T> & Matrix<T>::operator[](size_t index){
return M[index];
}
template <class T>
ostream & operator<< (ostream & os, Matrix<T> & data){
if(data.isEmpty())
os << "Empty Matrix";
for(size_t i = 0; i < data.rows; i++)
i == data.rows - 1 ? os << '|' << (data.M)[i] << '|' : os << '|' << (data.M)[i] << '|' << endl;
return os;
}
template <class T>
istream & operator>> (istream & is, Matrix<T> & data){
for(size_t i = 0; i < data.rows; i++)
is >> data[i];
return is;
//REVISAR LA CANTIDAD DE COLUMNAS, MODIFICAR OPERATOR>> DE ARRAY
}
template<class T>
void Matrix<T>::reSize(size_t nRows, size_t nCols){
M.reSize(nRows);
for(size_t i = 0; i < nRows; i++){
M[i].reSize(nCols);
}
rows = nRows;
cols = nCols;
}
#endif