-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMatrix.hpp
163 lines (138 loc) · 3.99 KB
/
Matrix.hpp
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
/*
* File : Matrix.hpp
* Authors : Robin Demarta, Loïc Dessaules
* Date : 21.02.2020
*/
#ifndef POO2_Labo01_MATRIX_H
#define POO2_Labo01_MATRIX_H
#include <ostream>
#include "Operator.hpp"
#include "Addition.hpp"
#include "Subtraction.hpp"
#include "Multiply.hpp"
class Matrix {
private:
int n;
int m;
int modulus;
int** content;
const static Addition addOp;
const static Subtraction subOp;
const static Multiply mulOp;
public:
/**
* Standard constructor of Matrix
* @param n number of rows
* @param m number of columns
* @param modulus
*/
Matrix(int n, int m, int modulus);
/**
* Copy constructor that allows to duplicate the Matrix object
* @param m
*/
Matrix(const Matrix& m);
/**
* Apply addition on new Matrix object
* @param other
* @return new Matrix object
*/
Matrix addCopy(const Matrix& other) const;
/**
* Apply subtraction on new Matrix object
* @param other
* @return new Matrix object
*/
Matrix subCopy(const Matrix& other) const;
/**
* Apply multiplication on new Matrix object
* @param other
* @return new Matrix object
*/
Matrix multiplyCopy(const Matrix& other) const;
/**
* Apply addition on dynamically allocated Matrix
* @param other
* @return pointer to the new Matrix
*/
Matrix* addDynamic(const Matrix& other) const;
/**
* Apply subtraction on dynamically allocated Matrix
* @param other
* @return pointer to the new Matrix
*/
Matrix* subDynamic(const Matrix& other) const;
/**
* Apply multiplication on dynamically allocated Matrix
* @param other
* @return pointer to the new Matrix
*/
Matrix* multiplyDynamic(const Matrix& other) const;
/**
* Apply addition on current Matrix
* @param other
* @return a reference to the current and modified Matrix
*/
Matrix& addModify(const Matrix& other);
/**
* Apply subtraction on current Matrix
* @param other
* @return a reference to the current and modified Matrix
*/
Matrix& subModify(const Matrix& other);
/**
* Apply multiplication on current Matrix
* @param other
* @return a reference to the current and modified Matrix
*/
Matrix& multiplyModify(const Matrix& other);
/**
* Copy operator
* @param matrix
* @return
*/
Matrix& operator=(const Matrix& matrix);
/**
* Allows to display Matrix using ostream <<
* @param os
* @param m
* @return
*/
friend std::ostream& operator<<(std::ostream& os, const Matrix& m);
~Matrix();
private:
/**
* Populate the Matrix with random values between 0 and modulus-1
*/
void randomPopulate();
/**
* Perform arithmetic operation on current matrix (Matrix object on which this function is called will be modified)
* @param other
* @param op
* @return
*/
Matrix& calc(const Matrix& other, const Operator& op);
/**
* Test a modulus. It cannot be 0 or minus because of the matrix values that must be between 0 and modulus-1
* @param modulus The modulus
* @throws RuntimeException if the modulus is 0 or minus
*/
void testModulus(int modulus) const;
/**
* Test the matrix dimensions. We cannot have void or negative dimensions
* @param n The row size of the Matrix
* @param m The column size of the Matrix
* @throws RuntimeException if a matrix dimension is 0 or negative
*/
void testMatrixDimensions(int n, int m) const;
/**
* Returns a cyclic value (going from 0 to modulus) instead of a negative one if left operand of % is negative.
* -1 % 5 will give 4 instead of -1.
* Formula source: https://stackoverflow.com/questions/11720656/modulo-operation-with-negative-numbers
* @param lhs
* @param rhs
* @return
*/
int trueModulus(int value, int mod) const;
};
#endif //POO2_Labo01_MATRIX_H