Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. #include<conio.h>
  2. #include<iostream>
  3. #include<Windows.h>
  4. using namespace std;
  5. void coordinates(int x, int y)
  6. {
  7. COORD gt = { x, y };
  8. HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE);
  9. SetConsoleCursorPosition(hnd, gt);
  10. }
  11. void graphicScreenSaver() {
  12. system("cls");
  13. 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;
  14. float a = 0, a1 = 0, a2 = 0, a3 = 0;
  15. HWND hwnd = GetConsoleWindow();
  16. HDC dc = GetDC(hwnd);
  17. RECT window = {};
  18. HBRUSH brush;
  19. brush = CreateSolidBrush(RGB(255, 0, 0));
  20. HBRUSH brush1;
  21. brush1 = CreateSolidBrush(RGB(255, 255, 0));
  22. HBRUSH brush2;
  23. brush2 = CreateSolidBrush(RGB(0, 255, 0));
  24. HBRUSH brush3;
  25. brush3 = CreateSolidBrush(RGB(255, 0, 255));
  26. RECT WinCoord = {};
  27. GetWindowRect(hwnd, &WinCoord);
  28. RECT rect;
  29. GetClientRect(hwnd, &rect);
  30. while (a < 25) {
  31. SelectObject(dc, brush);
  32. Sleep(5);
  33. x1 = 250 + 100 * sin(2 * a);
  34. y1 = 165 + 100 * sin(2 * a);
  35. a += 0.01;
  36. Ellipse(dc, x1, y1, x1 + 30, y1 + 30);
  37. SelectObject(dc, brush1);
  38. x = 250 + 100 * sin(2 * a);
  39. y = 165 - 100 * sin(2 * a);
  40. a1 += 0.01;
  41. Ellipse(dc, x, y, x + 30, y + 30);
  42. SelectObject(dc, brush2);
  43. x2 = 250 - 100 * sin(2 * a2);
  44. y2 = 165 - 100 * sin(2 * a2);
  45. a2 += 0.01;
  46. Ellipse(dc, x2, y2, x2 + 30, y2 + 30);
  47. SelectObject(dc, brush3);
  48. x3 = 250 - 100 * sin(2 * a3);
  49. y3 = 165 + 100 * sin(2 * a3);
  50. a3 += 0.01;
  51. Ellipse(dc, x3, y3, x3 + 30, y3 + 30);
  52. }
  53. ReleaseDC(hwnd, dc);
  54. cin.get();
  55. system("pause");
  56. }
  57. float q(float x)
  58. {
  59. return 2 * pow(pow(x, 2) + 1, 1/3) - 3 * sin(x) - 5;
  60. }
  61. void equation() {
  62. system("cls");
  63. float a = 7.15, b = 12.7, c, e = 0.001;
  64. while (b - a > e)
  65. {
  66. c = (a + b) / 2;
  67. if (q(b) * q(c) < 0)
  68. a = c;
  69. else
  70. b = c;
  71. }
  72. coordinates(5, 10);
  73. cout << "Решение уравнения методом половинного деления на интервале [7.15; 12.7]";
  74. coordinates(5, 11);
  75. cout << "2 * pow(pow(x, 2) + 1, 1/3) - 3 * sin(x) = 5 равен: " << c;
  76. system("pause >nul");
  77. }
  78. void graphs() {
  79. system("mode 80, 25");
  80. cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
  81. cout << endl << endl << endl << " ";
  82. float x;
  83. HDC hDC = GetDC(GetConsoleWindow());
  84. HPEN Pen1, Pen2, Pen3;
  85. Pen1 = CreatePen(PS_SOLID, 3, RGB(192, 192, 192));
  86. SelectObject(hDC, Pen1);
  87. MoveToEx(hDC, 0, 200, NULL);
  88. LineTo(hDC, 555, 200);
  89. MoveToEx(hDC, 245, 0, NULL);
  90. LineTo(hDC, 245, 400);
  91.  
  92. MoveToEx(hDC, 540, 210, NULL);
  93. LineTo(hDC, 555, 200);
  94. LineTo(hDC, 540, 190);
  95. MoveToEx(hDC, 230, 10, NULL);
  96. LineTo(hDC, 245, 0);
  97. LineTo(hDC, 260, 10);
  98.  
  99. SetBkColor(hDC, RGB(0, 0, 0));
  100. SetTextColor(hDC, RGB(192, 192, 192));
  101. TextOutA(hDC, 210, 5, "Y", 1);
  102. TextOutA(hDC, 545, 220, "X", 1);
  103. for (x = -3.14; x <= 3.14; x += 0.01f)
  104. {
  105. Sleep(4);
  106. Pen2 = CreatePen(PS_SOLID, 3, RGB(128, 0, 0));
  107. SelectObject(hDC, Pen2);
  108. MoveToEx(hDC, 50 * x + 305, -40 * (2 - cos(x)) + 200, NULL);
  109. LineTo(hDC, 50 * x + 305, -40 * (2 - cos(x)) + 200);
  110. Pen3 = CreatePen(PS_SOLID, 3, RGB(0, 128, 0));
  111. SelectObject(hDC, Pen3);
  112. MoveToEx(hDC, 50 * x + 305, -40 * sqrt(x + 4) + 200, NULL);
  113. LineTo(hDC, 50 * x + 305, -40 * sqrt(x + 4) + 200);
  114. }
  115. SelectObject(hDC, Pen1);
  116. {
  117. SetBkColor(hDC, RGB(0, 0, 0));
  118. SetTextColor(hDC, RGB(192, 192, 192));
  119. TextOutA(hDC, 80, 55, "y(f)=2-cos(x)", 13);
  120. SetBkColor(hDC, RGB(0, 0, 0));
  121. SetTextColor(hDC, RGB(192, 192, 192));
  122. TextOutA(hDC, 80, 125, "y(f)=sqrt(x+4)", 20);
  123. }
  124. cin.get();
  125. system("pause");
  126. system("cls");
  127. }
  128. float z(float x)
  129. {
  130. return pow((x), 2) * exp(-x);
  131. }
  132. float quad_integral(float a, float b, int n, float(*f)(float))
  133. {
  134. float h, res, x;
  135. int i;
  136. h = (b - a) / n;
  137. res = 0;
  138. for (i = 0; i < n - 1; i++)
  139. {
  140. x = a + i * h;
  141. res = res + f(x);
  142. }
  143. res = h * res;
  144. return res;
  145. }
  146. void integral() {
  147. system("cls");
  148. float i;
  149. float a, b, s;
  150. coordinates(20, 7);
  151. cout << "Введите интервал [a,b]";
  152. coordinates(20, 8);
  153. cout << "a = ";
  154. cin >> a;
  155. coordinates(20, 9);
  156. cout << "b = ";
  157. cin >> b;
  158. coordinates(20, 10);
  159. cout << "Введите число разбиений n > 50 ";
  160. cin >> s;
  161. i = quad_integral(a, b, s, z);
  162. coordinates(20, 11);
  163. cout << "Интеграл равен " << i;
  164. system("pause >nul");
  165. }
  166. float maxf(float* m, int N)
  167. {
  168. float max;
  169. max = m[0];
  170. for (int i = 1; i < N; i++)
  171. {
  172. if (m[i] > max)
  173. max = m[i];
  174. }
  175. return max;
  176. }
  177. float minf(float* m, int N)
  178. {
  179. float min;
  180. min = m[0];
  181. for (int i = 1; i < N; i++)
  182. {
  183. if (m[i] < min)
  184. min = m[i];
  185. }
  186. return min;
  187. }
  188. void table() {
  189. system("cls");
  190. float F1[20], F2[20];
  191. float a = -3.14, b = 3.14;
  192. float f1, f2, x, dx;
  193. int n = 16;
  194. dx = (abs(b) + abs(a)) / (n - 1);
  195. x = a;
  196. coordinates(4, 2);
  197. cout << "| I | X | F1 | F2 |" << endl;
  198. coordinates(4, 3);
  199. cout << "|____|_________|________|_________|";
  200. for (int i = 0; i < n; i++)
  201. {
  202. f1 = (2 - cos(x));
  203. f2 = sqrt(x + 4);
  204. F1[i] = f1;
  205. F2[i] = f2;
  206. coordinates(4, 4 + i);
  207. printf("| %3d| %8.4f|%8.4f| %8.4f|\n", i + 1, x, F1[i], F2[i]);
  208. x += dx;
  209. }
  210. coordinates(45, 9);
  211. cout << "Минимальное F1 = " << minf(F1, n);
  212. coordinates(45, 10);
  213. cout << "Минимальное F2 = " << minf(F2, n);
  214. coordinates(45, 12);
  215. cout << "Максимальное F1 = " << maxf(F1, n);
  216. coordinates(45, 13);
  217. cout << "Максимальное F2 = " << maxf(F2, n);
  218. system("pause >nul");
  219. }
  220. void aboutTheAuthor() {
  221. system("cls");
  222. coordinates(20, 7);
  223. cout << "Расчетно - графическая работа выполнена";
  224. coordinates(20, 8);
  225. cout << "Студентом группы ПИН-191";
  226. coordinates(20, 9);
  227. cout << "Пешехоновым Никитой Алексеевичем";
  228. coordinates(20, 10);
  229. cout << "ОмГТУ ФИТиКС АСОИУ 2019";
  230. system("pause >nul");
  231. }
  232. void menu() {
  233. do {
  234. int key = 0;
  235. int code;
  236. do {
  237. system("cls");
  238. key = (key + 7) % 7;
  239. coordinates(30, 5);
  240. if (key == 0)
  241. {
  242. cout << ">Графическая заставка";
  243. }
  244. else
  245. {
  246. cout << " Графическая заставка";
  247. }
  248. coordinates(30, 7);
  249. if (key == 1)
  250. {
  251. cout << ">Уравнение";
  252. }
  253. else
  254. {
  255. cout << " Уравнение";
  256. }
  257. coordinates(30, 9);
  258. if (key == 2)
  259. {
  260. cout << ">Графики";
  261. }
  262.  
  263. else
  264. {
  265.  
  266. cout << " Графики";
  267. }
  268. coordinates(30, 11);
  269. if (key == 3)
  270. {
  271. cout << ">Интеграл";
  272. }
  273. else
  274. {
  275. cout << " Интеграл";
  276. }
  277. coordinates(30, 13);
  278. if (key == 4)
  279. {
  280. cout << ">Таблица";
  281. }
  282. else
  283. {
  284. cout << " Таблица";
  285. }
  286. coordinates(30, 15);
  287. if (key == 5)
  288. {
  289. cout << ">Об авторе";
  290. }
  291. else
  292. {
  293. cout << " Об авторе";
  294. }
  295. coordinates(30, 17);
  296. if (key == 6)
  297. {
  298. cout << ">Выход";
  299. }
  300. else
  301. {
  302. cout << " Выход";
  303. }
  304. code = _getch();
  305. if (code == 224)
  306. {
  307. code = _getch();
  308. if (code == 80) key++;
  309. if (code == 72) key--;
  310. }
  311. if (key > 7) key = 0;
  312. if (key < 0) key = 6;
  313. } while (code != 13);
  314. if (key == 0) graphicScreenSaver();
  315. if (key == 1) equation();
  316. if (key == 2) graphs();
  317. if (key == 3) integral();
  318. if (key == 4) table();
  319. if (key == 5) aboutTheAuthor();
  320. if (key == 6) exit(0);
  321. } while (true);
  322. }
  323. void main() {
  324. system("mode 80, 25");
  325. setlocale(LC_ALL, "rus");
  326. menu();
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement