diff --git a/Calculator v0.1/Calculator/Calculator.cpp b/Calculator v0.1/Calculator/Calculator.cpp new file mode 100644 index 0000000..2383196 --- /dev/null +++ b/Calculator v0.1/Calculator/Calculator.cpp @@ -0,0 +1,20 @@ + +#include +#include +#include "calcul.h" +using namespace std; + +int main() +{ + calcul cal; + char c; + while (c=cin.peek()) + { + if (c == '#') break;//прерываем цикл записи + cal.readthread(); + cal.maths(); + cin.ignore(); + } + + +} diff --git a/Calculator v0.1/Calculator/calcul.cpp b/Calculator v0.1/Calculator/calcul.cpp new file mode 100644 index 0000000..d5a9fdb --- /dev/null +++ b/Calculator v0.1/Calculator/calcul.cpp @@ -0,0 +1,160 @@ +#include "calcul.h" + +int priority(char c)//приоритеты операций +{ + if ((c == '+') || (c == '-')) return 1; + if ((c == '*') || (c == '/')) return 2; + return 0; +} + +void calcul::processing_oper(char c)//обработка полученных опреаций +{ + if ((operation.size() == 0) || (c == '('))//открывающую скобку в любом случае либо в начало стека, либо кладём в стек поверх других операций + { + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; + } + + if (priority(c) <= priority(operation.top())) + //если у рассматриваемой операции приоритет меньше или равен уже лежащей на стеке операции, то сначала посчитаем операцию, которая есть на стеке, а потом добавим новую + { + oper(); + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; + } + //стек с операциями не пуст и приоритет рассматриваемой операции не меньше, чем уже положенная на стек + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; +} + +bool calcul::check_neg(char c)//обработка отрицательных чисел, если оно первое число в выражении или идёт после открывающей скобочки +{ + if (c == '-') + { + if (number.size() == 0) + return true; + if ((operation.top() == '(') && (operation.size() > number.size()))//когда - сразу после скобок, то количесвто операций превышает количество считанных чисел + { + return true; + } + return false;//c='-' но ни одно из условий не выполнено + } + return false; +} + +void calcul::readthread() +{ + char c; + while (c = cin.peek()) + { + if (c == '\n') break; + if (c == ' ') + { + cin.ignore(); + continue; + }; + if (((c >= '0') && (c <= '9')) || check_neg(c))//словили цифру от 0 до 9 + + { + double value; + cin >> value;//извлекаем число из потока + number.push(value); + continue; + } + if ((c == '+') || (c == '-') || (c == '/') || (c == '*') || (c == '(')) + { + processing_oper(c); + continue; + } + if (c == ')') + { + while (operation.top() != '(')//выполняем опрации в скобочках + { + oper(); + } + operation.pop();//удаляем открывающуюся скобку + cin.ignore();//извлекаем просмотренный символ из потока + continue; + } + + cout << "Expression entered incorrectly" << endl; + break; + + } +} + +calcul::calcul() +{ + +} + + +void calcul::maths()//чтобы обработать все необработанные операции с числами +{ + while (operation.size() != 0) + { + oper(); + } + if (number.size() != 0) cout << "Result=" << number.top() << endl; + number.pop();//удаляем последнее число в стеке +} + +void calcul::oper()//обрабатывает только одну операцию с числами +{ + double a, b, c; + a = number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + b=number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + //берём операцию из стека с операциями + switch (operation.top()) + { + case '+': sum(a, b); break; + case '-': substraction(b, a); break;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + case '*': multiplication(a, b); break; + case '/': division(b, a); break;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + } + if (operation.size()!=0) operation.pop();//удаляем операцию из стека при условии, что он не пуст, после попытки деления на 0 +} + +void calcul::sum(double a, double b) +{ + double c = a + b; + number.push(c);//кладём результат в стек с числами +} +void calcul::substraction(double a, double b) +{ + double c = a - b; + number.push(c);//кладём результат в стек с числами +} + + +template //шаблон, так как у нас два стека разных типов +void clearStack(stack & s) +{ + while (s.size() != 0) { + s.pop(); + } + return; +} + +void calcul::division(double a, double b) +{ + if (b == 0) + { + cout<<"Error. You can't divide by zero"; + //Чтобы дальше не обрабатывать операции, очищаем стеки чисел и операций + clearStack(operation); + clearStack(number); + return; + } + double c = a / b; + number.push(c);//кладём результат в стек с числами +} +void calcul::multiplication(double a, double b) +{ + double c = a * b; + number.push(c);//кладём результат в стек с числами +} \ No newline at end of file diff --git a/Calculator v0.1/Calculator/calcul.h b/Calculator v0.1/Calculator/calcul.h new file mode 100644 index 0000000..bea1bcf --- /dev/null +++ b/Calculator v0.1/Calculator/calcul.h @@ -0,0 +1,33 @@ +#pragma once +#ifndef calcul_h +#define calcul_h + +#include +#include +#include +#include + +using namespace std; + +class calcul +{ +private: + stack number; + stack operation; + +public: + calcul(); + void readthread(); + bool check_neg(char c); + void maths(); + void oper(); + void processing_oper(char c); + void sum(double a, double b); + void substraction(double a, double b); + void division(double a, double b); + void multiplication(double a, double b); + + + +}; +#endif \ No newline at end of file diff --git a/Calculator/Calculator.sln b/Calculator/Calculator.sln new file mode 100644 index 0000000..4cf099c --- /dev/null +++ b/Calculator/Calculator.sln @@ -0,0 +1,31 @@ +п»ї +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Calculator", "Calculator\Calculator.vcxproj", "{EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}" +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 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Debug|x64.ActiveCfg = Debug|x64 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Debug|x64.Build.0 = Debug|x64 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Debug|x86.ActiveCfg = Debug|Win32 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Debug|x86.Build.0 = Debug|Win32 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Release|x64.ActiveCfg = Release|x64 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Release|x64.Build.0 = Release|x64 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Release|x86.ActiveCfg = Release|Win32 + {EB43910F-C3D2-44CF-A1FF-855A2AA6EE51}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BE3AC232-DA28-4578-827B-9660B65419AC} + EndGlobalSection +EndGlobal diff --git a/Calculator/Calculator/Calculator.cpp b/Calculator/Calculator/Calculator.cpp new file mode 100644 index 0000000..ef706ee --- /dev/null +++ b/Calculator/Calculator/Calculator.cpp @@ -0,0 +1,13 @@ + +#include +#include +#include "calcul.h" +using namespace std; + +int main() +{ + calcul cal; + + cal.maths(); + +} diff --git a/Calculator/Calculator/Calculator.vcxproj b/Calculator/Calculator/Calculator.vcxproj new file mode 100644 index 0000000..3da545f --- /dev/null +++ b/Calculator/Calculator/Calculator.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {eb43910f-c3d2-44cf-a1ff-855a2aa6ee51} + Calculator + 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/Calculator/Calculator/calcul.cpp b/Calculator/Calculator/calcul.cpp new file mode 100644 index 0000000..1d80a59 --- /dev/null +++ b/Calculator/Calculator/calcul.cpp @@ -0,0 +1,141 @@ +#include "calcul.h" + +int priority(char c) +{ + if ((c == '+') || (c == '-')) return 1; + if ((c == '*') || (c == '/')) return 2; + else return 0;//если встретили0 открывающуюся скобку +} + +bool calcul::check_neg(char c)//обработка отрицательных чисел, если оно первое число в выражении или идёт после открывающей скобочки +{ + if (c == '-') + { + if (number.size() == 0) + return true; + else if ((operation.top() == '(') && (operation.size() > number.size()))//когда - сразу после скобок, то количесвто операций превышает количество считанных чисел + { + return true; + } + else return false; + } + else return false; +} + +calcul::calcul() +{ + char c; + while (c=cin.peek()) + { + if (c == '\n') break; + if (c == ' ') cin.ignore(); + if (((c >='0') && (c <= '9')) || check_neg(c))//словили цифру от 0 до 9 + + { + double value; + cin >> value;//извлекаем число из потока + number.push(value); + continue; + } + if ((c == '+') || (c == '-') || (c == '/') || (c == '*') || (c=='(')) + { + if ((operation.size() == 0)||(c=='('))//открывающую скобку в любом случае либо в начало стека, либо кладём в стек поверх других операций + { + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + } + else if (priority(c) <= priority(operation.top())) + //если у рассматриваемой операции приоритет меньше или равен уже лежащей на стеке операции, то сначала посчитаем операцию, которая есть на стеке, а потом добавим новую + { + oper(); + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + } + else//стек с операциями не пуст и приоритет рассматриваемой операции не меньше, чем уже положенная на стек + { + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + } + continue; + } + if (c == ')') + { + while (operation.top() != '(')//выполняем опрации в скобочках + { + oper(); + } + operation.pop();//удаляем открывающуюся скобку + cin.ignore();//извлекаем просмотренный символ из потока + } + else { + cout << "Expression entered incorrectly" << endl; + break; + } + } +} + + +void calcul::maths()//чтобы обработать все необработанные операции с числами +{ + while (operation.size() != 0) + { + oper(); + } + if (number.size() != 0) cout << "Result=" << number.top() << endl; +} + +void calcul::oper()//обрабатывает только одну операцию с числами +{ + double a, b, c; + a = number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + b=number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + //берём операцию из стека с операциями + switch (operation.top()) + { + case '+': sum(a, b); break; + case '-': substraction(b, a); break;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + case '*': multiplication(a, b); break; + case '/': division(b, a); break;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + } + if (operation.size()!=0) operation.pop();//удаляем операцию из стека при условии, что он не пуст, после попытки деления на 0 +} +void calcul::sum(double a, double b) +{ + double c = a + b; + number.push(c);//кладём результат в стек с числами +} +void calcul::substraction(double a, double b) +{ + double c = a - b; + number.push(c);//кладём результат в стек с числами +} + + +template //шаблон, так как у нас два стека разных типов +void clearStack(stack & s) +{ + while (s.size() != 0) { + s.pop(); + } + return; +} + +void calcul::division(double a, double b) +{ + if (b == 0) + { + cout<<"Error. You can't divide by zero"; + //Чтобы дальше не обрабатывать операции, очищаем стеки чисел и операций + clearStack(operation); + clearStack(number); + return; + } + double c = a / b; + number.push(c);//кладём результат в стек с числами +} +void calcul::multiplication(double a, double b) +{ + double c = a * b; + number.push(c);//кладём результат в стек с числами +} \ No newline at end of file diff --git a/Calculator/Calculator/calcul.h b/Calculator/Calculator/calcul.h new file mode 100644 index 0000000..761f7f8 --- /dev/null +++ b/Calculator/Calculator/calcul.h @@ -0,0 +1,30 @@ +#pragma once +#ifndef calcul_h +#define calcul_h + +#include +#include +#include +#include + +using namespace std; + +class calcul +{ +public: + stack number; + stack operation; + + calcul(); + bool check_neg(char c); + void maths(); + void oper(); + void sum(double a, double b); + void substraction(double a, double b); + void division(double a, double b); + void multiplication(double a, double b); + + + +}; +#endif \ No newline at end of file diff --git a/Calculator_main/Calculator_main/CMakeLists.txt b/Calculator_main/Calculator_main/CMakeLists.txt new file mode 100644 index 0000000..0b12039 --- /dev/null +++ b/Calculator_main/Calculator_main/CMakeLists.txt @@ -0,0 +1,20 @@ +п»ї# CMakeList.txt : CMake project for Calculator_main, include source and define +# project specific logic here. +# +cmake_minimum_required(VERSION 3.8) + +project( Calculator_main ) + +set(CMAKE_CXX_STANDARD 20) + +add_executable (Calculator_main "Calculator_main.cpp" "Calculator_main.h" "calcul.cpp" "calcul.h" "dll_read.h" "dll_read.cpp") + +set( SOURCE_LIB C:/program_visual_studio/programming/Calculator_main/plugins ) + +set ( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON ) + +add_library(cos SHARED ${SOURCE_LIB}/cos.cpp ) + +add_library(lg SHARED ${SOURCE_LIB}/lg.cpp) + +target_link_libraries(Calculator_main cos lg) diff --git a/Calculator_main/Calculator_main/Calculator_main.cpp b/Calculator_main/Calculator_main/Calculator_main.cpp new file mode 100644 index 0000000..939b4e2 --- /dev/null +++ b/Calculator_main/Calculator_main/Calculator_main.cpp @@ -0,0 +1,30 @@ +п»ї// Calculator_main.cpp : Defines the entry point for the application. +// + +#include "Calculator_main.h" + +#include +#include "calcul.h" +using namespace std; + +int main() +{ + cout << "This is a calculator" << endl; + cout << "Standart operations: +, -, *, /, ^, ()" << endl; + cout << "Non-standart mathematical operations: cos, ln" << endl; + cout << "To complete the work enter #" << endl << endl; + cout << "Enter the expression: "; + + calcul cal; + char c; + while (c = cin.peek()) + { + if (c == '#') break;//прерываем цикл записи + cal.readthread(); + cal.maths(); + cout << endl << "Enter the expression: "; + cin.ignore(); + } + + +} diff --git a/Calculator_main/Calculator_main/Calculator_main.h b/Calculator_main/Calculator_main/Calculator_main.h new file mode 100644 index 0000000..31a6fb2 --- /dev/null +++ b/Calculator_main/Calculator_main/Calculator_main.h @@ -0,0 +1,8 @@ +п»ї// Calculator_main.h : Include file for standard system include files, +// or project specific include files. + +#pragma once + +#include + +// TODO: Reference additional headers your program requires here. diff --git a/Calculator_main/Calculator_main/calcul.cpp b/Calculator_main/Calculator_main/calcul.cpp new file mode 100644 index 0000000..439d0e1 --- /dev/null +++ b/Calculator_main/Calculator_main/calcul.cpp @@ -0,0 +1,211 @@ +#include "calcul.h" + +template //шаблон, так как у нас два стека разных типов +void calcul::clearStack(stack & s) +{ + while (s.size() != 0) { + s.pop(); + } + return; +} + +calcul::calcul() +{ + oper_priority = { + {"+",1}, + {"-",1}, + {"*",2}, + {"/",2}, + {"^",3} + }; + function.insert( + { "+", + [&](double a,double b) {double c = a + b; number.push(c); }//кладём результат в стек с числами + } + ); + function.insert( + { "-", + [&](double a,double b) + {double c = b - a;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + number.push(c); + }//кладём результат в стек с числами + } + ); + function.insert( + { "*", + [&](double a,double b) {double c = a * b; number.push(c); }//кладём результат в стек с числами + } + ); + function.insert( + { "/", + [&](double a,double b) {if (a == 0) + { + cout << "Error. You can't divide by zero" << endl; + //Чтобы дальше не обрабатывать операции, очищаем стеки чисел и операций + clearStack(operation); + clearStack(number); + return; + } + double c = b / a;//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + number.push(c);//кладём результат в стек с числами + } + } + ); + function.insert( + { + "^", + [&](double a,double b) {double c = pow(b,a);//меняем порядок. так как порядок в стеке отличается от изначального порядка в консоли + number.push(c); } + }); +} + +void calcul::readthread() +{ + char c; + while (c = cin.peek()) + { + std::string s; + std::stringstream ss; + ss << c; + ss >> s; + if (c == '\n') break; + if (c == ' ') + { + cin.ignore(); + continue; + }; + if (((c >= '0') && (c <= '9')) || check_neg(s))//словили цифру от 0 до 9 + + { + double value; + cin >> value;//извлекаем число из потока + number.push(value); + continue; + } + if ((c == '+') || (c == '-') || (c == '/') || (c == '*') || (c == '(') || (c == '^')) + { + processing_oper(s); + continue; + } + if ((c == 'c') || (c == 'l')) + { + string nstand; + while (c != '(') { + nstand.push_back(c); + cin.ignore(); + c = cin.peek(); + } + + operation.push(nstand); + + continue; + } + if (c == ')') + { + while (operation.top() != "(")//выполняем опрации в скобочках + { + oper(); + } + operation.pop();//удаляем открывающуюся скобку + cin.ignore();//извлекаем просмотренный символ из потока + if (operation.size()!=0) nonstandart();//если после '(' сразу идёт нестандартная функция, сразу её считаем, чтобы не возникало проблем при подсчёте сложных выражений + continue; + } + } +} + +void calcul::processing_oper(string c)//обработка полученных опреаций +{ + if ((operation.size() == 0) || (c == "("))//открывающую скобку в любом случае либо в начало стека, либо кладём в стек поверх других операций + { + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; + } + + if (oper_priority[c] <= oper_priority[operation.top()]) + //если у рассматриваемой операции приоритет меньше или равен уже лежащей на стеке операции, то сначала посчитаем операцию, которая есть на стеке, а потом добавим новую + { + oper(); + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; + } + //стек с операциями не пуст и приоритет рассматриваемой операции не меньше, чем уже положенная на стек + operation.push(c); + cin.ignore();//извлекаем просмотренный символ из потока + return; +} + +bool calcul::check_neg(string c)//обработка отрицательных чисел, если оно первое число в выражении или идёт после открывающей скобочки +{ + if (c == "-") + { + if (number.size() == 0) + return true; + if (operation.size() != 0) + { + if ((operation.top() == "(") && (operation.size() > number.size()))//когда - сразу после скобок, то количество операций превышает количество считанных чисел + return true; + } + return false;//c='-' но ни одно из условий не выполнено + } + return false; +} + + +void calcul::maths()//чтобы обработать все необработанные операции с числами +{ + while (operation.size() != 0) + { + if (function.find(operation.top()) != function.end()) + { + oper(); + continue; + } + //нет обработки функций из plagins так как их считаем сразу как встретились, + //чтобы можно было правильно вычислять сложные выражения использующие нестандартные функции + cout << "Expression entered incorrectly" << endl; + clearStack(operation); + clearStack(number); + break; + } + if (number.size() != 0) + { + cout << "Result=" << number.top() << endl; + number.pop();//удаляем последнее число в стеке (результат) + } +} + +void calcul::nonstandart() +{ + if (dll.is_plugin(operation.top())) + { + double a = number.top(); + number.pop(); + double result = dll.calculation(operation.top(), a); + number.push(result); + operation.pop(); + } +} + +void calcul::oper()//обрабатывает только одну стандартную операцию с числами +{ + double a, b, c; + a = number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + b = number.top();//взяли вверхнее число из стека + number.pop();//удалили взятое число из стека + + //берём операцию из стека с операциями + function[operation.top()](a, b); + if (operation.size() != 0) operation.pop();//удаляем операцию из стека при условии, что он не пуст, после попытки деления на 0 +} + + +calcul::~calcul() +{ + clearStack(operation);//очищаем стек с опреациями + clearStack(number);//очищаем стек с числами + function.clear();//очищаем map с операциями + oper_priority.clear();//очищаем map с приоритетами +} \ No newline at end of file diff --git a/Calculator_main/Calculator_main/calcul.h b/Calculator_main/Calculator_main/calcul.h new file mode 100644 index 0000000..51ad877 --- /dev/null +++ b/Calculator_main/Calculator_main/calcul.h @@ -0,0 +1,41 @@ +#pragma once +#ifndef calcul_h +#define calcul_h + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dll_read.h" + + +using namespace std; + +class calcul +{ +private: + stack number; + stack operation; + map oper_priority;//приоритеты математических операций + map > function;//соотнесение математической операции и то, что она делает + dll_read dll; + +public: + calcul(); + void readthread(); + bool check_neg(string c); + void maths(); + void oper(); + void nonstandart(); + void processing_oper(string c); + template + void clearStack(stack & s); + ~calcul(); + +}; +#endif \ No newline at end of file diff --git a/Calculator_main/Calculator_main/dll_read.cpp b/Calculator_main/Calculator_main/dll_read.cpp new file mode 100644 index 0000000..8d8fe92 --- /dev/null +++ b/Calculator_main/Calculator_main/dll_read.cpp @@ -0,0 +1,34 @@ +#include "dll_read.h" + +dll_read::dll_read() { + WIN32_FIND_DATAA detect; + HANDLE det = FindFirstFileA((p + std::string("*.dll")).c_str(), &detect); + if (det == INVALID_HANDLE_VALUE) { + throw std::exception();//библиотека не существует + return; + } + do { + std::string func_name(detect.cFileName); + HMODULE hm = LoadLibraryA((p + func_name).c_str()); + if (!hm) throw std::exception();//проблема в загрузке библиотеки + + std::string funct = func_name.substr(0, func_name.find(".dll")); + + auto func = (double (*) (double))GetProcAddress(hm, "func"); + + if (func) { + function.insert(std::pair(funct, func)); + continue; + } + throw std::exception(); + } while (FindNextFileA(det, &detect) != NULL); +} + +double dll_read::calculation(std::string s, double num) { + + return(function[s](num)); +} + +bool dll_read::is_plugin(std::string str) { + return(function.find(str) != function.end()); +} \ No newline at end of file diff --git a/Calculator_main/Calculator_main/dll_read.h b/Calculator_main/Calculator_main/dll_read.h new file mode 100644 index 0000000..11d3a26 --- /dev/null +++ b/Calculator_main/Calculator_main/dll_read.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef dll_read_h +#define dll_read_h + +#include +#include +#include +#include +#include + +class dll_read +{ +private: + std::map > function; + std::string p = "C:\\program_visual_studio\\programming\\Calculator_main\\plugins\\"; +public: + dll_read(); + bool is_plugin(std::string s); + double calculation(std::string s,double number); +}; + +#endif \ No newline at end of file diff --git a/Calculator_main/plugins/cos.cpp b/Calculator_main/plugins/cos.cpp new file mode 100644 index 0000000..048f4ae --- /dev/null +++ b/Calculator_main/plugins/cos.cpp @@ -0,0 +1,9 @@ +#include +#define _USE_MATH_DEFINES +#define M_PI 3.14159265358979323846 + +extern "C" __declspec(dllexport) + +double func(double number) { + return std::cos(number*M_PI/180); +} \ No newline at end of file diff --git a/Calculator_main/plugins/cos.dll b/Calculator_main/plugins/cos.dll new file mode 100644 index 0000000..a24bc13 Binary files /dev/null and b/Calculator_main/plugins/cos.dll differ diff --git a/Calculator_main/plugins/lg.cpp b/Calculator_main/plugins/lg.cpp new file mode 100644 index 0000000..03d786d --- /dev/null +++ b/Calculator_main/plugins/lg.cpp @@ -0,0 +1,11 @@ +#include +#include +extern "C" __declspec(dllexport) + +double func(double number) { + if (number <= 0) + { + std::cout << "The logarithm of a non-positive number does not exist" << std::endl; + } + return std::log10(number); +} \ No newline at end of file diff --git a/Calculator_main/plugins/lg.dll b/Calculator_main/plugins/lg.dll new file mode 100644 index 0000000..3282edb Binary files /dev/null and b/Calculator_main/plugins/lg.dll differ diff --git a/Calculator_main_v.final/Calculator_main_v.final/CMakeLists.txt b/Calculator_main_v.final/Calculator_main_v.final/CMakeLists.txt new file mode 100644 index 0000000..f84baeb --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/CMakeLists.txt @@ -0,0 +1,25 @@ +п»ї# CMakeList.txt : CMake project for Calculator_main_v.final, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) + +project( Calculator_main ) +set(CMAKE_CXX_STANDARD 20) +# Add source to this project's executable. + +set(PROJECT_HEADERS Calculator_main.h, calcul.h) +add_executable(Calculator_main ${PROJECT_SOURCE_DIR}/ Calculator_main.cpp calcul.cpp "dll_read.cpp" "dll_read.h") + +add_library(cos SHARED ./plugins/cos.cpp "plugins/cos.cpp" "dll_read.cpp" "dll_read.h") +add_library(lg SHARED ./plugins/lg.cpp "plugins/lg.cpp" "dll_read.cpp" "dll_read.h") +add_library(sin SHARED ./plugins/sin.cpp "plugins/sin.cpp" "dll_read.cpp" "dll_read.h") +add_library(tg SHARED ./plugins/tg.cpp "plugins/tg.cpp" "dll_read.cpp" "dll_read.h") +add_library(ctg SHARED ./plugins/ctg.cpp "plugins/ctg.cpp" "dll_read.cpp" "dll_read.h") +add_library(ln SHARED ./plugins/ln.cpp "plugins/ln.cpp" "dll_read.cpp" "dll_read.h") +add_library(sqrt SHARED ./plugins/sqrt.cpp "plugins/sqrt.cpp" "dll_read.cpp" "dll_read.h") +add_library(cubsqrt SHARED ./plugins/cubsqrt.cpp "plugins/cubsqrt.cpp" "dll_read.cpp" "dll_read.h") +add_library(abs SHARED ./plugins/abs.cpp "plugins/abs.cpp" "dll_read.cpp" "dll_read.h") +add_library(round SHARED ./plugins/round.cpp "plugins/round.cpp" "dll_read.cpp" "dll_read.h") + +target_link_libraries(Calculator_main cos lg sin tg ctg ln sqrt cubsqrt abs round) + diff --git a/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.cpp b/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.cpp new file mode 100644 index 0000000..297ec11 --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.cpp @@ -0,0 +1,33 @@ +п»ї// Calculator_main.cpp : Defines the entry point for the application. +// + +#include "Calculator_main.h" +#include +#include "calcul.h" + +void main() +{ + std::cout << "This is a calculator" << std::endl; + std::cout << "Standart operations: +, -, *, /, ^, ()" << std::endl; + std::cout << "Non-standart mathematical operations: cos lg sin tg ctg ln sqrt cubsqrt abs round" << std::endl; + std::cout << "cubsqrt - counts the cubic root" << std::endl; + std::cout << "round - rounds to the largest integer, but not more than this number" << std::endl; + std::cout << "To complete the work enter #" << std::endl << std::endl; + + calcul cal; + if (cal.validation()) + { + std::cout << "Enter the expression: "; + char c; + while (c = std::cin.peek()) + { + if (c == '#') break;//interrupting the recording cycle + cal.readthread(); + cal.maths(); + std::cin.ignore();//extracting a scanned character for a common expression from a stream + std::cout << std::endl << "Enter the expression: "; + } + } + + +} diff --git a/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.h b/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.h new file mode 100644 index 0000000..c3dcd3b --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/Calculator_main.h @@ -0,0 +1,8 @@ +п»ї// Calculator_main_v.final.h : Include file for standard system include files, +// or project specific include files. + +#pragma once + +#include + +// TODO: Reference additional headers your program requires here. diff --git a/Calculator_main_v.final/Calculator_main_v.final/calcul.cpp b/Calculator_main_v.final/Calculator_main_v.final/calcul.cpp new file mode 100644 index 0000000..5fcc09f --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/calcul.cpp @@ -0,0 +1,258 @@ +#include "calcul.h" + +calcul::calcul() +{ + oper_priority = { + {"+",1}, + {"-",1}, + {"*",2}, + {"/",2}, + {"^",3} + }; + function.insert( + { "+", + [&](double a,double b) {double c = a + b; number.push(c); }//put the result into the stack of numbers + } + ); + function.insert( + { "-", + [&](double a,double b) + {double c = b - a;//change order because the stack order is different from the initial order in the console + number.push(c); + }//put the result into the stack of numbers + } + ); + function.insert( + { "*", + [&](double a,double b) {double c = a * b; number.push(c); }//put the result into the stack of numbers + } + ); + function.insert( + { "/", + [&](double a,double b) { + if (a == 0) + { + std::cout << "Error. You can't divide by zero" << std::endl; + //In order not to continue processing operations, we clear stacks of numbers and operations + deleteStacksEr(); + return; + } + double c = b / a;//change order because the stack order is different from the initial order in the console + number.push(c);//put the result into the stack of numbers + } + } + ); + function.insert( + { + "^", + [&](double a,double b) {double c = pow(b,a);//change order because the stack order is different from the initial order in the console + number.push(c); } + }); +} + +bool calcul::validation() +{ + //exception handling + try + { + dll.read_files(); + } + catch (std::exception) + { + std::cout << "Error in dll" << std::endl; + return false; + } + return true; +} + +template //template, because we have two stacks of different types +void calcul::clearStack(std::stack & s) +{ + while (s.size() != 0) { + s.pop(); + } + return; +} + +void calcul::readthread() +{ + char c; + while (c = std::cin.peek()) + { + std::string s; + std::stringstream ss; + ss << c; + ss >> s; + if (c == '\n') break; + if (c == ' ') + { + std::cin.ignore(); + continue; + }; + if (((c >= '0') && (c <= '9')) || check_neg(s))//number 0 to 9 + negative number check + { + double value; + std::cin >> value;//extracting a number from the stream + number.push(value); + continue; + } + if ((c == '+') || (c == '-') || (c == '/') || (c == '*') || (c == '(') || (c == '^')) + { + processing_oper(s); + if ((number.size()!=0)||(operation.size()!=0)) std::cin.ignore();//extracting the viewed symbol from the stream + continue; + } + if ((c == 'c') || (c == 'l') || (c=='s') || (c=='t') || (c=='r') ||(c=='a')) + { + std::string nstand; + while (c != '(') { + nstand.push_back(c); + std::cin.ignore(); + c = std::cin.peek(); + if ((c == ')')||(c=='\n')) break;//the expression was entered incorrectly + } + if ((c == ')') || (c == '\n')) + { + deleteStacksEr(); + break; + } + operation.push(nstand); + continue; + } + if (c == ')') + { + while (operation.top() != "(")//we perform operations in parentheses + { + if (function.find(operation.top()) != function.end()) + { + oper(); + if (operation.size() == 0) break;//if there was a division by 0, then the stacks became empty and it is necessary to stop the cycle + continue; + } + expr_incor(); + break; + } + if (number.size()!=0) std::cin.ignore();//extracting the scanned symbol from the stream, provided that there was no stack clearing due to an incorrect expression + if (operation.size() != 0) + { + operation.pop();//if there was no division by zero, then the opening bracket remains in the stack and it must be removed from the stack + if (nonstandart() == -1)//checking that a non-standard function is valid + { + deleteStacksEr(); + break; + } + } + continue; + } + //caught an incorrect character + deleteStacksEr(); + break; + } +} + +void calcul::expr_incor() +{ + std::cout << "Expression entered incorrectly" << std::endl; + clearStack(operation); + clearStack(number); +} + +void calcul::deleteStacksEr() +{ + std::string s; + std::getline(std::cin, s, '\n'); + expr_incor(); + std::cout << "To continue, press Enter" << std::endl; +} + +void calcul::processing_oper(std::string c)//processing of the received options +{ + if ((operation.empty()) || (c == "("))//in any case, the opening bracket is either at the beginning of the stack, or we put it on the stack on top of other operations + { + operation.push(c); + return; + } + + if (oper_priority[c] <= oper_priority[operation.top()]) + //if the operation in question has a priority less than or equal to the operation already lying on the stack, then first we will count the operation that is on the stack, and then we will add a new one + { + oper(); + if (number.size()!=0) operation.push(c);//check if the stack is not cleared after dividing by 0 + return; + } + //the stack with operations is not empty and the priority of the operation in question is not less than the one already placed on the stack + operation.push(c); + return; +} + +bool calcul::check_neg(std::string c)//processing negative numbers if it is the first number in the expression or comes after the opening parenthesis +{ + if (c == "-") + { + if (number.size() == 0) + return true; + if (operation.size() != 0) + { + if ((operation.top() == "(") && (operation.size() > number.size()))//when '-' is immediately after the parentheses, the number of operations exceeds the number of numbers read + return true; + } + return false;//c='-' but none of the conditions are met + } + return false; +} + +void calcul::maths()//to process all raw operations with numbers +{ + while (operation.size() != 0) + { + if (function.find(operation.top()) != function.end()) + { + oper(); + continue; + } + //there is no processing of functions from plugins as we consider them as soon as we met, + //so that complex expressions using non-standard functions can be correctly calculated + expr_incor(); + break; + } + if (number.size() != 0) + { + std::cout << "Result=" << number.top() << std::endl; + number.pop();//deleting the last number in the stack (result) + } +} + +int calcul::nonstandart() +{ + if (dll.is_plugin(operation.top())) + { + double a = number.top(); + number.pop(); + if (!dll.calculation(operation.top(), a)) return -1; + number.push(a); + operation.pop(); + return 1; + } + return 0; +} + +void calcul::oper()//handles only one standard operation with numbers +{ + double a, b; + a = number.top();//took the top number from the stack + number.pop();//removed the taken number from the stack + b = number.top();//took the top number from the stack + number.pop();//removed the taken number from the stack + + //taking an operation from the stack with operations + function[operation.top()](a, b); + if (operation.size() != 0) operation.pop();//we remove the operation from the stack, provided that it is not empty, after an attempt to divide by 0 +} + +calcul::~calcul() +{ + clearStack(operation);//clearing the stack with operations + clearStack(number);//clearing the stack with numbers + function.clear();//clearing the map with operations + oper_priority.clear();//clearing the map with priorities +} \ No newline at end of file diff --git a/Calculator_main_v.final/Calculator_main_v.final/calcul.h b/Calculator_main_v.final/Calculator_main_v.final/calcul.h new file mode 100644 index 0000000..0780045 --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/calcul.h @@ -0,0 +1,41 @@ +#pragma once +#ifndef calcul_h +#define calcul_h + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dll_read.h" + + +class calcul +{ +private: + std::stack number; + std::stack operation; + std::map oper_priority;//mathematical operations priorities + std::map > function;//correlation of a mathematical operation and what it does + dll_read dll; + bool check_neg(std::string c);//checking whether the number is negative + void oper();//processing of a single mathematical operation + int nonstandart();//working with non-standard functions + void deleteStacksEr();//clearing stacks if an error occurred when evaluating an expression (exception handling) + void processing_oper(std::string c);//processing of mathematical operations, namely checking for the emptiness of the stack and the priority of the mathematical operation + void expr_incor();//clearing stacks when an expression is entered incorrectly + template + void clearStack(std::stack & s); + +public: + calcul(); + bool validation();//checking exceptions from dynamic libraries + void readthread();//reading an expression from a stream + void maths();//perform mathematical operations and is responsible for the output of the result to the console + ~calcul(); +}; +#endif \ No newline at end of file diff --git a/Calculator_main_v.final/Calculator_main_v.final/dll_read.cpp b/Calculator_main_v.final/Calculator_main_v.final/dll_read.cpp new file mode 100644 index 0000000..dd6af54 --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/dll_read.cpp @@ -0,0 +1,36 @@ +#include "dll_read.h" + + +void dll_read::read_files() { + WIN32_FIND_DATAA detect; + HANDLE det = FindFirstFileA((p + std::string("*.dll")).c_str(), &detect); + + if (det == INVALID_HANDLE_VALUE) { + throw std::exception();//the library does not exist + return; + } + do { + std::string func_name(detect.cFileName); + HMODULE hm = LoadLibraryA((p + func_name).c_str()); + if (!hm) throw std::exception();//the problem is loading the library + + std::string funct = func_name.substr(0, func_name.find(".dll")); + + auto func = (bool (*) (double&))GetProcAddress(hm, "func"); + + if (func) { + function.insert(std::pair(funct, func)); + continue; + } + throw std::exception();//error in extracting the function address + } while (FindNextFileA(det, &detect) != NULL); +} + + +bool dll_read::calculation(std::string s, double& num) { + return(function[s](num)); +} + +bool dll_read::is_plugin(std::string str) { + return(function.find(str) != function.end()); +} \ No newline at end of file diff --git a/Calculator_main_v.final/Calculator_main_v.final/dll_read.h b/Calculator_main_v.final/Calculator_main_v.final/dll_read.h new file mode 100644 index 0000000..7482301 --- /dev/null +++ b/Calculator_main_v.final/Calculator_main_v.final/dll_read.h @@ -0,0 +1,26 @@ +#pragma once +#ifndef dll_read_h +#define dll_read_h + +#include +#include +#include +#include +#include + + +class dll_read +{ +private: + std::map > function; + std::string p = ".\\plugins\\"; + +public: + dll_read() {}; + void read_files(); + bool is_plugin(std::string s); + bool calculation(std::string s, double& number); + ~dll_read() { function.clear(); }; +}; + +#endif \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.cpp new file mode 100644 index 0000000..9d5325e --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.cpp @@ -0,0 +1,7 @@ +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + number = std::abs(number); + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.dll new file mode 100644 index 0000000..6175093 Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/abs.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.cpp new file mode 100644 index 0000000..4fb6b6b --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.cpp @@ -0,0 +1,15 @@ +#include +#define _USE_MATH_DEFINES +#define pi 3.14159265358979323846 +extern "C" __declspec(dllexport) + +bool func(double& number) { + double d=number; + number=std::cos(number*pi/180); + if (abs(sin(d * pi / 180)) == 1) + { + number=0;// angle= pi/2, 3*pi/2.. + } + + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.dll new file mode 100644 index 0000000..272c03e Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cos.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.cpp new file mode 100644 index 0000000..9774097 --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.cpp @@ -0,0 +1,17 @@ +#include +#include +#define _USE_MATH_DEFINES +#define pi 3.14159265358979323846 +extern "C" __declspec(dllexport) + +bool func(double& number) { + if (abs(cos(number * pi / 180)) == 1)//in this case sin=0 + { + std::cout << "The cotangent from 0 does not exist" << std::endl; + return false; + } + double d=number; + number = std::cos(number * pi / 180) / std::sin(number * pi / 180); + if (abs(sin(d * pi / 180)) == 1) number=0; + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.dll new file mode 100644 index 0000000..952813e Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ctg.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.cpp new file mode 100644 index 0000000..69c198c --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.cpp @@ -0,0 +1,8 @@ +#include +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + number=std::cbrt(number); + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.dll new file mode 100644 index 0000000..8de893e Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/cubsqrt.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.cpp new file mode 100644 index 0000000..96f5916 --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.cpp @@ -0,0 +1,13 @@ +#include +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + if (number <= 0) + { + std::cout << "The logarithm of a non-positive number does not exist" << std::endl; + return false; + } + number=std::log10(number); + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.dll new file mode 100644 index 0000000..57355a4 Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/lg.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.cpp new file mode 100644 index 0000000..6311159 --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.cpp @@ -0,0 +1,13 @@ +#include +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + if (number <= 0) + { + std::cout << "The logarithm of a non-positive number does not exist" << std::endl; + return false; + } + number = std::log(number); + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.dll new file mode 100644 index 0000000..167909c Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/ln.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.cpp new file mode 100644 index 0000000..627f8c3 --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.cpp @@ -0,0 +1,7 @@ +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + number=std::floor(number); + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.dll new file mode 100644 index 0000000..aeffa8a Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/round.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.cpp new file mode 100644 index 0000000..bf7a374 --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.cpp @@ -0,0 +1,14 @@ +#include +#define _USE_MATH_DEFINES +#define pi 3.14159265358979323846 +extern "C" __declspec(dllexport) + +bool func(double& number) { + double d=number; + number=std::sin(number*pi/180); + if (abs(cos(d * pi / 180)) == 1) + { + number=0;// angle=0,pi; 2*pi.. + } + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.dll new file mode 100644 index 0000000..264f3a6 Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sin.dll differ diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sqrt.cpp b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sqrt.cpp new file mode 100644 index 0000000..402728e --- /dev/null +++ b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/sqrt.cpp @@ -0,0 +1,13 @@ +#include +#include +extern "C" __declspec(dllexport) + +bool func(double& number) { + if (number<0) + { + std::cout<<"there is no square root of a negative number"< +#include +#define _USE_MATH_DEFINES +#define pi 3.14159265358979323846 +extern "C" __declspec(dllexport) + +bool func(double& number) { + + if (abs(sin(number * pi / 180)) == 1)//in this case cos=0 + { + std::cout << "The tangent from 90 does not exist" << std::endl; + return false; + } + double d=number; + number = std::sin(number * pi / 180) / std::cos(number * pi / 180); + if (abs(cos(d * pi / 180)) == 1) + { + number = 0; + } + return true; +} \ No newline at end of file diff --git a/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/tg.dll b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/tg.dll new file mode 100644 index 0000000..74bff83 Binary files /dev/null and b/Calculator_main_v.final/out/build/x64-debug/Calculator_main_v.final/plugins/tg.dll differ