Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. //Спецификация
  2. //
  3. #include <iostream>
  4. #include <cmath>
  5. using namespace std;
  6. const char* ERROR_X_1 = "Ошибка: переменная должна быть числом.";
  7. const char* ERROR_X_2 = "Ошибка: переменная должна лежать в интервале от -1 до 1.";
  8. const char* ERROR_NUMBER = "Ошибка: должно быть число.";
  9. const char* ERROR_NUM = "Ошибка: максимальное значение суммы не может быть меньше 2.";
  10.  
  11. void rost(int numberMax, double x, double p, double n, bool q, int f, int count)
  12. {
  13. for (int i = 0; i < numberMax; i++)
  14. {
  15. p = p * x * x;
  16. if (q == false)
  17. {
  18. n = n - p / f;
  19. q = true;
  20.  
  21. }
  22. else
  23. {
  24. n = n + p / f;
  25. q = false;
  26. }
  27. f = f * (count + 1) * (count + 2);
  28. count += 2;
  29.  
  30. }
  31. }
  32. int main()
  33. {
  34. try
  35. {
  36. setlocale(LC_ALL, "rus");
  37. int f = 2;
  38. int count = 2;
  39. double n = 1;
  40. double absError = 0.000001;
  41. double t = 0.001;
  42. double p = 1.0;
  43. bool q = false;
  44. double x;
  45. int numberMax;
  46. cout << "Введите максимальное число слагаемых: ";
  47. cin >> numberMax;
  48. if (!cin)
  49. {
  50. throw ERROR_NUMBER;
  51. return -1;
  52. }
  53. if (numberMax < 2)
  54. {
  55. throw ERROR_NUM;
  56. return -1;
  57. }
  58. cout << "Введите переменную: ";
  59. cin >> x;
  60. if (!cin)
  61. {
  62. throw ERROR_X_1;
  63. return -1;
  64. }
  65. if (x > 1 or x < -1)
  66. {
  67. throw ERROR_X_2;
  68. return -1;
  69. }
  70. Cos(numberMax, x, p, n, q, f, count);
  71. cout << cos(x) << " " << n << endl;
  72.  
  73. }
  74. catch (const char* error)
  75. {
  76. cerr << error << endl;
  77. return 0;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement