#include "Matrix.h"
Matrix::Matrix() : rows(5), cols(5), count(0), matrix(rows) {
srand(time(NULL));
for (std::vector<int>& col : matrix)
{
col = std::vector<int>(cols);
}
for (std::size_t i = 0; i < rows; i++) {
for (std::size_t j = 0; j < cols; j++) {
matrix[i][j] = rand() % 10;
}
}
}
void Matrix::printMatrix() const {
for (std::size_t i = 0; i < rows; i++) {
for (std::size_t j = 0; j < cols; j++) {
std::cout << matrix[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
void Matrix::findNumberInRow(const std::vector<std::int32_t> &row, const std::int32_t number) {
std::cout << "Thread ID = " << std::this_thread::get_id() << " for" << std::endl;
for (std::size_t i = 0; i < rows; i++) {
std::cout << row[i] << " ";
if (row[i] > number) {
count++;
}
}
std::cout << std::endl;
}
std::int32_t Matrix::findMoreThanNumber(std::int32_t number) {
std::vector<std::thread> threads;
for (std::size_t i = 0; i < cols; i++) {
std::thread thread(findNumberInRow, matrix[i], number);
threads.push_back(std::move(thread));
}
for (std::thread& thread : threads) {
thread.join();
}
return count;
}