File tree Expand file tree Collapse file tree 3 files changed +44
-3
lines changed
Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -168,4 +168,11 @@ int main() {
168168 cout << " =\n " << endl;
169169 mult1 *= mult2;
170170 mult1.print ();
171+
172+ Matrix mult3 (6 , 6 );
173+ mult3.print ();
174+ cout << " * 6 =\n " << endl;
175+
176+ mult3 *= 6 ;
177+ mult3.print ();
171178}
Original file line number Diff line number Diff line change @@ -186,4 +186,32 @@ Matrix& Matrix::operator*=(const Matrix& right) {
186186Matrix operator *(Matrix a, const Matrix& b) {
187187 a *= b;
188188 return a;
189+ }
190+
191+ Matrix& Matrix::operator *=(const double & n) {
192+ for (int x = 0 ; x < arr.size (); x++) {
193+ for (int y = 0 ; y < arr.size (); y++) {
194+ arr[y][x] *= n;
195+ }
196+ }
197+ return *this ;
198+ }
199+
200+ Matrix operator *(Matrix a, const double &b) {
201+ a *= b;
202+ return a;
203+ }
204+
205+ Matrix& Matrix::operator /=(const double & n) {
206+ for (int x = 0 ; x < arr.size (); x++) {
207+ for (int y = 0 ; y < arr.size (); y++) {
208+ arr[y][x] /= n;
209+ }
210+ }
211+ return *this ;
212+ }
213+
214+ Matrix operator /(Matrix a, const double &b) {
215+ a /= b;
216+ return a;
189217}
Original file line number Diff line number Diff line change @@ -32,11 +32,17 @@ class Matrix {
3232
3333 // операторы
3434
35- Matrix& operator +=(const Matrix& x);
36- Matrix& operator -=(const Matrix& x);
37- Matrix& operator *=(const Matrix& x);
35+ Matrix& operator +=(const Matrix& x); // сложение с матрицей
36+ Matrix& operator -=(const Matrix& x); // вычитание матрицы
37+ Matrix& operator *=(const Matrix& x); // умножение на матрицу
38+ Matrix& operator *=(const double & x); // умножение на скаляр
39+ Matrix& operator /=(const Matrix& x); // деление на матрицу
40+ Matrix& operator /=(const double & x); // деление на скаляр
3841
3942 friend Matrix operator +(Matrix a, const Matrix &b);
4043 friend Matrix operator -(Matrix a, const Matrix &b);
4144 friend Matrix operator *(Matrix a, const Matrix &b);
45+ friend Matrix operator *(Matrix a, const double &b);
46+ friend Matrix operator /(Matrix a, const Matrix &b);
47+ friend Matrix operator /(Matrix a, const double &b);
4248};
You can’t perform that action at this time.
0 commit comments