-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumerical_integration.cpp
More file actions
284 lines (280 loc) · 5.04 KB
/
numerical_integration.cpp
File metadata and controls
284 lines (280 loc) · 5.04 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include<iostream>
#include<math.h>
#include<string.h>
#define parts 2550
#define size 30
using namespace std;
class integ
{
protected:
double ar,h;
double ax[parts],ay[parts];
double area()
{
double su=0.00;
for(int i=1;i<parts-1;i++)
su+=ay[i];
ar=(h/2)*(ay[0]+ay[parts-1]+(2*su));
return ar;
}
double area1()
{
double sue=0.00,suo=0.0;
for(int i=1;i<parts-1;i+=2)
{
suo+=ay[i];
sue+=ay[i+1];
}
sue-=ay[parts-1];
ar=(h/3)*(ay[0]+ay[parts-1]+(4*suo)+(2*sue));
return ar;
}
};
class circle:public integ
{
double r,j;
public:
void get_radius()
{
cout<<"Enter Radius : ";
cin>>r;
}
void calc_x_y()
{
h=r/double(parts);
j=0.0;
for(int i=0;i<parts;i++)
{
ax[i]=j;
j+=h;
}
for(int i=0;i<parts;i++)
ay[i]=sqrt(r*r-ax[i]*ax[i]);
}
void display()
{
calc_x_y();
cout<<"area : "<<area()*4<<endl;
cout<<"area : "<<area1()*4<<endl;
cout<<"area nor :"<<r*r*3.14<<endl;
}
};
class rect:public integ
{
double l,b,j;
public:
void get_side()
{
cout<<"Enter length : ";
cin>>l;
cout<<"Enter breath : ";
cin>>b;
}
void calc_x_y()
{
h=b/double(parts);
j=0.0;
for(int i=0;i<parts;i++)
{
ax[i]=j;
j+=h;
}
for(int i=0;i<parts;i++)
ay[i]=(l/b)*ax[i];
}
void display()
{
calc_x_y();
cout<<"area : "<<area()*2<<endl;
cout<<"area : "<<area1()*2<<endl;
cout<<"area nor :"<<l*b<<endl;
}
};
/*class infi_post
{
public:
int G(char sy)
{
switch(sy)
{
case '+':
case '-':
return 1;
case '*':
case '/':
return 3;
case '^':
case '$':
return 6;
case '(':
return 9;
case ')':
return 0;
default :
return 7;
}
}
int F(char sy)
{
switch(sy)
{
case '+':
case '-':
return 2;
case '*':
case '/':
return 4;
case '^':
case '$':
return 5;
case '(':
return 0;
case '#':
return -1;
default :
return 8;
}
}
struct stack
{
int top;
char items[size];
};
int isFull(stack *s)
{
if(s->top==size)
{
return true;
}
else
{
return false;
}
}
int isEmpty(stack *s)
{
if(s->top<=-1)
{
return true;
}
else
{
return false;
}
}
void push(stack *s,char x)
{
if(!(isFull(s)))
{
s->top+=1;
s->items[s->top]=x;
}
}
char pop(stack *s)
{
if(!(isEmpty(s)))
{
char temp=s->items[s->top];
s->top--;
return temp;
}
else
return 'n';
}
void infix_postfix(char infix[size],char postfix[size])
{
stack s;
s.top=-1;
int i,j=0;
char sym,ch;
push(&s,'#');
for(i=0;i<strlen(infix);i++)
{
sym=infix[i];
while(F(s.items[s.top])>G(sym))
{
ch=pop(&s);
if(ch!='n')
postfix[j++]=ch;
}
if(F(s.items[s.top])!=G(sym))
{
push(&s,sym);
}
else
{
ch=pop(&s);
}
}
while(s.items[s.top]!='#')
{
postfix[j++]=pop(&s);
}
postfix[j]='\0';
}
};
class post_eval
{
struct stack
{
int top;
char items[size];
};
void push(char x,stack *s)
{
s->top+=1;
s->items[s->top]=x;
}
char pop(stack *s)
{
char temp=s->items[s->top];
s->top--;
return temp;
}
int OP(char symbol,int op1,int op2)
{
switch(symbol)
{
case '+':
return (op1+op2);
case '-':
return (op1-op2);
case '*':
return (op1*op2);
case '/':
return (op1/op2);
case '$':
case '^':
return (pow(op1,op2));
}
}
public:
};
class irregular:public integ,private infi_post
{
char infix[size],postfix[size];
public:
void get_data()
{
cout<<"infix : ";
cin>>infix;
}
void convert()
{
infix_postfix(infix,postfix);
cout<<"\npost: "<<postfix;
}
};*/
int main()
{
circle c1;
c1.get_radius();
c1.display();
rect r1;
r1.get_side();
r1.display();
//irregular i1;
//i1.get_data();
//i1.convert();
return (0);
}