generated from aigora/starter-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmenoramayor.c
321 lines (265 loc) · 6.48 KB
/
fmenoramayor.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
#include <stdio.h>
//Declaracion de structs
struct TDatosFuente {
char fuente[500];
float pH;
int conductividad;
int turbidez;
int coliformes;
};
//Prototipos de las funciones
float fmaximoLav(struct TDatosFuente[]);
float fmaximoCar(struct TDatosFuente[]);
float fmaximoVall(struct TDatosFuente[]);
float fminimoLav(struct TDatosFuente[]);
float fminimoCar(struct TDatosFuente[]);
float fminimoVall(struct TDatosFuente[]);
float fmenoramayorLav(struct TDatosFuente[]);
float fmenoramayorCar(struct TDatosFuente[]);
float fmenoramayorVall(struct TDatosFuente[]);
float fmayoramenorLav(struct TDatosFuente[]);
float fmayoramenorCar(struct TDatosFuente[]);
float fmayoramenorVall(struct TDatosFuente[]);
int main () {
//Declaracion de variables
int op;
int NumFuentesCar, NumFuentesLav, NumFuentesVall;
int potable;
int i, j, n;
float pH;
int conductividad, turbidez, coliformes;
char fuente[500];
int opcion;
float maximo, minimo;
struct TDatosFuente FuenteLav[500];
struct TDatosFuente FuenteCar[500];
struct TDatosFuente FuenteVall[500];
float menoramayor;
float mayoramenor;
//Abrir ficheros y escanearlos
//Carabanchel
FILE *fCarabanchel;
fCarabanchel = fopen("fCarabanchel.txt", "r");
if (fCarabanchel == NULL) {
printf ("ERROR, no se puede abrir el fichero.");
return 0;
}
while (fscanf (fCarabanchel, "%s %f %d %d %d", FuenteCar[i].fuente, &pH, &conductividad, &turbidez, &coliformes)!= EOF){
FuenteCar[i].pH = pH;
FuenteCar[i].conductividad = conductividad;
FuenteCar[i].turbidez = turbidez;
FuenteCar[i].coliformes = coliformes;
i++;
}
fclose (fCarabanchel);
NumFuentesCar = i;
//Lavapies
FILE *fLavapies;
fLavapies = fopen ("fLavapies.txt", "r");
if (fLavapies == NULL) {
printf ("ERROR, no se puede abrir el fichero.");
return 0;
}
i=0;
while (fscanf (fLavapies, "%s %f %d %d %d", FuenteLav[i].fuente, &pH, &conductividad, &turbidez, &coliformes)!= EOF){
FuenteLav[i].pH = pH;
FuenteLav[i].conductividad = conductividad;
FuenteLav[i].turbidez = turbidez;
FuenteLav[i].coliformes = coliformes;
i++;
}
fclose (fLavapies);
NumFuentesLav = i;
//Vallecas
FILE *fVallecas;
fVallecas = fopen ("fVallecas.txt", "r");
if (fVallecas == NULL) {
printf ("ERROR, no se puede abrir el fichero.");
return 0;
}
i=0;
while (fscanf (fVallecas, "%s %f %d %d %d", FuenteVall[i].fuente, &pH, &conductividad, &turbidez, &coliformes)!= EOF){
FuenteVall[i].pH = pH;
FuenteVall[i].conductividad = conductividad;
FuenteVall[i].turbidez = turbidez;
FuenteVall[i].coliformes = coliformes;
i++;
}
fclose (fVallecas);
NumFuentesVall = i;
do {
printf ("Introduzca una opcion: \n\n");
printf ("1 - Lavapies \n");
printf ("2 - Carabanchel \n");
printf ("3 - Vallecas \n\n");
scanf ("%d", &op);
} while (op<1 || op>3);
switch (op) {
//Lavapies
case 1:
do {
printf ("Introduzca una opcion: \n\n");
printf ("1 - De menor a mayor \n");
printf ("2 - De mayor a menor \n");
scanf("%d", &op);
} while (op<1 || op>2);
switch (op) {
case 1:
menoramayor=fmenoramayorLav(FuenteLav);
for(i=0;i<25;i++) {
printf("%s: ", FuenteLav[i].fuente);
printf("%.2f \n",FuenteLav[i].pH);
}
break;
case 2:
mayoramenor=fmayoramenorLav(FuenteLav);
for(i=0;i<25;i++) {
printf("%s: ", FuenteLav[i].fuente);
printf("%.2f \n",FuenteLav[i].pH);
}
break;
}
break;
//Carabanchel
case 2:
do {
printf ("Introduzca una opcion: \n\n");
printf ("1 - De menor a mayor \n");
printf ("2 - De mayor a menor \n");
scanf("%d", &op);
} while (op<1 || op>2);
switch (op) {
case 1:
menoramayor=fmenoramayorCar(FuenteCar);
for(i=0;i<30;i++) {
printf("%s: ", FuenteCar[i].fuente);
printf("%.2f \n",FuenteCar[i].pH);
}
break;
case 2:
mayoramenor=fmayoramenorCar(FuenteCar);
for(i=0;i<30;i++) {
printf("%s: ", FuenteCar[i].fuente);
printf("%.2f \n",FuenteCar[i].pH);
}
break;
}
break;
//Vallecas
case 3:
do {
printf ("Introduzca una opcion: \n\n");
printf ("1 - De menor a mayor \n");
printf ("2 - De mayor a menor \n");
scanf("%d", &op);
} while (op<1 || op>2);
switch (op) {
case 1:
menoramayor=fmenoramayorVall(FuenteVall);
for(i=0;i<27;i++) {
printf("%s: ", FuenteVall[i].fuente);
printf("%.2f \n",FuenteVall[i].pH);
}
break;
case 2:
mayoramenor=fmayoramenorVall(FuenteVall);
for(i=0;i<27;i++) {
printf("%s: ", FuenteVall[i].fuente);
printf("%.2f \n",FuenteVall[i].pH);
}
break;
}
break;
}
//Cerrar ficheros
fclose (fLavapies);
fclose (fCarabanchel);
fclose (fVallecas);
return 0;
}
//MENOR A MAYOR
float fmenoramayorLav (struct TDatosFuente FuenteLav[]) {
int i,j;
float aux;
for (i=0;i<25;i++) {
for (j=i+1;j<25;j++) {
if (FuenteLav[i].pH>FuenteLav[j].pH) {
aux=FuenteLav[i].pH;
FuenteLav[i].pH=FuenteLav[j].pH;
FuenteLav[j].pH=aux;
}
}
}
return aux;
}
float fmenoramayorCar (struct TDatosFuente FuenteCar[]) {
int i,j;
float aux;
for (i=0;i<30;i++) {
for (j=i+1;j<30;j++) {
if (FuenteCar[i].pH>FuenteCar[j].pH) {
aux=FuenteCar[i].pH;
FuenteCar[i].pH=FuenteCar[j].pH;
FuenteCar[j].pH=aux;
}
}
}
return aux;
}
float fmenoramayorVall (struct TDatosFuente FuenteVall[]) {
int i,j;
float aux;
for (i=0;i<27;i++) {
for (j=i+1;j<27;j++) {
if (FuenteVall[i].pH>FuenteVall[j].pH) {
aux=FuenteVall[i].pH;
FuenteVall[i].pH=FuenteVall[j].pH;
FuenteVall[j].pH=aux;
}
}
}
return aux;
}
//MAYOR A MENOR
float fmayoramenorLav (struct TDatosFuente FuenteLav[]) {
int i,j;
float aux;
for (i=0;i<25;i++) {
for (j=i+1;j<25;j++) {
if (FuenteLav[i].pH<FuenteLav[j].pH) {
aux=FuenteLav[i].pH;
FuenteLav[i].pH=FuenteLav[j].pH;
FuenteLav[j].pH=aux;
}
}
}
return aux;
}
float fmayoramenorCar (struct TDatosFuente FuenteCar[]) {
int i,j;
float aux;
for (i=0;i<30;i++) {
for (j=i+1;j<30;j++) {
if (FuenteCar[i].pH<FuenteCar[j].pH) {
aux=FuenteCar[i].pH;
FuenteCar[i].pH=FuenteCar[j].pH;
FuenteCar[j].pH=aux;
}
}
}
return aux;
}
float fmayoramenorVall (struct TDatosFuente FuenteVall[]) {
int i,j;
float aux;
for (i=0;i<27;i++) {
for (j=i+1;j<27;j++) {
if (FuenteVall[i].pH<FuenteVall[j].pH) {
aux=FuenteVall[i].pH;
FuenteVall[i].pH=FuenteVall[j].pH;
FuenteVall[j].pH=aux;
}
}
}
return aux;
}