Untitled

Oct 20th, 2021
784
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <cmath>
3. #include <cstring>
4. #include <time.h>
5.
6. long long factorio(long long n)
7. {
8.     if (n < 1)
9.     {return 1;}
10.     return n*factorio(n-1);
11. }
12.
14.
15. int main()
16. {
17.
19.     return 0;
20. }
21.
22. void change_to_undersores(char arr[])
23. {
24.
25.     for (int i = 0; i < strlen(arr); i++)
26.     {
27.         if ( !(arr[i] > 'a' && arr[i] < 'z') && !(arr[i] > 'A' && arr[i] < 'Z') && !(arr[i] > '0' && arr[i] < '9'))
28.         {
29.             arr[i] = '_';
30.         }
31.     }
32. }
33.
34. void EX1()
35. {
36.     system("cls");
37.     char text[] = "Text#with@weird^signs@()-";
38.     change_to_undersores(text);
39.     std::cout << text << std::endl;
40.     system("pause");
41.     system("cls");
42. }
43.
44. void calculate_tryg_from_series(double x, int n, double& sin, double& cos)
45. {
46.     //sine
47.
48.     for (int i = 0; i<=n; i-=-1)
49.     {
50.         sin += (pow(-1, i) * pow(x, 2*i+1))/factorio(2*i+1);
51.     }
52.
53.     //cosine
54.
55.     for (int i = 0; i<=n; i-=-1)
56.     {
57.         cos += (pow(-1, i) * pow(x, 2*i))/factorio(2*i);
58.     }
59.
60. }
61.
62. void EX2()
63. {
64.     system("cls");
65.
66.     double sin_val=0, cos_val=0;
67.     calculate_tryg_from_series(0.52, 20, sin_val, cos_val);
68.
69.     std::cout << "sin_val: " << sin_val << std::endl << "cos_val: " << cos_val << std::endl;
70.
71.     system("pause");
72.     system("cls");
73. }
74.
75. double polynomial(double coef[], int n, double& x)
76. {
77.     double result = 0;
78.     int n2 = n;
79.
80.     for (int i = 0; i < n; i -=- 1)
81.     {
82.         result += pow(x, n2-1) * coef[i];
83.         n2--;
84.     }
85.     return result;
86. }
87.
88. void EX3()
89. {
90.     system("cls");
91.
92.     double coefs[4] = {-3, 2, -3, 5};
93.     int n = 4;
94.     double x = 2;
95.     double result = polynomial(coefs, n, x);
96.
97.     std::cout << result << std::endl;
98.
99.     system("pause");
100.     system("cls");
101. }
102.
103. double mean(int arr[], int& n)
104. {
105.     int sum=0;
106.     for (int i = 0; i < n; i++)
107.     {
108.         sum+=arr[i];
109.     }
110.     return sum/n;
111. }
112.
113. void EX4()
114. {
115.     system("cls");
116.
117.     int arr[100];
118.     srand(time(NULL));
119.
120.     int n = sizeof(arr) / sizeof(arr[0]);
121.
122.     for (int i = 0 ; i < n; i++)
123.     {
124.         arr[i]=rand() % 101 + 50;
125.     }
126.
127.     double mean_val = mean(arr, n);
128.     std::cout << mean_val << std::endl;
129.
130.     system("pause");
131.     system("cls");
132.
133. }
134.
135.
137. {
138.     char choice = 'x';
139.
140.     std::cout << "Choose task: " << std::endl
141.               << "[1] " << std::endl
142.               << "[2] " << std::endl
143.               << "[3] " << std::endl
144.               << "[4] " << std::endl
145.               << "[0] to exit " << std::endl;
146.
147.     std::cin >> choice;
148.
149.     if (choice == '1')
150.     {
151.         EX1();
152.     }
153.     else if (choice == '2')
154.     {
155.         EX2();
156.     }
157.     else if (choice == '3')
158.     {
159.         EX3();
160.     }
161.
162.     else if (choice == '4')
163.     {
164.         EX4();
165.     }
166.     else if (choice == '0')
167.     {
168.         return false;
169.     }
170.     else
171.     {
172.         system("cls");
173.         std::cout << std::endl << "Wrong task number, please try again" << std::endl;
174.     }
175.     return true;
176. }
177.
RAW Paste Data