-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.cpp
70 lines (64 loc) · 1.55 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
/* -------------------------------------------------------------------
Matrix.cpp
Clase que modela una matriz de 4x4, y permite definir operaciones como
la multiplicacion de matrices a través de sobrecarga de operadores.
Marco Fuentes - 18188
Gráficas por computadora - Segundo Semestre 2020 - UVG
------------------------------------------------------------------- */
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include "Matrix.hpp"
using namespace std;
Matrix::Matrix(){
//Inicializar todo con 0
for (int i = 0 ; i < 4 ; i++){
for (int j = 0 ; j < 4 ; j++){
this->matriz[i][j] = 0.0;
}
}
}
Matrix::Matrix(double **matriz){
for (int i = 0 ; i < 4 ; i++){
for (int j = 0 ; j < 4 ; j++){
this->matriz[i][j] = matriz[i][j];
}
}
}
Matrix::Matrix(double matriz[4][4]){
for (int i = 0 ; i < 4 ; i++){
for (int j = 0 ; j < 4 ; j++){
this->matriz[i][j] = matriz[i][j];
}
}
}
double Matrix::getItem(int i , int j){
return this->matriz[i][j];
}
void Matrix::setValue(int i, int j , double value){
if (i<4 && j <4){
this->matriz[i][j] = value;
}else{
cout << "Indices invalidos" << endl;
}
}
void Matrix::toString(){
for (int i = 0; i < 4 ; i++){
for (int j = 0 ; j < 4 ; j ++){
cout << getItem(i,j) << "\t";
}
cout << endl;
}
}
double** Matrix::getMatrix(){
double **mat = new double*[4];
for (int i = 0 ; i < 4 ; i++){
mat[i] = new double[4];
for (int j = 0 ; j <4 ; j++){
mat[i][j] = matriz[i][j];
}
}
return mat;
}