Initial commit

This commit is contained in:
2026-02-25 18:10:23 +03:00
commit de343e911e
11 changed files with 421 additions and 0 deletions

106
src/lab3.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include <labs.h>
using IterationF = function<double(int i)>;
using LoopF = function<double(int min, int max, IterationF &f)>;
double iteration(double x, double i);
double mp_for(int min, int max, IterationF &f);
double mp_while(int min, int max, IterationF &f);
double mp_do_while(int min, int max, IterationF &f);
void lab3()
{
LoopF loopF;
IterationF f;
double x, y;
int n;
char c;
cout << "Enter x: ";
cin >> x;
f = [=](int i)
{ return iteration(x, i); };
cout
<< "Enter N: ";
cin >> n;
loop // while (1)
{
cout << endl
<< "Select mode (F/W/D): ";
cin >> c;
switch (c)
{
case 'f':
case 'F':
loopF = mp_for;
break;
case 'w':
case 'W':
loopF = mp_while;
break;
case 'd':
case 'D':
loopF = mp_do_while;
break;
default:
cout << "Invalid mode, exiting!" << endl;
return;
}
y = pow(loopF(1, n, f), 1.2 * x);
cout << "Result y(" << x << ") = " << y << endl;
}
}
double iteration(double x, double i)
{
return 2.8 * pow(x, 4.5) + cbrt(i);
}
double mp_for(int min, int max, IterationF &f)
{
double res = 1.0;
for (int i = min; i <= max; i++)
{
res += f(i);
}
return res;
}
double mp_while(int min, int max, IterationF &f)
{
double res = 1.0;
int i = min;
while (i <= max)
{
res += f(i);
i++;
}
return res;
}
double mp_do_while(int min, int max, IterationF &f)
{
double res = 1.0;
if (min >= max)
return res;
int i = min;
do
{
res += f(i);
i++;
} while (i <= max);
return res;
}