Pascal/Turbo Pascal - Ejercicio Basura Pascal

 
Vista:

Ejercicio Basura Pascal

Publicado por Juan (11 intervenciones) el 25/04/2013 00:39:38
Hola, a ver si me pueden ayudar. Este es el ejercicio:

Ejercicio 27



La empresa recolectora de basura debe realizar un informe sobre contaminación ambiental. Para ello
durante un periodo de tiempo (la cantidad de días no se conoce exactamente), cada día se registra la
información de la basura recolectada en cada uno de N hogares (seleccionados y siempre los mismos) de la siguiente forma:

- FECHA
Para cada uno de los N hogares, en dicha fecha :
- BASURA ORGÁNICA
- BASURA INORGÁNICA
- BASURA RECICLABLE (es una parte de la basura inorgánica, o sea inorgánica = reciclable + no reciclable)

Las siguientes relaciones que determinan el nivel de contaminación ambiental:

-------NIVEL-------------------CONTAMINACIÓN -------------------------------------RELACIÓN

---------0-----------------------------No hay ---------------------------BASURA ORGANICA constituye mas del
------------------------------------------------------------------------------------------80% de la BASURA TOTAL (*)



---------1-----------------------------Hay. de nivel 1---------------No se cumple (*) y BASURA RECICLABLE
---------------------------------------------------------------------------Constituye mas del 50% de la BASURA
------------------------------------------------------------------------------INORGÁNICA



---------2-----------------------------Hay, de nivel 2-------------------------------------otros casos




N=3
20/05/04
9 2 1
10 1 1
3 2 2

21/05/04
8 1 1
1 4 1
2 5 2

22/05/04
1 4 3
3 4 3
13 3 1

23/05/04
2 4 3
1 4 1
9 1 1
***


Se pide leer los datos descriptos , calcular e informar:
- Para cada fecha porcentaje de basura reciclable sobre el total de basura (recolectada ese día)
- Fecha con menor cantidad de hogares, con basura contaminante de nivel 2.
- Cantidad de fechas donde el total de basura recolectada en el día (suma de lo recolectado en los N hogares) no esta contaminada.
- Probar el programa con el juego de datos propuesto. Previamente resolver en forma manual.




A ver si alguien me puede ayudar, necesito hacerlo usando While o For o Repeat, es decir, sin utilizar ni procedimientos ni funciones.



Y si no es mucha molestia les dejo otro, pero mas que nada con una duda muy puntual, acá va:


Ejercicio 24



En un torneo de pesca, compiten 3 categorías. Se capturan N especies diferentes registrándose por cada una:
---Código de especie (cadena de 2 caracteres) y en cada una:
---Categoría (1,2 ó 3 ; 0 es fin de datos)
---Peso

N = 4
TB
1 1.6
1 2.6
1 3.7
0
PR
3 2.0
1 1.9
2 1.8
2 2.0
0
CV
2 2.2
2 2.1
0
LG
1 1.5
0

Se pide desarrollar un programa Pascal que resuelva:
a) Para cada especie, total de ejemplares por categoría
b) Peso promedio de ejemplares considerando todas las capturas del torneo
c) Cantidad total de ejemplares de menos de 2 kilos
d) Probar el programa con el juego de datos propuesto.

Mi Gran duda en este ejercicio es como hacer para cuando ingresas el cero te tire los resultados e igualmente te pida que ingreses para seguir con los datos ingresados y tambien para que una vez que termine me tire los resultados generales. Este es el código:

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
Program Pr2Ej24;
Uses
Crt;
Var
N,Cat,ContLGCat1,ContLGCat2,ContLGCat3,ContTBCat1,ContTBCat2, ContTBCat3, ContPRCat1, ContPRCat2, ContPRCat3,ContCVCat1, ContCVCat2, ContCVCat3: Integer;
Cod: String;
Peso,ContMen2K,AcumPesoTB,AcumPesoPR,AcumPesoCV,AcumPesoLG: Real;
i :Byte;
Begin
Clrscr;
   Write('Ingrese el codigo de la especie: ');
    Readln(Cod);
   Write('Ingrese la categoria: ');
    Readln(Cat);
   Write('Ingrese el peso: ');
    Readln(Peso);
 
 
 
 
