From 606362d6db4009a3739ab7062f4938043f648f24 Mon Sep 17 00:00:00 2001 From: Anastasia <95341361+Anleo1@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:23:19 +0300 Subject: [PATCH 1/3] Create Functions.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Заголовочный файл функций --- Lab1/Functions.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Lab1/Functions.h diff --git a/Lab1/Functions.h b/Lab1/Functions.h new file mode 100644 index 0000000..c5069d1 --- /dev/null +++ b/Lab1/Functions.h @@ -0,0 +1,7 @@ +#pragma once +#include +#include +double* input(double[]); +double discriminant(double[]); +double* solve(double[], double[]); +void output(); From 668202fcc9c77a224142f49c45f70f51707646bf Mon Sep 17 00:00:00 2001 From: Anastasia <95341361+Anleo1@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:24:58 +0300 Subject: [PATCH 2/3] Create Functions.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Файл с функциями --- Lab1/Functions.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Lab1/Functions.cpp diff --git a/Lab1/Functions.cpp b/Lab1/Functions.cpp new file mode 100644 index 0000000..6d26ab0 --- /dev/null +++ b/Lab1/Functions.cpp @@ -0,0 +1,50 @@ +#include "Functions.h" + +double* input(double k[]) { + bool flag = true; + while (flag) + { + std::cout << "Введите коэффициенты(через enter):" << std::endl; + if (std::cin >> k[0] && std::cin >> k[1] && std::cin >> k[2]) + { + flag = false; + } + else + { + std::cin.clear(); + std::cin.ignore(1, '\n'); + std::cout << "Вы ввели неверные коэффициенты!" << std::endl; + } + } + return k; +} +double discriminant(double k[]) { + double dis = 0.0; + dis = ((k[1] * k[1]) - (4 * k[0] * k[2])); + if (dis < 0) { + std::cout << "Нет корней\n"; + exit(0); + } + else { + return sqrt(dis); + } +} +double* solve(double k[], double res[]) { + double dis = discriminant(k); + if (dis == 0) { + std::cout << "Два идентичных корня - вершина параболы\n"; + } + res[0] = ((-k[1] + dis) / (2 * k[0])); + res[1] = ((-k[1] - dis) / (2 * k[0])); + + return res; +} +void output() { + setlocale(LC_ALL, "Rus"); + double coefficients[3]; + double res[2]; + input(coefficients); + solve(coefficients, res); + std::cout << "Корни:\nx1 = " << res[0] << "\nx2 = " << res[1] << std::endl; + return; +} From d0198487c8a5cc6d949a134694e6c984719b089f Mon Sep 17 00:00:00 2001 From: Anastasia <95341361+Anleo1@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:26:06 +0300 Subject: [PATCH 3/3] Create Main.cpp --- Lab1/Main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Lab1/Main.cpp diff --git a/Lab1/Main.cpp b/Lab1/Main.cpp new file mode 100644 index 0000000..045d239 --- /dev/null +++ b/Lab1/Main.cpp @@ -0,0 +1,6 @@ +#include "Functions.h" + +int main() { + output(); + return 0; +}