Advertisement
Tark_Wight

Untitled

Mar 23rd, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class Tabul {
  8. private:
  9. double step; // Параметр для функций
  10. double start,
  11. end;
  12.  
  13. void sinX() {
  14. cout << "Введите диапазон [-1, 1]: ";
  15. cin >> start >> end;
  16. std::cout << "Введите шаг: ";
  17. std::cin >> step;
  18. std::cout << '\n';
  19. for (double x = start; x <= end; x += step) {
  20. double y = sin(x);
  21. cout << "sin(" << x << ") = " << y << '\n';
  22. }
  23. std::cout << '\n';
  24. }
  25.  
  26. void cosX() {
  27. cout << "Введите диапазон [0, 1]: ";
  28. cin >> start >> end;
  29. std::cout << "Введите шаг: ";
  30. std::cin >> step;
  31. std::cout << '\n';
  32. for (double x = start; x <= end; x += step) {
  33. double y = cos(x);
  34. cout << "cos(" << x << ") = " << y << '\n';
  35. }
  36. std::cout << '\n';
  37. }
  38.  
  39. void arctgX() {
  40. cout << "Введите диапазон [-2 , 2]: ";
  41. cin >> start >> end;
  42. std::cout << "Введите шаг: ";
  43. std::cin >> step;
  44. std::cout << '\n';
  45. for (double x = start; x <= end; x += step) {
  46. double y = atan(x);
  47. cout << "arctg(" << x << ") = " << y << '\n';
  48. }
  49. std::cout << '\n';
  50. }
  51.  
  52. void arcctgX(){
  53. cout << "Введите диапазон [0, 1]: ";
  54. cin >> start >> end;
  55. std::cout << "Введите шаг: ";
  56. std::cin >> step;
  57. std::cout << '\n';
  58. for (double x = start; x <= end; x += step) {
  59. double y = atan(1/x);
  60. cout << "arcctg(" << x << ") = " << y << '\n';
  61. }
  62. std::cout << '\n';
  63. }
  64.  
  65.  
  66. void lnX() {
  67. cout << "Введите диапозон (0, 10]:";
  68. cin >> start >> end;
  69. cout << "Введите шаг: ";
  70. cin >> step;
  71. cout << '\n';
  72. for (double x = start; x <= end; x += step){
  73. if (x <= 0) {
  74. std::cerr << "Error: ln(x) is undefined for x <= 0\n";
  75. break;
  76. }
  77. double y = log(x);
  78. cout << "log(" << x << ") = " << y << '\n';
  79. }
  80. cout << '\n';
  81. }
  82.  
  83. public:
  84. void doTask() {
  85. int temp;
  86. std::cout << "Какую функцию Вам нужно протабулировать:\n";
  87. std::cout << "sin(x) : 1\n";
  88. std::cout << "cos(x) : 2\n";
  89. std::cout << "arctg(x) : 3\n";
  90. std::cout << "arcctg(x) : 4\n";
  91. std::cout << "log(x) : 5\n";
  92. std::cout << '\n';
  93. std::cin >> temp;
  94.  
  95. switch (temp) {
  96. case 1 : sinX();
  97. break;
  98.  
  99. case 2 : cosX();
  100. break;
  101.  
  102. case 3 : arctgX();
  103. break;
  104.  
  105. case 4 : arcctgX();
  106. break;
  107.  
  108. case 5 : lnX();
  109. break;
  110.  
  111. default : std::cout << "Неправильный ввод\n";
  112. break;
  113. }
  114.  
  115. }
  116. };
  117.  
  118. int main() {
  119. char cont = 'y';
  120. while (cont == 'y') {
  121. Tabul task;
  122. task.doTask();
  123. std::cout << "\nЖелаете продолжить? y/n\t";
  124. std::cin >> cont;
  125. }
  126.  
  127. return 0;
  128. }
  129.  
  130. /// sin(x)
  131. /// cos(x)
  132. /// arctg(x)
  133. /// arcctg(x)
  134. /// ln(x)
  135.  
  136. /*
  137. f(x) = x^2
  138. f(x) = x^3
  139.  
  140. f(x) = |x| // abs()
  141.  
  142.  
  143.  
  144.  
  145. f(x) = ax^2 + bx + c
  146.  
  147. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement