Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<conio.h>
- #include<iostream>
- #include<Windows.h>
- using namespace std;
- void coordinates(int x, int y)
- {
- COORD gt = { x, y };
- HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hnd, gt);
- }
- void graphicScreenSaver() {
- system("cls");
- int x = 0, y = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, a4 = 0, y4 = 0, m = 0;
- float a = 0, a1 = 0, a2 = 0, a3 = 0;
- HWND hwnd = GetConsoleWindow();
- HDC dc = GetDC(hwnd);
- RECT window = {};
- HBRUSH brush;
- brush = CreateSolidBrush(RGB(255, 0, 0));
- HBRUSH brush1;
- brush1 = CreateSolidBrush(RGB(255, 255, 0));
- HBRUSH brush2;
- brush2 = CreateSolidBrush(RGB(0, 255, 0));
- HBRUSH brush3;
- brush3 = CreateSolidBrush(RGB(255, 0, 255));
- RECT WinCoord = {};
- GetWindowRect(hwnd, &WinCoord);
- RECT rect;
- GetClientRect(hwnd, &rect);
- while (a < 25) {
- SelectObject(dc, brush);
- Sleep(5);
- x1 = 250 + 100 * sin(2 * a);
- y1 = 165 + 100 * sin(2 * a);
- a += 0.01;
- Ellipse(dc, x1, y1, x1 + 30, y1 + 30);
- SelectObject(dc, brush1);
- x = 250 + 100 * sin(2 * a);
- y = 165 - 100 * sin(2 * a);
- a1 += 0.01;
- Ellipse(dc, x, y, x + 30, y + 30);
- SelectObject(dc, brush2);
- x2 = 250 - 100 * sin(2 * a2);
- y2 = 165 - 100 * sin(2 * a2);
- a2 += 0.01;
- Ellipse(dc, x2, y2, x2 + 30, y2 + 30);
- SelectObject(dc, brush3);
- x3 = 250 - 100 * sin(2 * a3);
- y3 = 165 + 100 * sin(2 * a3);
- a3 += 0.01;
- Ellipse(dc, x3, y3, x3 + 30, y3 + 30);
- }
- ReleaseDC(hwnd, dc);
- cin.get();
- system("pause");
- }
- float q(float x)
- {
- return 2 * pow(pow(x, 2) + 1, 1/3) - 3 * sin(x) - 5;
- }
- void equation() {
- system("cls");
- float a = 7.15, b = 12.7, c, e = 0.001;
- while (b - a > e)
- {
- c = (a + b) / 2;
- if (q(b) * q(c) < 0)
- a = c;
- else
- b = c;
- }
- coordinates(5, 10);
- cout << "Решение уравнения методом половинного деления на интервале [7.15; 12.7]";
- coordinates(5, 11);
- cout << "2 * pow(pow(x, 2) + 1, 1/3) - 3 * sin(x) = 5 равен: " << c;
- system("pause >nul");
- }
- void graphs() {
- system("mode 80, 25");
- cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
- cout << endl << endl << endl << " ";
- float x;
- HDC hDC = GetDC(GetConsoleWindow());
- HPEN Pen1, Pen2, Pen3;
- Pen1 = CreatePen(PS_SOLID, 3, RGB(192, 192, 192));
- SelectObject(hDC, Pen1);
- MoveToEx(hDC, 0, 200, NULL);
- LineTo(hDC, 555, 200);
- MoveToEx(hDC, 245, 0, NULL);
- LineTo(hDC, 245, 400);
- MoveToEx(hDC, 540, 210, NULL);
- LineTo(hDC, 555, 200);
- LineTo(hDC, 540, 190);
- MoveToEx(hDC, 230, 10, NULL);
- LineTo(hDC, 245, 0);
- LineTo(hDC, 260, 10);
- SetBkColor(hDC, RGB(0, 0, 0));
- SetTextColor(hDC, RGB(192, 192, 192));
- TextOutA(hDC, 210, 5, "Y", 1);
- TextOutA(hDC, 545, 220, "X", 1);
- for (x = -3.14; x <= 3.14; x += 0.01f)
- {
- Sleep(4);
- Pen2 = CreatePen(PS_SOLID, 3, RGB(128, 0, 0));
- SelectObject(hDC, Pen2);
- MoveToEx(hDC, 50 * x + 305, -40 * (2 - cos(x)) + 200, NULL);
- LineTo(hDC, 50 * x + 305, -40 * (2 - cos(x)) + 200);
- Pen3 = CreatePen(PS_SOLID, 3, RGB(0, 128, 0));
- SelectObject(hDC, Pen3);
- MoveToEx(hDC, 50 * x + 305, -40 * sqrt(x + 4) + 200, NULL);
- LineTo(hDC, 50 * x + 305, -40 * sqrt(x + 4) + 200);
- }
- SelectObject(hDC, Pen1);
- {
- SetBkColor(hDC, RGB(0, 0, 0));
- SetTextColor(hDC, RGB(192, 192, 192));
- TextOutA(hDC, 80, 55, "y(f)=2-cos(x)", 13);
- SetBkColor(hDC, RGB(0, 0, 0));
- SetTextColor(hDC, RGB(192, 192, 192));
- TextOutA(hDC, 80, 125, "y(f)=sqrt(x+4)", 20);
- }
- cin.get();
- system("pause");
- system("cls");
- }
- float z(float x)
- {
- return pow((x), 2) * exp(-x);
- }
- float quad_integral(float a, float b, int n, float(*f)(float))
- {
- float h, res, x;
- int i;
- h = (b - a) / n;
- res = 0;
- for (i = 0; i < n - 1; i++)
- {
- x = a + i * h;
- res = res + f(x);
- }
- res = h * res;
- return res;
- }
- void integral() {
- system("cls");
- float i;
- float a, b, s;
- coordinates(20, 7);
- cout << "Введите интервал [a,b]";
- coordinates(20, 8);
- cout << "a = ";
- cin >> a;
- coordinates(20, 9);
- cout << "b = ";
- cin >> b;
- coordinates(20, 10);
- cout << "Введите число разбиений n > 50 ";
- cin >> s;
- i = quad_integral(a, b, s, z);
- coordinates(20, 11);
- cout << "Интеграл равен " << i;
- system("pause >nul");
- }
- float maxf(float* m, int N)
- {
- float max;
- max = m[0];
- for (int i = 1; i < N; i++)
- {
- if (m[i] > max)
- max = m[i];
- }
- return max;
- }
- float minf(float* m, int N)
- {
- float min;
- min = m[0];
- for (int i = 1; i < N; i++)
- {
- if (m[i] < min)
- min = m[i];
- }
- return min;
- }
- void table() {
- system("cls");
- float F1[20], F2[20];
- float a = -3.14, b = 3.14;
- float f1, f2, x, dx;
- int n = 16;
- dx = (abs(b) + abs(a)) / (n - 1);
- x = a;
- coordinates(4, 2);
- cout << "| I | X | F1 | F2 |" << endl;
- coordinates(4, 3);
- cout << "|____|_________|________|_________|";
- for (int i = 0; i < n; i++)
- {
- f1 = (2 - cos(x));
- f2 = sqrt(x + 4);
- F1[i] = f1;
- F2[i] = f2;
- coordinates(4, 4 + i);
- printf("| %3d| %8.4f|%8.4f| %8.4f|\n", i + 1, x, F1[i], F2[i]);
- x += dx;
- }
- coordinates(45, 9);
- cout << "Минимальное F1 = " << minf(F1, n);
- coordinates(45, 10);
- cout << "Минимальное F2 = " << minf(F2, n);
- coordinates(45, 12);
- cout << "Максимальное F1 = " << maxf(F1, n);
- coordinates(45, 13);
- cout << "Максимальное F2 = " << maxf(F2, n);
- system("pause >nul");
- }
- void aboutTheAuthor() {
- system("cls");
- coordinates(20, 7);
- cout << "Расчетно - графическая работа выполнена";
- coordinates(20, 8);
- cout << "Студентом группы ПИН-191";
- coordinates(20, 9);
- cout << "Пешехоновым Никитой Алексеевичем";
- coordinates(20, 10);
- cout << "ОмГТУ ФИТиКС АСОИУ 2019";
- system("pause >nul");
- }
- void menu() {
- do {
- int key = 0;
- int code;
- do {
- system("cls");
- key = (key + 7) % 7;
- coordinates(30, 5);
- if (key == 0)
- {
- cout << ">Графическая заставка";
- }
- else
- {
- cout << " Графическая заставка";
- }
- coordinates(30, 7);
- if (key == 1)
- {
- cout << ">Уравнение";
- }
- else
- {
- cout << " Уравнение";
- }
- coordinates(30, 9);
- if (key == 2)
- {
- cout << ">Графики";
- }
- else
- {
- cout << " Графики";
- }
- coordinates(30, 11);
- if (key == 3)
- {
- cout << ">Интеграл";
- }
- else
- {
- cout << " Интеграл";
- }
- coordinates(30, 13);
- if (key == 4)
- {
- cout << ">Таблица";
- }
- else
- {
- cout << " Таблица";
- }
- coordinates(30, 15);
- if (key == 5)
- {
- cout << ">Об авторе";
- }
- else
- {
- cout << " Об авторе";
- }
- coordinates(30, 17);
- if (key == 6)
- {
- cout << ">Выход";
- }
- else
- {
- cout << " Выход";
- }
- code = _getch();
- if (code == 224)
- {
- code = _getch();
- if (code == 80) key++;
- if (code == 72) key--;
- }
- if (key > 7) key = 0;
- if (key < 0) key = 6;
- } while (code != 13);
- if (key == 0) graphicScreenSaver();
- if (key == 1) equation();
- if (key == 2) graphs();
- if (key == 3) integral();
- if (key == 4) table();
- if (key == 5) aboutTheAuthor();
- if (key == 6) exit(0);
- } while (true);
- }
- void main() {
- system("mode 80, 25");
- setlocale(LC_ALL, "rus");
- menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement