Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Задание 1.
- */
- #include <iomanip>
- #include <iostream>
- #include <functional>
- using namespace std;
- int main() {
- double x_first;
- double x_last;
- double dx;
- double a;
- double b;
- double c;
- cin >> x_first >> x_last >> dx >> a >> b >> c;
- double result = 0;
- bool is_ok = true;
- auto function1 = [&a, &b, &c, &result, &is_ok](const double& x) {
- if (b < 0) {
- cout << "Cant get sqrt froom negative number\n";
- is_ok = false;
- return;
- }
- result = -1 * (a * x * x) - sqrt(b);
- };
- auto function2 = [&a, &b, &c, &result, &is_ok](const double& x) {
- if (c == 0 || x == 0) {
- cout << "Cant devide by 0\n";
- is_ok = false;
- return;
- }
- result = (x - a) / (c * x);
- };
- auto function3 = [&a, &b, &c, &result, &is_ok](const double& x) {
- if (b == 0) {
- cout << "Cant divide by 0\n";
- is_ok = false;
- return;
- }
- result = -1 * x / b;
- };
- vector<function<void(double)>> functions = { function1, function2, function3 };
- size_t foo_idx = 2;
- if (c < 0 && a) {
- foo_idx = 0;
- }
- if (c > 5 && !a) {
- foo_idx = 1;
- }
- auto foo = functions[foo_idx];
- const int PRECISION = 15;
- size_t iterations_count = (x_last - x_first) / dx + 1;
- for (size_t i = 0; i < iterations_count; ++i) {
- result = 0;
- is_ok = true;
- foo(x_first + i * dx);
- if (is_ok) {
- cout << fixed << setprecision(PRECISION) << result << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement