-
Notifications
You must be signed in to change notification settings - Fork 0
/
if_trigonometry.cpp
258 lines (243 loc) · 6.24 KB
/
if_trigonometry.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "header.h"
using namespace std;
int all_t=0;
int trigono_token=0,kt=0;
bool trigonometry_function(string equ)
{
int lnCount=80,trigCount,rootCount=80;
for(int i=0; i<equ.size(); i++)
{
if(equ[i] == 'l')
lnCount=i;
else if(equ[i]=='t' || equ[i]== 's' || equ[i]=='c')
trigCount=i;
else if(equ[i]=='s' && equ[i+1]=='q')
rootCount=i;
}
if(lnCount<trigCount)
return false;
if(rootCount<trigCount)
return false;
for(int i=0; i<equ.size(); i++)
{
if(equ[i]=='s' && equ[i+1]=='i' && equ[i+2]=='n')
{
trigono_token=1;
return true;
}
else if(equ[i]=='c' && equ[i+2]=='s' && equ[i+3] != 'e')
{
trigono_token = 2;
return true;
}
else if(equ[i]=='c' && equ[i+3]=='e')
{
trigono_token = 3;
return true;
}
else if(equ[i]=='s' && equ[i+2]=='c')
{
trigono_token = 4;
return true;
}
else if(equ[i]=='t' && equ[i+2]=='n')
{
trigono_token = 5;
return true;
}
else if(equ[i]=='c' && equ[i+2]=='t')
{
trigono_token = 6;
return true;
}
}
if(trigono_token==0)
return false;
}
int trigono_sign()
{
kt++;
return trigono_token;
}
void all_trigon()
{
all_t++;
}
void trigo_null()
{
all_t = 0;
}
string if_trigonometry(string equ)
{
string ans7="";
char trigonometry_chain[1000];
int j=0,k;
int ob=0,i;
char trigono_var;
for(int i=0; i<equ.size(); i++)
{
if(equ[i]=='(' && i==0)
continue;
if(equ[i]=='(' && equ[i+1] == '(')
continue;
if(equ[i]== '(' && i != 0)
{
if(equ[i+2] ==')' && equ[i+1]!='(')
{
k=1;
int n_type=char_type(equ[i+1]);
if(n_type==1)
trigono_var = equ[i+1];
else if(n_type==2)
trigono_var = '\0';
}
else
{
trigonometry_chain[j] = equ[i];
j++;
trigonometry_chain[j] = equ[i+1];
j++;
}
}
else if(j>0)
{
trigonometry_chain[j] = equ[i+1];
j++;
}
if(equ[i]==')')
{
trigonometry_chain[j] = '\0';
}
}
for( i=0; i<strlen(trigonometry_chain); i++)
{
if(trigonometry_chain[i]=='(')
{
ob++;
}
else break;
}
for(int j=i; j<=strlen(trigonometry_chain); j++)
trigonometry_chain[j-ob]=trigonometry_chain[j];
if(all_t>0 && k != 1)
{
cout<<"d/d";
int xt,yt=0;
char ct='\0';
for(int i=0; i<equ.size(); i++)
{
if(equ[i] != '(' && yt==0)
continue;
if(char_type(equ[i]) == 1 && char_type(equ[i+1])==1)
continue;
if(char_type(equ[i])==1 && equ[i+1]=='(')
continue;
else
{
yt++;
xt=char_type(equ[i]);
if(xt==1)
{
ct=equ[i];
break;
}
}
}
if(ct=='\0')
{
ct='x';
cout<<ct<<" "<<"(";
}
else cout<<ct<<" "<<"(";
cout<<trigonometry_chain<<"*";
}
if(trigono_token == 2 || trigono_token == 3 || trigono_token == 6 )
{
if(kt == 0 )
{
ans7 += "-";
if(all_t>0 && k!=1)
cout<<"-";
}
}
if( k != 1)
{
ans7 += "(";
ans7 +=for_partition(trigonometry_chain);
ans7 +="*";
}
else
{
if(trigono_var == '\0' )
{
ans7 = "0";
return ans7;
}
else
{
trigonometry_chain[0] = '(';
trigonometry_chain[1] = trigono_var;
trigonometry_chain[2] = ')';
trigonometry_chain[3] = '\0';
}
}
if(trigono_token==2)
{
if(all_t>0 && k != 1)
cout<<"sin("<<trigonometry_chain;
ans7 += "sin(";
for(int i=0; trigonometry_chain[i] != '\0'; i++)
ans7 += trigonometry_chain[i];
}
else if(trigono_token==3)
{
if(all_t>0 && k!=1)
cout<<"cosec("<<trigonometry_chain<<"*cot("<<trigonometry_chain;
ans7 += "cosec(";
for(int i=0; trigonometry_chain[i] != '\0'; i++)
ans7 += trigonometry_chain[i];
ans7 += "*cot(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
}
else if(trigono_token==1)
{
if(all_t>0 && k!=1)
cout<<"cos("<<trigonometry_chain;
ans7 += "cos(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
}
else if(trigono_token==5)
{
if(all_t>0 && k!=1)
cout<<"sec^2("<<trigonometry_chain;
ans7 += "sec^2(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
}
else if(trigono_token==6)
{
if(all_t>0 && k!=1)
cout<<"cosec^2("<<trigonometry_chain;
ans7 += "cosec^2(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
}
else if(trigono_token==4)
{
if(all_t>0 && k!=1)
cout<<"sec("<<trigonometry_chain<<"*tan("<<trigonometry_chain;
ans7 += "sec(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
ans7 += "*tan(";
for(int i=0; trigonometry_chain[i]!='\0'; i++)
ans7 += trigonometry_chain[i];
}
if(all_t>0 && k != 1)
cout<<"\n\n\t\t\t = ";
trigono_token = 0;
kt=0;
return ans7;
}