ContLGCat1:=0;
ContLGCat2:=0;
ContLGCat3:=0;
ContTBCat1:=0;
ContTBCat2:=0;
ContTBCat3:=0;
ContPRCat1:=0;
ContPRCat2:=0;
ContPRCat3:=0;
ContCVCat1:=0;
ContCVCat2:=0;
ContCVCat3:=0;
AcumPesoTB:=0;
AcumPesoPR:=0;
AcumPesoCV:=0;
AcumPesoLG:=0;
ContMen2K:=0;
 
 While Cat <> 0 do
   begin
     Cod:= Upcase(Cod);
 
 
         If Peso < 2 then
         ContMen2K := ContMen2K + 1;
 
 
 
     If (Cod='TB') and (Cat=1)then
      ContTBCat1:= ContTBCat1 + 1
       else
      If (Cod='TB') and (Cat=2) then
      ContTBCat2:= ContTBCat2 + 1
        else
       If (Cod='TB') and (Cat=3) then
       ContTBCat3:= ContTBCat3 + 1;
 
        If (Cod='TB') and (Peso <> 0) then
         AcumPesoTB:= Peso + AcumPesoTB;
 
       Writeln('TB Cat 1 --> ', ContTBCat1);
       Writeln('TB Cat 2 --> ', ContTBCat2);
       Writeln('TB Cat 3 --> ', ContTBCat3);
 
 
 
 
 
      If (Cod= 'PR') and (Cat=1) then
         ContPRCat1:= ContPRCat1 + 1
       else
      If (Cod= 'PR') and (Cat=2) then
         ContPRCat2:= ContPRCat2 + 1
       else
      If (Cod= 'PR') and (Cat=3) then
         ContPRCat3:= ContPRCat3 + 1;
 
        If (Cod='PR') and (Peso <> 0) then
         AcumPesoPR:= Peso + AcumPesoPR;
 
       Writeln('PR Cat 1 --> ', ContPRCat1);
       Writeln('PR Cat 2 --> ', ContPRCat2);
       Writeln('PR Cat 3 --> ', ContPRCat3);
 
 
      If (Cod= 'CV') and (Cat=1) then
         ContCVCat1:= ContCVCat1 + 1
       else
      If (Cod= 'CV') and (Cat=2) then
         ContCVCat2:= ContCVCat2 + 1
        else
      If (Cod= 'CV') and (Cat=3) then
         ContCVCat3:= ContCVCat3 + 1;
 
         If (Cod='CV') and (Peso <> 0) then
         AcumPesoCV:= Peso + AcumPesoCV;
 
 
 
       Writeln('CV Cat 1 --> ', ContCVCat1);
       Writeln('CV Cat 2 --> ', ContCVCat2);
       Writeln('CV Cat 3 --> ', ContCVCat3);
 
 
       If (Cod= 'LG') and (Cat=1) then
         ContLGCat1:= ContLGCat1 + 1
         else
       If (Cod= 'LG') and (Cat=2) then
         ContLGCat2:= ContLGCat2 + 1
        else
       If (Cod= 'LG') and (Cat=3) then
         ContLGCat3:= ContLGCat3 + 1;
 
         If (Cod='LG') and (Peso <> 0) then
         AcumPesoLG:= Peso + AcumPesoLG;
 
 
 
       Writeln('LG Cat 1 --> ', ContLGCat1);
       Writeln('LG Cat 2 --> ', ContLGCat2);
       Writeln('LG Cat 3 --> ', ContLGCat3);
 
 
 
 
      Write('Ingrese el codigo de la especie: ');
     Readln(Cod);
   Write('Ingrese la categoria: ');
     Readln(Cat);
   Write('Ingrese el peso: ');
    Readln(Peso);
 
 
              end;
 
 
 
 
 
 
 
 
 
 
       Writeln('Peso Promedio --> ', ((AcumPesoTB + AcumPesoPR + AcumPesoCV + AcumPesoLG) / (ContLGCat1 + ContLGCat2 + ContLGCat3 + ContTBCat1 + ContTBCat2 + ContTBCat3 + ContPRCat1 + ContPRCat2 + ContPRCat3 + ContCVCat1+ ContCVCat2 + ContCVCat3)):4:2);
       Writeln('Cantidad Menores a 2 Kg --> ', ContMen2K:4:2);
       Writeln('');
 
 
          Readln;
         End.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ejercicio Basura Pascal

