-
Notifications
You must be signed in to change notification settings - Fork 33
Гасилова Мария #32
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?
Гасилова Мария #32
Changes from all commits
8c76916
8dc72fd
21379dc
0854b6a
2a10deb
fab3e58
0f0f089
593d8b6
ec5ca79
3d9c082
f49e879
cc769d3
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,6 +1,43 @@ | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
| #include <iomanip> | ||
|
|
||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (a == 0) | ||
| { | ||
|
Contributor
Author
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. оформление if должно быть в одном стиле |
||
| if (b == 0) { | ||
| if (c == 0) { | ||
| std::cout << "infinite solutions"; | ||
| } | ||
| else { | ||
| std::cout << "no solutions"; | ||
|
Contributor
Author
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. лучше избавиться от вложженности и для каждого особого случая сделать короткую ветвь с return будет лучше читаться |
||
| } | ||
| } | ||
| else { | ||
| double sol = -static_cast<double>(c) / static_cast<double>(b); | ||
| std::cout << std::setprecision(6) << sol; | ||
| } | ||
| } | ||
| else { | ||
| // ���������� ��������� | ||
|
Contributor
Author
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. Комментарии не видны, вероятно проблемы с кодировкой, нужно для исходного файла задать UTF-8, тогда в репозитории буудет корректно отражаться |
||
| double discriminant = static_cast<double>(b) * static_cast<double>(b) - 4.0 * static_cast<double>(a) * static_cast<double>(c); | ||
|
Contributor
Author
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. лишние касты, достаточно у одного |
||
| if (discriminant < 0) { | ||
| std::cout << "no solutions"; | ||
| } | ||
| else if (discriminant == 0) { | ||
| double sol = -b / (2.0 * a); | ||
| std::cout << std::setprecision(6) << sol; | ||
| } | ||
| else { | ||
| double sqr = std::sqrt(discriminant); | ||
| double x1 = (-b - sqr) / (2.0 * a); | ||
| double x2 = (-b + sqr) / (2.0 * a); | ||
| // ������������ ������� x1 < x2 | ||
| if (x1 > x2) { | ||
| std::swap(x1, x2); | ||
| } | ||
| std::cout << std::setprecision(6) << x1 << " " << x2; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,18 @@ | ||
| #include <cstdef> | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
|
|
||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (size == 0 || values == nullptr) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| double sumofSquares = 0.0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| sumofSquares += values[i] * values[i]; | ||
| } | ||
|
|
||
| double meanofSquares = sumofSquares / static_cast<double>(size); | ||
|
Contributor
Author
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 к double не нужно он приведется неявно поскольку sumofSquares имеет тип double |
||
| return std::sqrt(meanofSquares); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,18 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| double ApplyOperations(double a, double b /* other arguments */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| double ApplyOperations(double a, double b, double (**funks)(double, double), size_t size) { | ||
|
Contributor
Author
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. funcs тогда, от слова functions, имена лучше не русифицирвоать, + нагляднее был бы массив указателей на функцию чем указатель на указатель на функцию |
||
| if (funks == nullptr || size == 0) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| double Sum = 0.0; | ||
|
|
||
| for (size_t i = 0; i < size; ++i) { | ||
| if (funks[i] != nullptr) { | ||
| Sum += funks[i](a, b); | ||
| } | ||
| } | ||
|
|
||
| return Sum; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| int* FindLastElement(int* begin,int* end, bool (*predicate)(int)) { | ||
|
Contributor
Author
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. пробел после запятой пропал, + функция должна принимать и возвращать указатели на константу, так как функция не изменяет элементы и требований к возможности изменению по возвращаемому указателю нет |
||
| if (begin == nullptr || end == nullptr || begin > end) { | ||
| return end; | ||
| } | ||
| for (int* p = end - 1; p >= begin; --p) { | ||
| if (predicate(*p)) { | ||
| return p; | ||
| } | ||
| } | ||
| return end; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| void SwapPtr(/* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void SwapPtr(int* a, int* b) { | ||
| int* c = a; | ||
| a = b; | ||
| b = c; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| #include <stdexcept> | ||
| #include <vector> | ||
|
|
||
|
|
||
| /* return_type */ Filter(/* args */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void Filter(std::vector<int>& v, bool (*predicate)(int)) { | ||
| size_t ind = 0; | ||
| for (size_t i = 0; i < v.size(); ++i) { | ||
| if (predicate(v[i])) { | ||
| v[ind] = v[i]; | ||
| ++ind; | ||
| } | ||
| } | ||
| v.resize(ind); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| #include <stdexcept> | ||
| #include <vector> | ||
|
|
||
|
|
||
| /* return_type */ FindAll(/* args */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::vector<size_t> FindAll(const std::vector<int>& container, bool (*predicate)(int)) { | ||
| std::vector<size_t> cont2; | ||
|
Contributor
Author
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. pos - позиции было бы лучше для навания |
||
|
|
||
| for (size_t i = 0; i < container.size(); ++i) { | ||
| if (predicate(container[i])) { | ||
| cont2.push_back(i); | ||
| } | ||
| } | ||
|
|
||
| return cont2; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,26 @@ | ||
| #include <stdexcept> | ||
| #include <vector> | ||
|
|
||
| /* return_type */ Unique(/* args */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::vector<int> Unique(const std::vector<int>& v) { | ||
| if (v.empty()) { | ||
| return {}; | ||
| } | ||
| size_t uniq = 1; | ||
| for (size_t i = 1; i < v.size(); ++i) { | ||
| if (v[i] != v[i - 1]) { | ||
| ++uniq; | ||
| } | ||
| } | ||
| std::vector<int> res(uniq); | ||
| res[0] = v[0]; | ||
|
|
||
| size_t index = 1; | ||
| for (size_t i = 1; i < v.size(); ++i) { | ||
| if (v[i] != v[i - 1]) { | ||
| res[index] = v[i]; | ||
| ++index; | ||
| } | ||
| } | ||
|
|
||
| return res; | ||
| } |
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.
Лишний каст, второй операнд не следует приводить явно, так как он бы преобразовался с помощью неявного каста. Принято использовать такую возможность и не писать явный каст самостоятельно второй раз