forked from Aleksandr505/LabsUniversity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab7.cpp
89 lines (68 loc) · 1.68 KB
/
lab7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <cmath>
using namespace std;
class SinusSpecialClassForMySpecialProgramWithoutSpringImplements {
private:
int x;
public:
static int n;
void setX(int x) {
this->x = x;
}
// для теста
int getX() {
return x;
}
double CalculatingSinusInsightClass();
};
int factorial(int i) {
if (i == 0) {
return 1;
}
else {
return i * factorial(i - 1);
}
}
int safeInput() {
while (true) {
int a;
cin >> a;
if (cin.fail()) {
cin.clear();
cin.ignore(32767, '\n');
cout << "Please, input integer number" << "\n" << endl;
}
else {
cin.ignore(32767, '\n');
return a;
}
}
}
int binpow(int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow(a, n - 1) * a;
else {
int b = binpow(a, n / 2);
return b * b;
}
}
int SinusSpecialClassForMySpecialProgramWithoutSpringImplements::n;
int main() {
setlocale(LC_ALL, "Rus");
SinusSpecialClassForMySpecialProgramWithoutSpringImplements sinObj;
SinusSpecialClassForMySpecialProgramWithoutSpringImplements::n = 4;
cout << "Введите целочисленный аргумент " << endl;
sinObj.setX(safeInput());
cout << "sin(x) = " << sinObj.CalculatingSinusInsightClass() << "\n" << endl;
return 0;
}
double SinusSpecialClassForMySpecialProgramWithoutSpringImplements::CalculatingSinusInsightClass() {
double sumSin = 0;
for (int i = 0; i <= n; i++) {
sumSin += (double) binpow(-1, i) * binpow(x, 2 * i + 1) / factorial(2 * i + 1);
cout << "числа внутри метода: x=" << x << ", n=" << n << ", sumSin=" << sumSin << "\n" << endl;
}
return sumSin;
}