Лабораторная работа по "Информатике"
Автор: Егор Синичкин • Апрель 30, 2019 • Лабораторная работа • 2,502 Слов (11 Страниц) • 450 Просмотры
/* |
=========================================================== |
Лабораторная работа 1 |
Выполнил: Синичкин Е.А. |
=========================================================== |
*/ |
#include |
#include |
#include |
#include |
double f(double, double ); |
int main() |
{ |
using namespace std; |
setlocale(0, "rus"); |
double x_min {0.}, |
x_max {10.}; |
size_t number_of_points {30}; |
double a {3.}; |
double dx = (x_max - x_min) / (number_of_points - 1.); |
const double Eps {1e-10}, |
Inf {1. / 0.}; |
double y_min {Inf}, |
y_max { -Inf}, |
y {}; |
for (double x {x_min}; x < x_max + Eps; x += dx) { |
y = f(x, a); |
if (y_min > y && y != -Inf) |
y_min = y; |
if (y_max < y) |
y_max = y; |
} |
string tire (27, '='); |
tire += "\n"; |
cout << "\n Tаблица y = y(x,a), a = " << a << endl |
<< tire |
<< " x y(x) \n" |
<< tire; |
typedef std::string::size_type sst; |
const sst Size = 41; |
string line(Size, ' '); |
for (double x {x_min}; x < x_max + Eps; x += dx) { |
double y = f(x, a); |
sst iy {}; |
if (y != -Inf) |
iy = floor(Eps + (Size - 1.) |
* (y - y_min) |
/ (y_max - y_min)); |
int iy0 = floor(Eps + (Size - 1.) |
* (0. - y_min) |
/ (y_max - y_min)); |
if (0 <= iy0 && iy0 < int(Size)) |
line[iy0] = '|'; |
line[iy] = y != -Inf ? 'Ж' : '?'; |
cout << fixed << setprecision(2) |
<< setw(10) << x << " " |
<< setw(10) << y << " " |
<< line << endl; |
line[iy] = ' '; |
} |
cout << tire; |
return 0; |
} |
auto f(double x, double a) -> double { |
const double Eps {1e-10}; |
double y {}; |
if (a * x > 1) |
y = cos(a + x); |
else if (a * x <= -0,5) |
y = tan(a * x); |
else |
y = sin(a - x); |
return y; |
} |
/* |
Tаблица y = y(x,a), a = 3 |
=========================== |
x y(x) |
=========================== |
0.00 0.00 . |
0.34 -0.98 . | |
0.69 -0.85 . | |
1.03 -0.63 . | |
1.38 -0.33 . | |
1.72 0.01 |. |
2.07 0.35 | . |
2.41 0.65 | . |
2.76 0.87 | . |
3.10 0.98 | . |
3.45 0.99 | . |
3.79 0.87 | . |
4.14 0.66 | . |
4.48 0.36 | . |
4.83 0.03 |. |
5.17 -0.31 . | |
5.52 -0.62 . | |
5.86 -0.85 . | |
6.21 -0.98 . | |
6.55 -0.99 . | |
6.90 -0.89 . | |
7.24 -0.68 . | |
7.59 -0.40 . | |
7.93 -0.06 .| |
8.28 0.28 | . |
8.62 0.59 | . |
8.97 0.82 | . |
9.31 0.97 | . |
9.66 1.00 | . |
10.00 0.91 | . |
=========================== |
*/ |
...