From c826d3f7264bdafb612198e7bda5d84b8dbb9ff3 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov Date: Tue, 18 Feb 2025 13:31:39 +0300 Subject: [PATCH 1/9] add case diskriminant < 0 --- hw.cpp/functions.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw.cpp/functions.cpp b/hw.cpp/functions.cpp index ed311f5..fdaec03 100644 --- a/hw.cpp/functions.cpp +++ b/hw.cpp/functions.cpp @@ -6,7 +6,12 @@ std::vector solve(double a, double b, double c) { } std::vectorres; double diskr = b * b - 4 * a * c; - + if (diskr < 0) { + std::exception ex("The roots are not real, D < 0\n"); + std::cout << ex.what(); + + exit(1); + } res.push_back((-b + sqrt(diskr)) / (2 * a)); res.push_back((-b - sqrt(diskr)) / (2 * a)); return res; From b4679c4a4a61ca546826e9055e4cf246e13b98fc Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:46:46 +0300 Subject: [PATCH 2/9] Delete hw.cpp/Header.hpp --- hw.cpp/Header.hpp | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 hw.cpp/Header.hpp diff --git a/hw.cpp/Header.hpp b/hw.cpp/Header.hpp deleted file mode 100644 index 1e5aa07..0000000 --- a/hw.cpp/Header.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include -#include -#include -#include -std::vector solve(double a, double b, double c); From b7b109b0afb6c33b9e5baf6177665a333efdd8b3 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:46:55 +0300 Subject: [PATCH 3/9] Delete hw.cpp/functions.cpp --- hw.cpp/functions.cpp | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 hw.cpp/functions.cpp diff --git a/hw.cpp/functions.cpp b/hw.cpp/functions.cpp deleted file mode 100644 index fdaec03..0000000 --- a/hw.cpp/functions.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Header.hpp" - -std::vector solve(double a, double b, double c) { - if (a == 0) { - throw std::invalid_argument("Coefficient 'a' can't be zero."); - } - std::vectorres; - double diskr = b * b - 4 * a * c; - if (diskr < 0) { - std::exception ex("The roots are not real, D < 0\n"); - std::cout << ex.what(); - - exit(1); - } - res.push_back((-b + sqrt(diskr)) / (2 * a)); - res.push_back((-b - sqrt(diskr)) / (2 * a)); - return res; -} \ No newline at end of file From f6436c07a8c5ddc1608ecbf6da78f396d40ec67d Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:47:31 +0300 Subject: [PATCH 4/9] Delete hw.cpp/hw.cpp.sln --- hw.cpp/hw.cpp.sln | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 hw.cpp/hw.cpp.sln diff --git a/hw.cpp/hw.cpp.sln b/hw.cpp/hw.cpp.sln deleted file mode 100644 index 642f965..0000000 --- a/hw.cpp/hw.cpp.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.12.35527.113 d17.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hw.cpp", "hw.cpp.vcxproj", "{5861813B-A2F6-4AFF-A225-42ED788A9F92}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Debug|x64.ActiveCfg = Debug|x64 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Debug|x64.Build.0 = Debug|x64 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Debug|x86.ActiveCfg = Debug|Win32 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Debug|x86.Build.0 = Debug|Win32 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Release|x64.ActiveCfg = Release|x64 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Release|x64.Build.0 = Release|x64 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Release|x86.ActiveCfg = Release|Win32 - {5861813B-A2F6-4AFF-A225-42ED788A9F92}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal From b66033f957cbb521c5eb0b3afac2de50c90f1165 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:47:38 +0300 Subject: [PATCH 5/9] Delete hw.cpp/hw.cpp.vcxproj --- hw.cpp/hw.cpp.vcxproj | 140 ------------------------------------------ 1 file changed, 140 deletions(-) delete mode 100644 hw.cpp/hw.cpp.vcxproj diff --git a/hw.cpp/hw.cpp.vcxproj b/hw.cpp/hw.cpp.vcxproj deleted file mode 100644 index fe750bd..0000000 --- a/hw.cpp/hw.cpp.vcxproj +++ /dev/null @@ -1,140 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {5861813b-a2f6-4aff-a225-42ed788a9f92} - hwcpp - 10.0 - hw1.cpp - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - \ No newline at end of file From 9529f70ea09d6919d8007177f0ccc641f4a24409 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:47:45 +0300 Subject: [PATCH 6/9] Delete hw.cpp/hw.cpp.vcxproj.filters --- hw.cpp/hw.cpp.vcxproj.filters | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 hw.cpp/hw.cpp.vcxproj.filters diff --git a/hw.cpp/hw.cpp.vcxproj.filters b/hw.cpp/hw.cpp.vcxproj.filters deleted file mode 100644 index 4d7bb0b..0000000 --- a/hw.cpp/hw.cpp.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - Исходные файлы - - - - - Файлы заголовков - - - \ No newline at end of file From 637a4d31a52c953b52e698e527e6fe757dcb9c02 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:47:52 +0300 Subject: [PATCH 7/9] Delete hw.cpp/hww.cpp --- hw.cpp/hww.cpp | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 hw.cpp/hww.cpp diff --git a/hw.cpp/hww.cpp b/hw.cpp/hww.cpp deleted file mode 100644 index 94bc096..0000000 --- a/hw.cpp/hww.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "Header.hpp" - -int main() { - double a, b, c; - std::cout << "Enter coefficients:" << std::endl; - std::cout << "a, b, c" << std::endl; - std::cin >> a >> b >> c; - - if (a == 0) { - std::cout << "This is not a quadratic equation." << std::endl; - return 1; - } - - std::cout << "The equation turned out:" << std::endl; - std::cout << a << "x^2 + " << b << "x + " << c << " = 0" << std::endl; - - std::vector res = solve(a, b, c); - - std::cout << "Roots of the equation: " << std::endl; - if (res.empty()) { - std::cout << "No real roots." << std::endl; - } - else { - for (const auto& root : res) { - std::cout << root << " "; - } - std::cout << std::endl; - } - - return 0; -} \ No newline at end of file From ef418666d7684d2f6bbf2c52c42388ed4625c075 Mon Sep 17 00:00:00 2001 From: Artem Nikonorov Date: Tue, 18 Feb 2025 14:00:22 +0300 Subject: [PATCH 8/9] add all files --- homework/Header.hpp | 6 ++ homework/functions.cpp | 19 ++++ homework/homework.sln | 28 ++++++ homework/homework.vcxproj | 139 ++++++++++++++++++++++++++++++ homework/homework.vcxproj.filters | 30 +++++++ homework/main.cpp | 32 +++++++ 6 files changed, 254 insertions(+) create mode 100644 homework/Header.hpp create mode 100644 homework/functions.cpp create mode 100644 homework/homework.sln create mode 100644 homework/homework.vcxproj create mode 100644 homework/homework.vcxproj.filters create mode 100644 homework/main.cpp diff --git a/homework/Header.hpp b/homework/Header.hpp new file mode 100644 index 0000000..bc693b4 --- /dev/null +++ b/homework/Header.hpp @@ -0,0 +1,6 @@ +#pragma once +#include +#include +#include + +std::vector solve(double a, double b, double c); \ No newline at end of file diff --git a/homework/functions.cpp b/homework/functions.cpp new file mode 100644 index 0000000..b93bfe7 --- /dev/null +++ b/homework/functions.cpp @@ -0,0 +1,19 @@ +#include "Header.hpp" + +std::vector solve(double a, double b, double c) { + if (a == 0) { + throw invalid + } + std::vectorres; + double diskr = b * b - 4 * a * c; + + if (diskr < 0) { + std::exception ex("Roots are not real, diskriminant < 0"); + cout << ex.what(); + exit(1); + } + double diskr = b * b - 4 * a * c; + res.push_back((-b + sqrt(diskr)) / (2 * a)); + res.push_back((-b - sqrt(diskr)) / (2 * a)); + return res; +} \ No newline at end of file diff --git a/homework/homework.sln b/homework/homework.sln new file mode 100644 index 0000000..b10d28b --- /dev/null +++ b/homework/homework.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "homework", "homework.vcxproj", "{ABF24FD9-A54B-4309-8932-F9CBF777409B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Debug|x64.ActiveCfg = Debug|x64 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Debug|x64.Build.0 = Debug|x64 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Debug|x86.ActiveCfg = Debug|Win32 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Debug|x86.Build.0 = Debug|Win32 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Release|x64.ActiveCfg = Release|x64 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Release|x64.Build.0 = Release|x64 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Release|x86.ActiveCfg = Release|Win32 + {ABF24FD9-A54B-4309-8932-F9CBF777409B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/homework/homework.vcxproj b/homework/homework.vcxproj new file mode 100644 index 0000000..c805101 --- /dev/null +++ b/homework/homework.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {abf24fd9-a54b-4309-8932-f9cbf777409b} + homework + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/homework/homework.vcxproj.filters b/homework/homework.vcxproj.filters new file mode 100644 index 0000000..4ece200 --- /dev/null +++ b/homework/homework.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + \ No newline at end of file diff --git a/homework/main.cpp b/homework/main.cpp new file mode 100644 index 0000000..8968a25 --- /dev/null +++ b/homework/main.cpp @@ -0,0 +1,32 @@ +#include "Header.hpp" +#include + +int main() { + double a, b, c; + std::cout << "Enter coefficients:" << std::endl; + std::cout << "a, b, c" << std::endl; + std::cin >> a >> b >> c; + + if (a == 0) { + std::cout << "This is not a quadratic equation." << std::endl; + return 1; + } + + std::cout << "The equation turned out:" << std::endl; + std::cout << a << "x^2 + " << b << "x + " << c << " = 0" << std::endl; + + std::vector res = solve(a, b, c); + + std::cout << "Roots of the equation: " << std::endl; + if (res.empty()) { + std::cout << "No real roots." << std::endl; + } + else { + for (const auto& root : res) { + std::cout << root << " "; + } + std::cout << std::endl; + } + + return 0; +} \ No newline at end of file From 3817ae64f42abb7a7a3c00b13a2178632bc280fe Mon Sep 17 00:00:00 2001 From: Artem Nikonorov <147204464+akkniko@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:18:08 +0300 Subject: [PATCH 9/9] Update functions.cpp delete error with coefficient a --- homework/functions.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/homework/functions.cpp b/homework/functions.cpp index b93bfe7..7985a6f 100644 --- a/homework/functions.cpp +++ b/homework/functions.cpp @@ -1,9 +1,6 @@ #include "Header.hpp" std::vector solve(double a, double b, double c) { - if (a == 0) { - throw invalid - } std::vectorres; double diskr = b * b - 4 * a * c; @@ -16,4 +13,4 @@ std::vector solve(double a, double b, double c) { res.push_back((-b + sqrt(diskr)) / (2 * a)); res.push_back((-b - sqrt(diskr)) / (2 * a)); return res; -} \ No newline at end of file +}