-
Notifications
You must be signed in to change notification settings - Fork 12
Коротин Егор #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Коротин Егор #3
Changes from 15 commits
a23cc79
d670531
a3b0a88
67b9fce
1e1b078
e12651f
875fb31
9a116e8
b30c43a
9500bea
a4a686f
34a862b
7430a8b
1412cb3
624abd3
6fb4f08
83efbe9
602664f
1063426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,27 @@ | ||
| // ���������� ������� � ������� ��� ���������� �������������� ��������� | ||
| // ���������� ������� � ������� ��� ���������� �������������� ��������� | ||
|
|
||
| #include "stack.h" | ||
| #include <vector> | ||
| #include <map> | ||
| #include <cmath> | ||
| #include <string> | ||
|
|
||
| class TPostfix { | ||
| std::vector<std::string> RPN; | ||
|
|
||
| std::string Error_string(const std::string& s, int i); //Method that selects element number "i" in a string. Uses only for selecting incorrect element when throws. | ||
|
|
||
| int get_prior(const std::string& s) noexcept; //Method that return the priority of an operation. If it is not an operation returns 0 | ||
|
|
||
| int TPostfix::get_prior(char c) noexcept; //similar method for characters | ||
|
|
||
| double valid(const std::string& s); //Method that turns correct string into a number | ||
|
|
||
| std::string number_check(const std::string& s, int& i); //Method takes the string being processed and the index from which the expected number begins and checks it for correctness | ||
| public: | ||
| TPostfix(const std::string& s); //Turns string into a Reverse Polish Notation, if it possible. | ||
|
|
||
| double count(); //Count a string stored in a class element. User enter variables | ||
|
|
||
| double TPostfix::count(double* variables, int number_of_variables); //Count a string stored in a class element. Variables is entered by programm. | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,57 @@ | |
| // - �������� �� �������, | ||
| // - ��������� ���������� ��������� � ����� | ||
| // - ������� ����� | ||
| // ��� ������� � ������ ���� ������ �������������� ������ | ||
| // ��� ������� � ������ ���� ������ �������������� ������ | ||
| #include <iostream> | ||
|
|
||
| template <class T> | ||
| class TStack { | ||
| T* mas; | ||
| size_t count; | ||
| size_t size; | ||
| bool isFull() noexcept { | ||
| return count == size; | ||
| } | ||
| void resize() { | ||
| T* tmp = new T[size*2]; | ||
| std::copy(mas, mas + size, tmp); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Копируется size элементов, хотя значения лежат только в size/2 эл-тов |
||
| size *= 2; | ||
| delete[] mas; | ||
| mas = tmp; | ||
| } | ||
| public: | ||
| TStack() { | ||
| mas = new T[10]; | ||
| count = 0; | ||
| size = 10; | ||
| } | ||
| ~TStack() { | ||
| delete[] mas; | ||
| mas = nullptr; | ||
| } | ||
| bool isEmpty() noexcept { | ||
| return count == 0; | ||
| } | ||
| void push_back(const T& val) { | ||
| if (isFull()) resize(); | ||
| mas[count++] = val; | ||
| } | ||
| size_t GetCount() noexcept { | ||
| return count; | ||
| } | ||
| T& top() { | ||
| if (!isEmpty())return mas[count-1]; | ||
| throw std::out_of_range("There are no elements in this Stack"); | ||
| } | ||
| T pop_back() { | ||
| if (!isEmpty()) return mas[--count]; | ||
| throw std::out_of_range("There are no elements in this Stack"); | ||
| } | ||
| void clear() { | ||
| T* tmp = new T[10]; | ||
| count = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не ошибка, но всё же: при очистке лучше откатить stack к заводским, т.е. снова сделать его размер маленьким и очистить лишнюю память |
||
| size = 10; | ||
| delete[] mas; | ||
| mas = tmp; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,42 @@ | ||
| // реализация пользовательского приложения | ||
|
|
||
| #include "arithmetic.h" | ||
| int main() | ||
| { | ||
| return 0; | ||
| std::string str; | ||
| while (true) { | ||
| try { | ||
| int fl = 0; | ||
| std::cout << "Enter a string what you want to count or enter \"end\" to end work with program \n"; | ||
| std::cout << "Availble math fuctions:sin, cos, tan, cot, exp, log \n"; | ||
| std::cout << "After functions you need to enter \'(\'\n"; | ||
| std::cout << "You can enter an unlimited number of variables. Available variable names: x, x#any set of numbers#\n"; | ||
| std::getline(std::cin, str); | ||
| if (str == "end") break; | ||
| if (str == "") { | ||
| system("cls"); | ||
| continue; | ||
| } | ||
| for (int i = 0; i < str.size(); i++) if (str[i] == 'x') fl = 1; | ||
| TPostfix solution(str); | ||
| system("cls"); | ||
| do { | ||
| std::cout << str << '\n'; | ||
| std::cout << "Res: " << solution.count() << "\n\n"; | ||
| if (fl) { | ||
| do { | ||
| std::cout << "Enter \'1\' if you want to recalculate an expression with new variables or enter \'0\' to enter new expression: "; | ||
| std::cin >> fl; | ||
| if (fl != 0 && fl != 1) std::cout << "This option does not exist\n"; | ||
| } while (fl != 0 && fl != 1); | ||
| system("cls"); | ||
| } | ||
| } | ||
| while (fl); | ||
| } | ||
| catch (std::exception& e) { | ||
| system("cls"); | ||
| std::cout << str << '\n'; | ||
| std::cout << e.what() << "\n\n"; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем здесь прямое указание поля имён TPostfix::? Аналогично ниже
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мда, поправил