lesson_3 #3
|
@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Iterator(array + i * matrixSize);
|
||||
}
|
||||
|
||||
Matrix::Iterator Matrix::begin()
|
||||
{
|
||||
return Iterator(array);
|
||||
}
|
||||
|
||||
Matrix::Iterator Matrix::end()
|
||||
{
|
||||
return Iterator(array + matrixCapacity);
|
||||
}
|
||||
|
||||
/*
|
||||
* Расчет определителя
|
||||
*/
|
||||
|
|
|
@ -33,13 +33,18 @@ public:
|
|||
class Iterator
|
||||
{
|
||||
private:
|
||||
double *currentRow;
|
||||
double *current;
|
||||
public:
|
||||
Iterator(double *row);
|
||||
Iterator(double *pointer);
|
||||
double& operator[](size_t i);
|
||||
Iterator& operator ++();
|
||||
bool operator !=(const Iterator &iterator);
|
||||
double& operator *();
|
||||
};
|
||||
|
||||
Iterator operator[](size_t i);
|
||||
Iterator begin();
|
||||
Iterator end();
|
||||
|
||||
~Matrix();
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* exercise_3.hpp
|
||||
*
|
||||
* Created on: 30 сент. 2021 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void exercise_3();
|
|
@ -7,11 +7,13 @@
|
|||
|
||||
#include "exercise_1.hpp"
|
||||
#include "exercise_2.hpp"
|
||||
#include "exercise_3.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
// exercise_1();
|
||||
exercise_1();
|
||||
exercise_2();
|
||||
exercise_3();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue