exercises 1,2,3

This commit is contained in:
Alexander Zhirov 2021-09-30 20:08:09 +03:00
parent a6b44883a8
commit 9b54c0446d
5 changed files with 76 additions and 6 deletions

View File

@ -19,21 +19,48 @@ Matrix::Matrix(const int size) : matrixSize(size), matrixCapacity(size * size)
} }
/* /*
* Перегрузка операторов [][] * Перегрузка операторов итератора
*/ */
Matrix::Iterator::Iterator(double *row) : currentRow(row) Matrix::Iterator::Iterator(double *pointer) : current(pointer)
{ {
} }
double& Matrix::Iterator::operator[](size_t i) double& Matrix::Iterator::operator[](size_t i)
{ {
return *(currentRow + i); return *(current + i);
}
Matrix::Iterator& Matrix::Iterator::operator ++()
{
++current;
return *this;
}
bool Matrix::Iterator::operator !=(const Iterator &iterator)
{
return current != iterator.current;
}
double& Matrix::Iterator::operator *()
{
return *current;
} }
Matrix::Iterator Matrix::operator[](size_t i) Matrix::Iterator Matrix::operator[](size_t i)
{ {
return Iterator(array + i * matrixSize); return Iterator(array + i * matrixSize);
} }
Matrix::Iterator Matrix::begin()
{
return Iterator(array);
}
Matrix::Iterator Matrix::end()
{
return Iterator(array + matrixCapacity);
}
/* /*
* Расчет определителя * Расчет определителя
*/ */

View File

@ -33,13 +33,18 @@ public:
class Iterator class Iterator
{ {
private: private:
double *currentRow; double *current;
public: public:
Iterator(double *row); Iterator(double *pointer);
double& operator[](size_t i); double& operator[](size_t i);
Iterator& operator ++();
bool operator !=(const Iterator &iterator);
double& operator *();
}; };
Iterator operator[](size_t i); Iterator operator[](size_t i);
Iterator begin();
Iterator end();
~Matrix(); ~Matrix();
}; };

26
lesson_3/exercise_3.cpp Normal file
View File

@ -0,0 +1,26 @@
/*
* exercise_3.cpp
*
* Created on: 30 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <iomanip>
#include "exercise_3.hpp"
#include "exercise_2.hpp"
using namespace std;
void exercise_3()
{
Matrix m(4);
m.fillRandom();
for (const double &i : m)
{
cout << setw(5) << i;
}
cout << endl;
}

10
lesson_3/exercise_3.hpp Normal file
View File

@ -0,0 +1,10 @@
/*
* exercise_3.hpp
*
* Created on: 30 сент. 2021 г.
* Author: alexander
*/
#pragma once
void exercise_3();

View File

@ -7,11 +7,13 @@
#include "exercise_1.hpp" #include "exercise_1.hpp"
#include "exercise_2.hpp" #include "exercise_2.hpp"
#include "exercise_3.hpp"
int main() int main()
{ {
// exercise_1(); exercise_1();
exercise_2(); exercise_2();
exercise_3();
return 0; return 0;
} }