-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
369 lines (309 loc) · 10.6 KB
/
main.c
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/* # Waste Management
@author deepak sai pendyala
Instructions:
Step 1: Enter 1 for the functionalities of Municipal Authority:
Enter 2 for the functionality of consumer:
Step 2: Enter No of Areas
Step 3: Enter No of Houses
Step 4: Enter No of days
Step 5: If Option ‘1’ is chosen in Step 1:
Enter one of the functionalities below:
1). Calculate Average waste
2). Reward the House which gave lowest waste
3). Compute the Earnings of municipality
4). Check what percentage of the waste is from what category
Else if Option ‘2’ is chosen, the Program will Automatically proceed to functionality of “As an individual family, analyzing the expense for managing the waste”
Step 6: Enter Data of quantities for individual days and Houses of different houses.
Step 7: The program will display the output as per functionalities selected
Step 8: The Program will create the file named “output.txt” automatically & the output will be saved to it.
*/
#include <stdio.h>
#include <string.h>
FILE *filePointer ;
//Function Prototyping
float avg(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,float finall,int a,int b,int c);
int reward(float degrad[],float plastic[],float elec[],int area,int h,int d,int a,int b,int c);
float earn(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,int a,int b,int c);
int percentage(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,float *td,float *tp,float *te,float *ptotal,int a,int b,int c);
int customer();
int main() {
filePointer = fopen("output.txt", "a+") ;
int option,choice,h,d,area,x,j,k,i,g;
int a,b,c;
float finall=0;
float result=0;
printf("Namaskar..! Welcome to Waste Management Calculator\nif you are consumer, please type 1\nif you are from Municipal Authority, please press 2:");
scanf("%d", &option);
if (option==2){
printf("Welcome back to Municipal Waste management calculator\nPlease enter no of areas in the municipality:");
scanf("%d", &area);
printf("Please enter no of houses in the area:");
scanf("%d", &h);
printf("Please enter the no of days to be calculated:");
scanf("%d", &d);
c=d/3;
if (d%3==2) {
a=(c+1)*h;
b=(c+1)*h;
c=c*h; }
else if (d%3==1) {
a=(c+1)*h;
b=c*h;
c=c*h; }
else if(d%3==0){
a=c*h;
b=c*h;
c=c*h; }
float degrad[a],plastic[b],elec[c];
float td=0,tp=0,te=0,ptotal=0;
x=h;
k=0;
printf("If you want to computes the statistics of the waste collection per area, Please enter 1\n If you want to reward the house which gives less quantity of waste, please enter 2\nIf you want to Compute the total earning for the municipality, please enter 3\nIf you want to know what percentage of the waste is from what category, please enter 4:");
scanf("%d",&choice);
for (int f=0;f<area;f++){
k=0;
h=x;
printf("ENTER THE DETAILS IN AREA %d\n",f+1);
for (g=0;g<d;g=g+3) {
printf("enter the quantity of degradable waste in kg on day %d\n",g+1);
j=0;
for (i=k;i<h;i++){
printf("Enter quantity in house %d :",j+1);
scanf("%f",°rad[i]);
j=j+1; }
k=i;
h=h+x; }
k=0;
h=x;
for(g=1;g<d;g=g+3) {
printf("enter the quantity of plastic waste in kg on day %d\n",g+1);
j=0;
for (i=k;i<h;i++){
printf("Enter quantity in house %d :",j+1);
scanf("%f",&plastic[i]);
j=j+1; }
k=i;
h=h+x; }
k=0;
h=x;
for (g=2;g<d;g=g+3) {
printf("enter the quantity of electronic waste in kg on day %d\n",g+1);
j=0;
for(i=k;i<h;i++){
printf("Enter quantity in house %d :",j+1);
scanf("%f",&elec[i]);
j=j+1; }
k=i;
h=h+x; }
switch(choice){
case 1:
finall=avg(degrad,plastic,elec,area,x,d,f,finall,a,b,c);
break;
case 2:
reward(degrad,plastic,elec,area,x,d,a,b,c);
break;
case 3:
earn(degrad,plastic,elec,area,x,d,f,a,b,c);
break;
case 4:
percentage(degrad,plastic,elec,area,x,d,f,&td,&tp,&te,&ptotal,a,b,c);
break;
default:
printf("wrong input, sorry! run again");
}
printf("\n\n\n"); }
}
else if (option==1){
printf("Now, You're entering as a customer\n");
customer(); }
else printf("wrong input, sorry! run again");
fprintf(filePointer, "%s"," END OF PROGRAM \n");
fclose(filePointer);
return 0;
}
/*charges : 1kg degredable waste - 5rs
1kg plastic waste - 10rs
1kg electronic waste - 15rs */
float avg(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,float finall,int a,int b,int c){
filePointer = fopen("output.txt", "a+") ;
float tdeg=0,tplas=0,telec=0,total,avg=0;
int i;
for (i=0;i<a;i++){
tdeg+=degrad[i];}
for (i=0;i<b;i++){
tplas+=plastic[i]; }
for(i=0;i<c;i++){
telec+=elec[i]; }
total=tdeg+tplas+telec;
avg=total/3;
finall+=avg;
if(area==f+1){
printf("So Finally, Average waste in all Categories of waste in Municipality for %d days in %d Area/Areas is %.2f kgs",d,f+1,finall);
fprintf(filePointer, "%s","Average waste function:\n");
fprintf(filePointer, "%s %d %s %d %s %f %s", "So Finally, Average waste in all Categories of waste in Municipality for ", d," days in ", f+1," Area/Areas is ",finall," kgs\n");
return 0;
}
return finall;
}
int reward(float degrad[],float plastic[],float elec[],int area,int h,int d,int a,int b,int c){
filePointer = fopen("output.txt", "a+") ;
fprintf(filePointer, "%s","Rewards function:\n");
int i,j,k=0;
float dh[a],ph[b],eh[c];
float dhd[a],phd[b],ehd[c];
for(i=0;i<h;i++){
dh[i]=0;
for(j=k;j<a;j+=h){
dh[i]+=degrad[j];
}k+=1;
}
for(int i=0;i<h;i++){
printf("House %d gives %.2f kgs degradable waste \n",i+1,dh[i]);
fprintf(filePointer,"%s %d %s %f %s","House ",i+1," gives ",dh[i],"kgs degradable waste \n");
}
float min = dh[0];
int hn;
for(i=0;i<h;i++){
dhd[i]=dh[i];
}
for (i=1;i<h;i++)
if (dh[i]<min){
min=dh[i];
}
for(i=0;i<h;i++){
if(min==dhd[i]){
printf("The house which gives low quantity of degradable waste is rewarded with badminton kit i.e house %d with %.2f kgs bio degradable waste\n",i+1,min);
fprintf(filePointer,"%s %d %s %f %s","The house which gives low quantity of degradable waste is rewarded with badminton kit i.e house ",i+1," with ",min," kgs bio degradable waste \n");
}
}
k=0;
for(i=0;i<h;i++){
ph[i]=0;
for(j=k;j<b;j+=h){
ph[i]+=plastic[j];
}k+=1;
}
for(int i=0;i<h;i++){
printf("House %d gives %.2f kgs plastic waste \n",i+1,ph[i]);
fprintf(filePointer,"%s %d %s %f %s","House ",i+1," gives ",ph[i],"kgs plastic waste \n");
}
min = ph[0];
for(i=0;i<h;i++){
phd[i]=ph[i];
}
for (i=1;i<h;i++)
if (ph[i]<min){
min=ph[i];
}
for(i=0;i<h;i++){
if(min==phd[i]){
printf("The house which gives low quantity of plastic waste is rewarded with cricket kit i.e house %d with %.2f kgs plastic waste \n",i+1,min);
fprintf(filePointer,"%s %d %s %f %s","The house which gives low quantity of plastic waste is rewarded with cricket kit i.e ",i+1," with ",min," kgs bio degradable waste \n");
}
}
k=0;
for(i=0;i<h;i++){
eh[i]=0;
for(j=k;j<c;j+=h){
eh[i]+=elec[j];
}k+=1;
}
for(int i=0;i<h;i++){
printf("House %d gives %.2f kgs electronic waste \n",i+1,eh[i]);
fprintf(filePointer,"%s %d %s %f %s","House ",i+1," gives ",eh[i],"kgs electronic waste \n");
}
min = eh[0];
for(i=0;i<h;i++){
ehd[i]=eh[i];
}
for (i=1;i<h;i++)
if (eh[i]<min){
min=eh[i];
}
for(i=0;i<h;i++){
if(min==ehd[i]){
printf("The house which gives low quantity of electronic waste is rewarded with footbal kit i.e house %d with %.2f kgs electronic waste",i+1,min);
fprintf(filePointer,"%s %d %s %f %s","The house which gives low quantity of electronic waste is rewarded with footbal kit i.e house ",i+1," with ",min," kgs electronic waste \n");
}
}
return 0;
}
float earn(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,int a,int b,int c){
filePointer = fopen("output.txt", "a+") ;
static float finall;
float tdeg=0,tplas=0,telec=0,total;
int i;
for (i=0;i<a;i++){
tdeg+=degrad[i]*5;}
for (i=0;i<b;i++){
tplas+=plastic[i]*10; }
for(i=0;i<c;i++){
telec+=elec[i]*15; }
total=tdeg+tplas+telec;
finall+=total;
if(area==f+1){
printf("So Finally, Total Earnings of the Municipality for %d days in %d Area/Areas is ₹%.2f ",d,f+1,finall);
fprintf(filePointer, "%s","Earings function:\n");
fprintf(filePointer, "%s %d %s %d %s %f\n", "So Finally, Total Earnings of the Municipality for ", d," days in ", f+1," Area/Areas is ₹",finall);
}
return 0;
}
int percentage(float degrad[],float plastic[],float elec[],int area,int h,int d,int f,float *td,float *tp,float *te,float *ptotal,int a,int b,int c){
filePointer = fopen("output.txt", "a+") ;
float tdeg=0,tplas=0,telec=0,total;
int i;
for (i=0;i<a;i++){
tdeg+=degrad[i];}
for (i=0;i<b;i++){
tplas+=plastic[i]; }
for(i=0;i<c;i++){
telec+=elec[i]; }
total=tdeg+tplas+telec;
*td+=tdeg;
*tp+=tplas;
*te+=telec;
*ptotal+=total;
if(area==f+1) {
*td=(*td / *ptotal)*100;
*tp=(*tp / *ptotal)*100;
*te=(*te / *ptotal)*100;
printf("total wastage is %.2f KGS\n",*ptotal);
printf("%.2f %% is from degradable waste category\n",*td);
printf("%.2f %% is from plastic waste category\n",*tp);
printf("%.2f %% is from electronic waste category\n",*te);
fprintf(filePointer, "%s %d %s","percentage function in area",f+1," :\n");
fprintf(filePointer, "%s %f %s", "total wastage is ",*ptotal ,"KGS\n");
fprintf(filePointer, "%f %s",*td ," %% is from degradable waste category\n");
fprintf(filePointer, "%f %s",*tp ," %% is from plastic waste category\n");
fprintf(filePointer, "%f %s",*te ," %% is from electronic waste category\n");
}
return 0;
}
int customer(){
filePointer = fopen("output.txt", "a+") ;
fprintf(filePointer, "%s","customer function:");
int d,g;
printf("Please enter the no of days to be calculated:");
scanf("%d", &d);
float arr[d];
float tdeg=0,tplas=0,telec=0,total;
for (g=0;g<d;g=g+3){
printf("enter the quantity of degradable waste in kg on day %d:",g+1);
scanf("%f",&arr[g]);
tdeg+=(arr[g]*5);
}
for(g=1;g<d;g=g+3){
printf("enter the quantity of plastic waste in kg on day %d:",g+1);
scanf("%f",&arr[g]);
tplas=(arr[g]*10);
}
for (g=2;g<d;g=g+3){
printf("enter the quantity of electronic waste in kg on day %d:",g+1);
scanf("%f",&arr[g]);
telec+=(arr[g]*15);
}
total=tdeg+tplas+telec;
printf("Total expenditure on waste management for %d days is ₹%.2f",d,total);
fprintf(filePointer, "Total expenditure on waste management for %d days is ₹ %f\n",d,total);
return 0;
}