Publicado por ramon (2158 intervenciones) el 25/04/2013 22:33:57
Disculpa la forma de resolverlo y estructurarlo tiene que ser esa o puedo hacerlo con otra estructura.
De momento te informo que esto da fallo Cod:= Upcase(Cod); pues upcase es para char no
string,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ejercicio Basura Pascal

Publicado por Juan (11 intervenciones) el 26/04/2013 00:17:27
Si, tenia esa duda de que cuando presionas 0 se termina, pero en realidad tira bien los resultados y todo...
En cuanto al tema de Cod:= Upcase(Cod) no me tira nungun error. Yo tambien pensé que me iba a tirar un error, pero no fue así y lo probé con minúsculas y con Mayúsculas y funciona perfectamente.

En cuanto al de la basura. Conoces alguna manera diferente de hacerlo a lo que yo pienso?. Porque como yo lo pienso tengo que ingresar todos estos datos, y me parecen demasiados, que decis?:

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
Program Pr2Ej27;
Uses
Crt;
Var
Fecha: String;
OrgHog1,OrgHog2,OrgHog3, InorgHog1, InorgHog2,InorgHog3, ReciHog1,ReciHog2,ReciHog3: Integer;
 
Begin
Clrscr;
 Write('Ingrese la fecha: ')
  Readln(Fecha);
 Write('Ingrese el total de basura organica Hogar 1: ');
  Readln(OrgHog1);
   Write('Ingrese el total de basura organica Hogar 2: ');
  Readln(OrgHog2);
   Write('Ingrese el total de basura organica Hogar 3: ');
  Readln(OrgHog3);
 Write('Ingrese el total de basura inorganica Hogar 1: ');
  Readln(InorgHog1);
  Write('Ingrese el total de basura inorganica Hogar 2: ');
  Readln(InorgHog2);
  Write('Ingrese el total de basura inorganica Hogar 3: ');
  Readln(InorgHog3);
 Write('Ingrese el total de basura reciclable Hogar 1: ');
  Readln(ReciHog1);
   Write('Ingrese el total de basura reciclable Hogar 2: ');
  Readln(ReciHog2);
   Write('Ingrese el total de basura reciclable Hogar 3: ');
  Readln(ReciHog3);
 
 
 While Fecha <> *** do
  Begin
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ejercicio Basura Pascal

Publicado por ramon (2158 intervenciones) el 29/04/2013 12:57:11
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
{Mira esto}
 
 program recicla;
  uses
     crt;
  type
    niveles = record
         nivel : integer;
 contaminacion : integer;
      relacion : string[20];
         end;
 
    vecino = record
         fecha : string[12];
         bsorganica : integer;
       bsinorganica : integer;
       bsreciclable : integer;
               nive : niveles;
       end;
 
 
 
   const
      nuvecin = 5;
 
  var
    informe : array[1..nuvecin] of vecino;
    t, cont : integer;
    tecla : char;
    salir : boolean;
    orga, reci : integer;
 
 
   begin
      cont := 1;
    repeat
      clrscr;
      gotoxy(10,2);write('---- Entrada Datos ----');
      gotoxy(10,4);write('Fecha      : ');
      gotoxy(23,4);readln(informe[cont].fecha);
      gotoxy(10,5);write('Organica   : ');
      gotoxy(23,5);readln(informe[cont].bsorganica);
      gotoxy(10,6);write('Reciclable : ');
      gotoxy(23,6);readln(informe[cont].bsreciclable);
      informe[cont].bsinorganica := informe[cont].bsorganica +
                                    informe[cont].bsreciclable;
      gotoxy(10,8);write('Entra Mas Datos [S/N]');
      repeat
          tecla := upcase(readkey);
      until tecla in[#83,#78];
     if tecla = #78 then
     salir := true
   else
     cont := cont + 1;
     if cont > nuvecin then
     cont := nuvecin;
   until salir = true;
   writeln;
   for t := 1 to cont do
   begin
   writeln('  Fecha = ',informe[cont].fecha);
   reci := reci + informe[t].bsreciclable;
   orga := orga + informe[t].bsorganica;
   writeln('  Reciclable = ',reci,' Organica = ',orga);
   if  reci > orga then
   writeln('   Nivel De Contaminacion OK');
   if reci = orga - (orga div 2) then
   writeln('   Nivel De Contaminacion Normal');
   if reci <= orga then
   writeln('   Nivel De Contaminacion No OK');
   end;
   readln;
 end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar