From 88b0d517402507a55e344f3f74e6119d67b53a62 Mon Sep 17 00:00:00 2001
From: gleb7499 <164905074+gleb7499@users.noreply.github.com>
Date: Tue, 17 Sep 2024 18:14:52 +0300
Subject: [PATCH 1/6] added src without doc
---
tasks/task_01/.gitignore | 2 +
tasks/task_01/CMakeLists.txt | 11 +++
tasks/task_01/src/main.cpp | 78 +++++++++++++++++++
tasks/task_01/src/models.cpp | 37 +++++++++
tasks/task_01/src/models.h | 41 ++++++++++
...1\203\320\274\320\265\320\275\321\202.txt" | 0
trunck/as0006315/task_01/src/CMakeLists.txt | 11 +++
trunck/as0006315/task_01/src/main.cpp | 78 +++++++++++++++++++
trunck/as0006315/task_01/src/models.cpp | 37 +++++++++
trunck/as0006315/task_01/src/models.h | 41 ++++++++++
10 files changed, 336 insertions(+)
create mode 100644 tasks/task_01/.gitignore
create mode 100644 tasks/task_01/CMakeLists.txt
create mode 100644 tasks/task_01/src/main.cpp
create mode 100644 tasks/task_01/src/models.cpp
create mode 100644 tasks/task_01/src/models.h
create mode 100644 "trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt"
create mode 100644 trunck/as0006315/task_01/src/CMakeLists.txt
create mode 100644 trunck/as0006315/task_01/src/main.cpp
create mode 100644 trunck/as0006315/task_01/src/models.cpp
create mode 100644 trunck/as0006315/task_01/src/models.h
diff --git a/tasks/task_01/.gitignore b/tasks/task_01/.gitignore
new file mode 100644
index 00000000..5acb669b
--- /dev/null
+++ b/tasks/task_01/.gitignore
@@ -0,0 +1,2 @@
+build
+.vscode
diff --git a/tasks/task_01/CMakeLists.txt b/tasks/task_01/CMakeLists.txt
new file mode 100644
index 00000000..92a3d66f
--- /dev/null
+++ b/tasks/task_01/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.10)
+project(MyProject)
+
+# Устанавливаем переменную SRC_DIR
+set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
+
+# Добавляем исходные файлы
+add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cpp ${SRC_DIR}/models.cpp)
+
+# Добавляем заголовочные файлы
+include_directories(${SRC_DIR})
\ No newline at end of file
diff --git a/tasks/task_01/src/main.cpp b/tasks/task_01/src/main.cpp
new file mode 100644
index 00000000..cf676c09
--- /dev/null
+++ b/tasks/task_01/src/main.cpp
@@ -0,0 +1,78 @@
+#include "models.h"
+#include
+#include
+
+using namespace std;
+
+void get_liner_model();
+void get_nonlinear_model();
+bool choice_input(int &choice);
+
+int main() {
+ void (*point[])() = { []() { exit(0); }, get_liner_model, get_nonlinear_model};
+ int choice;
+ while (true) {
+ cout << "\n\tInput choice (0 - exit, 1 - linear model, 2 - nonlinear model)\n";
+ if (!choice_input(choice)) {
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ continue;
+ }
+ point[choice]();
+ }
+
+ return 0;
+}
+
+template bool input_value(T &value, const string &name) {
+ while (true) {
+ cout << "Input " << name << ": ";
+ if (cin >> value) {
+ return true;
+ }
+ else {
+ cin.clear();
+ cin.ignore(numeric_limits::max(), '\n');
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ }
+ }
+}
+
+void get_liner_model() {
+ double A, B, current_temperature, warm;
+ int time;
+ input_value(A, "A");
+ input_value(B, "B");
+ input_value(current_temperature, "current_temperature");
+ input_value(warm, "warm");
+ input_value(time, "time");
+ LinearModel model(A, B, current_temperature, warm);
+ model.calculate_and_print(time);
+}
+
+void get_nonlinear_model() {
+ double A, B, C, D, current_temperature, warm;
+ int time;
+ input_value(A, "A");
+ input_value(B, "B");
+ input_value(C, "C");
+ input_value(D, "D");
+ input_value(current_temperature, "current_temperature");
+ input_value(warm, "warm");
+ input_value(time, "time");
+ NonLinearModel model(A, B, C, D, current_temperature, warm);
+ model.calculate_and_print(time);
+}
+
+bool choice_input(int &choice) {
+ while (true) {
+ if (input_value(choice, "choice")) {
+ if (choice >= 0 && choice <= 2) {
+ return true;
+ }
+ else {
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ }
+ }
+ }
+}
+
diff --git a/tasks/task_01/src/models.cpp b/tasks/task_01/src/models.cpp
new file mode 100644
index 00000000..16b3f41a
--- /dev/null
+++ b/tasks/task_01/src/models.cpp
@@ -0,0 +1,37 @@
+#include "models.h"
+
+LinearModel::LinearModel(double a, double b, double current_temperature, double warm)
+ : A(a), B(b), current_temperature(current_temperature), warm(warm) {}
+
+void LinearModel::calculate_and_print(const int& time) {
+ std::cout.setf(std::ios::left);
+ std::cout << std::setw(10) << "TIME";
+ std::cout << std::setw(30) << "LINEAR MODEL" << std::endl;
+ std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+ double temp = current_temperature;
+ for (int i = 1; i <= time; ++i) {
+ std::cout << std::setw(10) << i;
+ temp = A * temp + B * warm;
+ std::cout << std::setw(30) << temp << std::endl;
+ }
+}
+
+NonLinearModel::NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm)
+ : A(A), B(B), C(C), D(D), current_temperature(current_temperature), warm(warm) {}
+
+void NonLinearModel::calculate_and_print(const int& time) {
+ std::cout.setf(std::ios::left);
+ std::cout << std::setw(10) << "TIME";
+ std::cout << std::setw(30) << "NONLINEAR MODEL" << std::endl;
+ std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+ double curr_temp = current_temperature;
+ double previous_temperature = 0.0;
+ double buffer = 0.0;
+ for (int i = 1; i <= time; ++i) {
+ std::cout << std::setw(10) << i;
+ buffer = A * curr_temp - B * pow(previous_temperature, 2) + C * warm + D * sin(warm);
+ previous_temperature = curr_temp;
+ curr_temp = buffer;
+ std::cout << std::setw(30) << curr_temp << std::endl;
+ }
+}
diff --git a/tasks/task_01/src/models.h b/tasks/task_01/src/models.h
new file mode 100644
index 00000000..a77f0d7a
--- /dev/null
+++ b/tasks/task_01/src/models.h
@@ -0,0 +1,41 @@
+#ifndef MODELS_H
+#define MODELS_H
+
+#include
+#include
+#include
+#include
+
+class ModelingObject {
+public:
+ virtual void calculate_and_print(const int& time) = 0;
+};
+
+class LinearModel : public ModelingObject {
+private:
+ double A;
+ double B;
+ double current_temperature;
+ double warm;
+
+public:
+ LinearModel(double a, double b, double current_temperature, double warm);
+ void calculate_and_print(const int& time);
+};
+
+class NonLinearModel : public ModelingObject {
+private:
+ double A;
+ double B;
+ double C;
+ double D;
+ double current_temperature;
+ double previous_temperature;
+ double warm;
+
+public:
+ NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm);
+ void calculate_and_print(const int& time);
+};
+
+#endif // MODELS_H
\ No newline at end of file
diff --git "a/trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt" "b/trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt"
new file mode 100644
index 00000000..e69de29b
diff --git a/trunck/as0006315/task_01/src/CMakeLists.txt b/trunck/as0006315/task_01/src/CMakeLists.txt
new file mode 100644
index 00000000..92a3d66f
--- /dev/null
+++ b/trunck/as0006315/task_01/src/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.10)
+project(MyProject)
+
+# Устанавливаем переменную SRC_DIR
+set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
+
+# Добавляем исходные файлы
+add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cpp ${SRC_DIR}/models.cpp)
+
+# Добавляем заголовочные файлы
+include_directories(${SRC_DIR})
\ No newline at end of file
diff --git a/trunck/as0006315/task_01/src/main.cpp b/trunck/as0006315/task_01/src/main.cpp
new file mode 100644
index 00000000..cf676c09
--- /dev/null
+++ b/trunck/as0006315/task_01/src/main.cpp
@@ -0,0 +1,78 @@
+#include "models.h"
+#include
+#include
+
+using namespace std;
+
+void get_liner_model();
+void get_nonlinear_model();
+bool choice_input(int &choice);
+
+int main() {
+ void (*point[])() = { []() { exit(0); }, get_liner_model, get_nonlinear_model};
+ int choice;
+ while (true) {
+ cout << "\n\tInput choice (0 - exit, 1 - linear model, 2 - nonlinear model)\n";
+ if (!choice_input(choice)) {
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ continue;
+ }
+ point[choice]();
+ }
+
+ return 0;
+}
+
+template bool input_value(T &value, const string &name) {
+ while (true) {
+ cout << "Input " << name << ": ";
+ if (cin >> value) {
+ return true;
+ }
+ else {
+ cin.clear();
+ cin.ignore(numeric_limits::max(), '\n');
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ }
+ }
+}
+
+void get_liner_model() {
+ double A, B, current_temperature, warm;
+ int time;
+ input_value(A, "A");
+ input_value(B, "B");
+ input_value(current_temperature, "current_temperature");
+ input_value(warm, "warm");
+ input_value(time, "time");
+ LinearModel model(A, B, current_temperature, warm);
+ model.calculate_and_print(time);
+}
+
+void get_nonlinear_model() {
+ double A, B, C, D, current_temperature, warm;
+ int time;
+ input_value(A, "A");
+ input_value(B, "B");
+ input_value(C, "C");
+ input_value(D, "D");
+ input_value(current_temperature, "current_temperature");
+ input_value(warm, "warm");
+ input_value(time, "time");
+ NonLinearModel model(A, B, C, D, current_temperature, warm);
+ model.calculate_and_print(time);
+}
+
+bool choice_input(int &choice) {
+ while (true) {
+ if (input_value(choice, "choice")) {
+ if (choice >= 0 && choice <= 2) {
+ return true;
+ }
+ else {
+ cerr << "\n\a\t\t***Input value is not correct***\n\n";
+ }
+ }
+ }
+}
+
diff --git a/trunck/as0006315/task_01/src/models.cpp b/trunck/as0006315/task_01/src/models.cpp
new file mode 100644
index 00000000..16b3f41a
--- /dev/null
+++ b/trunck/as0006315/task_01/src/models.cpp
@@ -0,0 +1,37 @@
+#include "models.h"
+
+LinearModel::LinearModel(double a, double b, double current_temperature, double warm)
+ : A(a), B(b), current_temperature(current_temperature), warm(warm) {}
+
+void LinearModel::calculate_and_print(const int& time) {
+ std::cout.setf(std::ios::left);
+ std::cout << std::setw(10) << "TIME";
+ std::cout << std::setw(30) << "LINEAR MODEL" << std::endl;
+ std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+ double temp = current_temperature;
+ for (int i = 1; i <= time; ++i) {
+ std::cout << std::setw(10) << i;
+ temp = A * temp + B * warm;
+ std::cout << std::setw(30) << temp << std::endl;
+ }
+}
+
+NonLinearModel::NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm)
+ : A(A), B(B), C(C), D(D), current_temperature(current_temperature), warm(warm) {}
+
+void NonLinearModel::calculate_and_print(const int& time) {
+ std::cout.setf(std::ios::left);
+ std::cout << std::setw(10) << "TIME";
+ std::cout << std::setw(30) << "NONLINEAR MODEL" << std::endl;
+ std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+ double curr_temp = current_temperature;
+ double previous_temperature = 0.0;
+ double buffer = 0.0;
+ for (int i = 1; i <= time; ++i) {
+ std::cout << std::setw(10) << i;
+ buffer = A * curr_temp - B * pow(previous_temperature, 2) + C * warm + D * sin(warm);
+ previous_temperature = curr_temp;
+ curr_temp = buffer;
+ std::cout << std::setw(30) << curr_temp << std::endl;
+ }
+}
diff --git a/trunck/as0006315/task_01/src/models.h b/trunck/as0006315/task_01/src/models.h
new file mode 100644
index 00000000..a77f0d7a
--- /dev/null
+++ b/trunck/as0006315/task_01/src/models.h
@@ -0,0 +1,41 @@
+#ifndef MODELS_H
+#define MODELS_H
+
+#include
+#include
+#include
+#include
+
+class ModelingObject {
+public:
+ virtual void calculate_and_print(const int& time) = 0;
+};
+
+class LinearModel : public ModelingObject {
+private:
+ double A;
+ double B;
+ double current_temperature;
+ double warm;
+
+public:
+ LinearModel(double a, double b, double current_temperature, double warm);
+ void calculate_and_print(const int& time);
+};
+
+class NonLinearModel : public ModelingObject {
+private:
+ double A;
+ double B;
+ double C;
+ double D;
+ double current_temperature;
+ double previous_temperature;
+ double warm;
+
+public:
+ NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm);
+ void calculate_and_print(const int& time);
+};
+
+#endif // MODELS_H
\ No newline at end of file
From f6c5b19dff3991bbc85ebac848efe5f623127dcf Mon Sep 17 00:00:00 2001
From: gleb7499 <164905074+gleb7499@users.noreply.github.com>
Date: Tue, 17 Sep 2024 19:27:00 +0300
Subject: [PATCH 2/6] Added readme.md file
---
trunck/as0006315/task_01/doc/readme.md | 105 ++++++++++++++++++
...1\203\320\274\320\265\320\275\321\202.txt" | 0
2 files changed, 105 insertions(+)
create mode 100644 trunck/as0006315/task_01/doc/readme.md
delete mode 100644 "trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt"
diff --git a/trunck/as0006315/task_01/doc/readme.md b/trunck/as0006315/task_01/doc/readme.md
new file mode 100644
index 00000000..81c88112
--- /dev/null
+++ b/trunck/as0006315/task_01/doc/readme.md
@@ -0,0 +1,105 @@
+Ministry of Education of the Republic of Belarus
+ Educational Institution
+“Brest State Technical University”
+Department of Computer Science and Information Technologies
+
+Laboratory work №1
+On the discipline “Theory and methods of automatic control”
+Topic: “Modeling of object temperature”
+
+Performed by:
+Student of the 3rd course
+Group AS-63
+Loginov G. O.
+Checked by:
+Sitkovets Y. S.
+
+Brest 2024
+
+---
+
+## Task:
+
+Let's get some object to be controlled. We want to control its temperature, which can be described by this differential equation:
+
+$$\Large\frac{dy(\tau)}{d\tau}=\frac{u(\tau)}{C}+\frac{Y_0-y(\tau)}{RC} $$ (1)
+
+where $\tau$ – time; $y(\tau)$ – input temperature; $u(\tau)$ – input warm; $Y_0$ – room temperature; $C,RC$ – some constants.
+
+After transformation we get these linear (2) and nonlinear (3) models:
+
+$$\Large y_{\tau+1}=ay_{\tau}+bu_{\tau}$$ (2)
+
+$$\Large y_{\tau+1}=ay_{\tau}-by_{\tau-1}^2+cu_{\tau}+d\sin(u_{\tau-1})$$ (3)
+
+where $\tau$ – time discrete moments ($1,2,3{\dots}n$); $a,b,c,d$ – some constants.
+
+Task is to write program (**С++**), which simulates this object temperature.
+
+## Example of program output:
+
+``` bash
+ Input choice (0 - exit, 1 - linear model, 2 - nonlinear model)
+Input choice: 1
+Input A: 2
+Input B: 3.96
+Input current_temperature: 12
+Input warm: 40
+Input time: 5
+TIME LINEAR MODEL
+=========================
+1 182.4
+2 523.2
+3 1204.8
+4 2568
+5 5294.4
+
+ Input choice (0 - exit, 1 - linear model, 2 - nonlinear model)
+Input choice: 2
+Input A: 8
+Input B: 3
+Input C: 0.1
+Input D: 2.015
+Input current_temperature: 1
+Input warm: 12
+Input time: 7
+TIME NONLINEAR MODEL
+=========================
+1 8.11881
+2 62.0693
+3 298.928
+4 -9166.23
+5 -341403
+6 -2.54791e+08
+7 -3.51707e+11
+```
+
+### Input error handling has also been added:
+``` bash
+ Input choice (0 - exit, 1 - linear model, 2 - nonlinear model)
+Input choice: 5
+
+ ***Input value is not correct***
+
+Input choice: р
+
+ ***Input value is not correct***
+```
+
+### And exit the program:
+
+``` bash
+ Input choice (0 - exit, 1 - linear model, 2 - nonlinear model)
+Input choice: 0
+PS C:\Users\kseni\Documents\Универ\3курс\ТМАУ\TMAU-2024-my\TMAU-2024\tasks\task_01\build>
+```
+
+## The source code
+
+#### The source code is located in the [src folder](/src/).
+
+- [CMakeLists.txt](/src/CMakeLists.txt) - this is a file that contains CMake commands to control the project build process.
+- [models.h](/src/models.h) - header file, contains functions declarations for linear and nonlinear models simulation.
+- [models.cpp](/src/models.cpp) - source file, contains functions definitions for linear and nonlinear models simulation.
+- [main.cpp](/src/main.cpp) - source file, contains the main function that controls the program execution.
+
diff --git "a/trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt" "b/trunck/as0006315/task_01/doc/\320\242\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt"
deleted file mode 100644
index e69de29b..00000000
From e4982d5f201f1b5687eb14e6ad764f2ea8b00704 Mon Sep 17 00:00:00 2001
From: gleb7499 <164905074+gleb7499@users.noreply.github.com>
Date: Tue, 17 Sep 2024 19:38:02 +0300
Subject: [PATCH 3/6] some refactoring
---
.../as0006315/task_01/doc/readme.md | 30 +++++++++----------
.../as0006315/task_01/src/CMakeLists.txt | 0
.../as0006315/task_01/src/main.cpp | 0
.../as0006315/task_01/src/models.cpp | 0
.../as0006315/task_01/src/models.h | 0
5 files changed, 15 insertions(+), 15 deletions(-)
rename {trunck => trunk}/as0006315/task_01/doc/readme.md (61%)
rename {trunck => trunk}/as0006315/task_01/src/CMakeLists.txt (100%)
rename {trunck => trunk}/as0006315/task_01/src/main.cpp (100%)
rename {trunck => trunk}/as0006315/task_01/src/models.cpp (100%)
rename {trunck => trunk}/as0006315/task_01/src/models.h (100%)
diff --git a/trunck/as0006315/task_01/doc/readme.md b/trunk/as0006315/task_01/doc/readme.md
similarity index 61%
rename from trunck/as0006315/task_01/doc/readme.md
rename to trunk/as0006315/task_01/doc/readme.md
index 81c88112..8db03925 100644
--- a/trunck/as0006315/task_01/doc/readme.md
+++ b/trunk/as0006315/task_01/doc/readme.md
@@ -1,18 +1,18 @@
-Ministry of Education of the Republic of Belarus
- Educational Institution
-“Brest State Technical University”
-Department of Computer Science and Information Technologies
+Ministry of Education of the Republic of Belarus
+Educational Institution
+“Brest State Technical University”
+Department of Computer Systems and Information Technologies
-Laboratory work №1
-On the discipline “Theory and methods of automatic control”
-Topic: “Modeling of object temperature”
+Laboratory work No. 1
+on the discipline “Theory and methods of automatic control”
+Theme: “Temperature modeling of an object”
Performed by:
-Student of the 3rd course
+Student of the 3rd year
Group AS-63
-Loginov G. O.
+Loganov G. A.
Checked by:
-Sitkovets Y. S.
+Sitkovets Yu. S.
Brest 2024
@@ -96,10 +96,10 @@ PS C:\Users\kseni\Documents\Универ\3курс\ТМАУ\TMAU-2024-my\TMAU-20
## The source code
-#### The source code is located in the [src folder](/src/).
+#### The source code is located in the [src folder](/trunk/as0006315/task_01/src).
-- [CMakeLists.txt](/src/CMakeLists.txt) - this is a file that contains CMake commands to control the project build process.
-- [models.h](/src/models.h) - header file, contains functions declarations for linear and nonlinear models simulation.
-- [models.cpp](/src/models.cpp) - source file, contains functions definitions for linear and nonlinear models simulation.
-- [main.cpp](/src/main.cpp) - source file, contains the main function that controls the program execution.
+- [CMakeLists.txt](/trunk/as0006315/task_01/src/CMakeLists.txt) - this is a file that contains CMake commands to control the project build process.
+- [models.h](/trunk/as0006315/task_01/src/models.h) - header file, contains functions declarations for linear and nonlinear models simulation.
+- [models.cpp](/trunk/as0006315/task_01/src/models.cpp) - source file, contains functions definitions for linear and nonlinear models simulation.
+- [main.cpp](/trunk/as0006315/task_01/src/main.cpp) - source file, contains the main function that controls the program execution.
diff --git a/trunck/as0006315/task_01/src/CMakeLists.txt b/trunk/as0006315/task_01/src/CMakeLists.txt
similarity index 100%
rename from trunck/as0006315/task_01/src/CMakeLists.txt
rename to trunk/as0006315/task_01/src/CMakeLists.txt
diff --git a/trunck/as0006315/task_01/src/main.cpp b/trunk/as0006315/task_01/src/main.cpp
similarity index 100%
rename from trunck/as0006315/task_01/src/main.cpp
rename to trunk/as0006315/task_01/src/main.cpp
diff --git a/trunck/as0006315/task_01/src/models.cpp b/trunk/as0006315/task_01/src/models.cpp
similarity index 100%
rename from trunck/as0006315/task_01/src/models.cpp
rename to trunk/as0006315/task_01/src/models.cpp
diff --git a/trunck/as0006315/task_01/src/models.h b/trunk/as0006315/task_01/src/models.h
similarity index 100%
rename from trunck/as0006315/task_01/src/models.h
rename to trunk/as0006315/task_01/src/models.h
From f38e0d585f8b0f0f7800b2616da246a4d48b5b9e Mon Sep 17 00:00:00 2001
From: gleb7499 <164905074+gleb7499@users.noreply.github.com>
Date: Tue, 17 Sep 2024 19:44:47 +0300
Subject: [PATCH 4/6] correction of the display of the title page of the report
---
trunk/as0006315/task_01/doc/readme.md | 28 +++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/trunk/as0006315/task_01/doc/readme.md b/trunk/as0006315/task_01/doc/readme.md
index 8db03925..0087944f 100644
--- a/trunk/as0006315/task_01/doc/readme.md
+++ b/trunk/as0006315/task_01/doc/readme.md
@@ -1,20 +1,20 @@
-Ministry of Education of the Republic of Belarus
-Educational Institution
-“Brest State Technical University”
-Department of Computer Systems and Information Technologies
+Ministry of Education of the Republic of Belarus
+Educational Institution
+“Brest State Technical University”
+Department of Information and Intelligent Technologies
-Laboratory work No. 1
-on the discipline “Theory and methods of automatic control”
-Theme: “Temperature modeling of an object”
+Laboratory work №1
+On the discipline “Theory and methods of automatic control”
+Topic: “Temperature modeling of an object”
-Performed by:
-Student of the 3rd year
-Group AS-63
-Loganov G. A.
-Checked by:
-Sitkovets Yu. S.
+Performed by:
+Student of the 3rd course
+Group AS-63
+Loginov G. O.
+Supervised by:
+Sitkovets J. S.
-Brest 2024
+Brest 2024
---
From b8ab6931fb44d26c9100d0ded126dc7b8d228ff1 Mon Sep 17 00:00:00 2001
From: gleb7499 <164905074+gleb7499@users.noreply.github.com>
Date: Wed, 18 Sep 2024 15:52:15 +0300
Subject: [PATCH 5/6] The calculate_and_print() function has been split into
two (calculate and print). A small refactoring has been performed.
---
tasks/task_01/CMakeLists.txt | 11 ---
tasks/task_01/src/main.cpp | 78 -------------------
tasks/task_01/src/models.cpp | 37 ---------
tasks/task_01/src/models.h | 41 ----------
{tasks => trunk/as0006315}/task_01/.gitignore | 1 +
trunk/as0006315/task_01/src/CMakeLists.txt | 5 +-
trunk/as0006315/task_01/src/main.cpp | 10 ++-
trunk/as0006315/task_01/src/models.cpp | 39 ++++++----
trunk/as0006315/task_01/src/models.h | 15 +++-
9 files changed, 42 insertions(+), 195 deletions(-)
delete mode 100644 tasks/task_01/CMakeLists.txt
delete mode 100644 tasks/task_01/src/main.cpp
delete mode 100644 tasks/task_01/src/models.cpp
delete mode 100644 tasks/task_01/src/models.h
rename {tasks => trunk/as0006315}/task_01/.gitignore (56%)
diff --git a/tasks/task_01/CMakeLists.txt b/tasks/task_01/CMakeLists.txt
deleted file mode 100644
index 92a3d66f..00000000
--- a/tasks/task_01/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 3.10)
-project(MyProject)
-
-# Устанавливаем переменную SRC_DIR
-set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
-
-# Добавляем исходные файлы
-add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cpp ${SRC_DIR}/models.cpp)
-
-# Добавляем заголовочные файлы
-include_directories(${SRC_DIR})
\ No newline at end of file
diff --git a/tasks/task_01/src/main.cpp b/tasks/task_01/src/main.cpp
deleted file mode 100644
index cf676c09..00000000
--- a/tasks/task_01/src/main.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "models.h"
-#include
-#include
-
-using namespace std;
-
-void get_liner_model();
-void get_nonlinear_model();
-bool choice_input(int &choice);
-
-int main() {
- void (*point[])() = { []() { exit(0); }, get_liner_model, get_nonlinear_model};
- int choice;
- while (true) {
- cout << "\n\tInput choice (0 - exit, 1 - linear model, 2 - nonlinear model)\n";
- if (!choice_input(choice)) {
- cerr << "\n\a\t\t***Input value is not correct***\n\n";
- continue;
- }
- point[choice]();
- }
-
- return 0;
-}
-
-template bool input_value(T &value, const string &name) {
- while (true) {
- cout << "Input " << name << ": ";
- if (cin >> value) {
- return true;
- }
- else {
- cin.clear();
- cin.ignore(numeric_limits::max(), '\n');
- cerr << "\n\a\t\t***Input value is not correct***\n\n";
- }
- }
-}
-
-void get_liner_model() {
- double A, B, current_temperature, warm;
- int time;
- input_value(A, "A");
- input_value(B, "B");
- input_value(current_temperature, "current_temperature");
- input_value(warm, "warm");
- input_value(time, "time");
- LinearModel model(A, B, current_temperature, warm);
- model.calculate_and_print(time);
-}
-
-void get_nonlinear_model() {
- double A, B, C, D, current_temperature, warm;
- int time;
- input_value(A, "A");
- input_value(B, "B");
- input_value(C, "C");
- input_value(D, "D");
- input_value(current_temperature, "current_temperature");
- input_value(warm, "warm");
- input_value(time, "time");
- NonLinearModel model(A, B, C, D, current_temperature, warm);
- model.calculate_and_print(time);
-}
-
-bool choice_input(int &choice) {
- while (true) {
- if (input_value(choice, "choice")) {
- if (choice >= 0 && choice <= 2) {
- return true;
- }
- else {
- cerr << "\n\a\t\t***Input value is not correct***\n\n";
- }
- }
- }
-}
-
diff --git a/tasks/task_01/src/models.cpp b/tasks/task_01/src/models.cpp
deleted file mode 100644
index 16b3f41a..00000000
--- a/tasks/task_01/src/models.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "models.h"
-
-LinearModel::LinearModel(double a, double b, double current_temperature, double warm)
- : A(a), B(b), current_temperature(current_temperature), warm(warm) {}
-
-void LinearModel::calculate_and_print(const int& time) {
- std::cout.setf(std::ios::left);
- std::cout << std::setw(10) << "TIME";
- std::cout << std::setw(30) << "LINEAR MODEL" << std::endl;
- std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
- double temp = current_temperature;
- for (int i = 1; i <= time; ++i) {
- std::cout << std::setw(10) << i;
- temp = A * temp + B * warm;
- std::cout << std::setw(30) << temp << std::endl;
- }
-}
-
-NonLinearModel::NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm)
- : A(A), B(B), C(C), D(D), current_temperature(current_temperature), warm(warm) {}
-
-void NonLinearModel::calculate_and_print(const int& time) {
- std::cout.setf(std::ios::left);
- std::cout << std::setw(10) << "TIME";
- std::cout << std::setw(30) << "NONLINEAR MODEL" << std::endl;
- std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
- double curr_temp = current_temperature;
- double previous_temperature = 0.0;
- double buffer = 0.0;
- for (int i = 1; i <= time; ++i) {
- std::cout << std::setw(10) << i;
- buffer = A * curr_temp - B * pow(previous_temperature, 2) + C * warm + D * sin(warm);
- previous_temperature = curr_temp;
- curr_temp = buffer;
- std::cout << std::setw(30) << curr_temp << std::endl;
- }
-}
diff --git a/tasks/task_01/src/models.h b/tasks/task_01/src/models.h
deleted file mode 100644
index a77f0d7a..00000000
--- a/tasks/task_01/src/models.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef MODELS_H
-#define MODELS_H
-
-#include
-#include
-#include
-#include
-
-class ModelingObject {
-public:
- virtual void calculate_and_print(const int& time) = 0;
-};
-
-class LinearModel : public ModelingObject {
-private:
- double A;
- double B;
- double current_temperature;
- double warm;
-
-public:
- LinearModel(double a, double b, double current_temperature, double warm);
- void calculate_and_print(const int& time);
-};
-
-class NonLinearModel : public ModelingObject {
-private:
- double A;
- double B;
- double C;
- double D;
- double current_temperature;
- double previous_temperature;
- double warm;
-
-public:
- NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm);
- void calculate_and_print(const int& time);
-};
-
-#endif // MODELS_H
\ No newline at end of file
diff --git a/tasks/task_01/.gitignore b/trunk/as0006315/task_01/.gitignore
similarity index 56%
rename from tasks/task_01/.gitignore
rename to trunk/as0006315/task_01/.gitignore
index 5acb669b..be5e9100 100644
--- a/tasks/task_01/.gitignore
+++ b/trunk/as0006315/task_01/.gitignore
@@ -1,2 +1,3 @@
build
.vscode
+CMakeFiles
diff --git a/trunk/as0006315/task_01/src/CMakeLists.txt b/trunk/as0006315/task_01/src/CMakeLists.txt
index 92a3d66f..37f6cd6e 100644
--- a/trunk/as0006315/task_01/src/CMakeLists.txt
+++ b/trunk/as0006315/task_01/src/CMakeLists.txt
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(MyProject)
-# Устанавливаем переменную SRC_DIR
-set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
-
# Добавляем исходные файлы
-add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cpp ${SRC_DIR}/models.cpp)
+add_executable(${PROJECT_NAME} main.cpp models.cpp)
# Добавляем заголовочные файлы
include_directories(${SRC_DIR})
\ No newline at end of file
diff --git a/trunk/as0006315/task_01/src/main.cpp b/trunk/as0006315/task_01/src/main.cpp
index cf676c09..a29cb133 100644
--- a/trunk/as0006315/task_01/src/main.cpp
+++ b/trunk/as0006315/task_01/src/main.cpp
@@ -6,7 +6,7 @@ using namespace std;
void get_liner_model();
void get_nonlinear_model();
-bool choice_input(int &choice);
+bool choice_input(const int &choice);
int main() {
void (*point[])() = { []() { exit(0); }, get_liner_model, get_nonlinear_model};
@@ -46,7 +46,8 @@ void get_liner_model() {
input_value(warm, "warm");
input_value(time, "time");
LinearModel model(A, B, current_temperature, warm);
- model.calculate_and_print(time);
+ model.calculate(time);
+ model.print();
}
void get_nonlinear_model() {
@@ -60,10 +61,11 @@ void get_nonlinear_model() {
input_value(warm, "warm");
input_value(time, "time");
NonLinearModel model(A, B, C, D, current_temperature, warm);
- model.calculate_and_print(time);
+ model.calculate(time);
+ model.print();
}
-bool choice_input(int &choice) {
+bool choice_input(const int &choice) {
while (true) {
if (input_value(choice, "choice")) {
if (choice >= 0 && choice <= 2) {
diff --git a/trunk/as0006315/task_01/src/models.cpp b/trunk/as0006315/task_01/src/models.cpp
index 16b3f41a..8acbc94a 100644
--- a/trunk/as0006315/task_01/src/models.cpp
+++ b/trunk/as0006315/task_01/src/models.cpp
@@ -1,37 +1,44 @@
#include "models.h"
-LinearModel::LinearModel(double a, double b, double current_temperature, double warm)
- : A(a), B(b), current_temperature(current_temperature), warm(warm) {}
-
-void LinearModel::calculate_and_print(const int& time) {
+void ModelingObject::print(const std::map &temps, const std::string &name) {
std::cout.setf(std::ios::left);
std::cout << std::setw(10) << "TIME";
- std::cout << std::setw(30) << "LINEAR MODEL" << std::endl;
+ std::cout << std::setw(30) << name << std::endl;
std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+ for (auto it = temps.begin(); it != temps.end(); ++it) {
+ std::cout << std::setw(10) << it->first;
+ std::cout << std::setw(30) << it->second << std::endl;
+ }
+}
+
+LinearModel::LinearModel(double a, double b, double current_temperature, double warm) : A(a), B(b), current_temperature(current_temperature), warm(warm) {}
+
+void LinearModel::calculate(const int& time) {
double temp = current_temperature;
for (int i = 1; i <= time; ++i) {
- std::cout << std::setw(10) << i;
temp = A * temp + B * warm;
- std::cout << std::setw(30) << temp << std::endl;
+ temps[i] = temp;
}
}
-NonLinearModel::NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm)
- : A(A), B(B), C(C), D(D), current_temperature(current_temperature), warm(warm) {}
+void LinearModel::print() {
+ ModelingObject::print(this->temps, "LINEAR MODEL");
+}
+
+NonLinearModel::NonLinearModel(double A, double B, double C, double D, double current_temperature, double warm) : A(A), B(B), C(C), D(D), current_temperature(current_temperature), warm(warm) {}
-void NonLinearModel::calculate_and_print(const int& time) {
- std::cout.setf(std::ios::left);
- std::cout << std::setw(10) << "TIME";
- std::cout << std::setw(30) << "NONLINEAR MODEL" << std::endl;
- std::cout << std::setfill('=') << std::setw(25) << "" << std::setfill(' ') << std::endl;
+void NonLinearModel::calculate(const int& time) {
double curr_temp = current_temperature;
double previous_temperature = 0.0;
double buffer = 0.0;
for (int i = 1; i <= time; ++i) {
- std::cout << std::setw(10) << i;
buffer = A * curr_temp - B * pow(previous_temperature, 2) + C * warm + D * sin(warm);
previous_temperature = curr_temp;
curr_temp = buffer;
- std::cout << std::setw(30) << curr_temp << std::endl;
+ temps[i] = curr_temp;
}
}
+
+void NonLinearModel::print() {
+ ModelingObject::print(this->temps, "NONLINEAR MODEL");
+}
diff --git a/trunk/as0006315/task_01/src/models.h b/trunk/as0006315/task_01/src/models.h
index a77f0d7a..d2dd422e 100644
--- a/trunk/as0006315/task_01/src/models.h
+++ b/trunk/as0006315/task_01/src/models.h
@@ -5,10 +5,12 @@
#include
#include
#include
+#include