From 07d8a83ebe31aa10a2e2e15de765b90f5a949604 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Tue, 3 Dec 2024 15:22:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B1=D0=BE=D1=80=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab1/CellularAutomaton.cpp | 6 +++--- lab1/CellularAutomaton.h | 2 +- lab1/lab1.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lab1/CellularAutomaton.cpp b/lab1/CellularAutomaton.cpp index 6cee99b..006063a 100644 --- a/lab1/CellularAutomaton.cpp +++ b/lab1/CellularAutomaton.cpp @@ -1,12 +1,12 @@ #include "CellularAutomaton.h" -CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width), m_fieldHeight(height) +CellularAutomaton::CellularAutomaton(int width, int height, bool fillWithRandom) : m_fieldWidth(width), m_fieldHeight(height) { field.resize(m_fieldHeight, std::vector(m_fieldWidth, 0)); fieldNextState.resize(m_fieldHeight, std::vector(m_fieldWidth, 0)); - //initializeRandom(); - initializeManual(); + if (fillWithRandom) initializeRandom(); + else initializeManual(); } diff --git a/lab1/CellularAutomaton.h b/lab1/CellularAutomaton.h index 1e8726e..5abd91c 100644 --- a/lab1/CellularAutomaton.h +++ b/lab1/CellularAutomaton.h @@ -19,7 +19,7 @@ class CellularAutomaton int getCellState(int x, int y) const; int getNeighborhoodIndex(int x, int y) const; public: - CellularAutomaton(int width, int height); + CellularAutomaton(int width, int height, bool fillWithRandom); void update(); void displayField() const; diff --git a/lab1/lab1.cpp b/lab1/lab1.cpp index 2f0b986..705fa7b 100644 --- a/lab1/lab1.cpp +++ b/lab1/lab1.cpp @@ -40,9 +40,11 @@ int main() cout << "Укажите количество итераций (min 1): "; int iterationsCount = inputNumber(1); - clear(); + cout << "Заполнить поле случайными значениями? (yes/no)\n"; + bool fillWithRandom = userApprove(); - CellularAutomaton ca(fieldWidth, fieldHeight); + CellularAutomaton ca(fieldWidth, fieldHeight, fillWithRandom); + clear(); std::cout << "\nИтерация 0:\n"; ca.displayField();