Advertisement
Lbit

Pregunta 1 PC2 2016-2

Sep 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.12 KB | None | 0 0
  1. program pregunta1;
  2. Const MaxLine=120;
  3.  
  4.  
  5. Procedure makeLn(var archOut:Text;ch:Char);
  6. var x:Integer;
  7. begin
  8.      for x:=1 to MaxLine do write(archOut,ch);
  9.      writeln(archOut);
  10. end;
  11.  
  12. Procedure formato2(var archOut:Text; dato1,dato2,dato3:Integer; ch:Char);
  13. begin
  14.      If dato1 <10 then write(archout,'0',dato1,ch) else
  15.         if dato1=0 then write(archout,'00',ch) else
  16.         write(archout,dato1,ch);
  17.  
  18.      If dato2 <10 then write(archout,'0',dato2,ch) else
  19.         if dato2=0 then write(archout,'00',ch) else
  20.         write(archout,dato2,ch);
  21.  
  22.      If dato3 <10 then write(archout,'0',dato3) else
  23.         if dato3=0 then write(archout,'00') else
  24.         write(archout,dato3);
  25. end;
  26.  
  27. var nombArchIn,estac,ciudad,depar:String;
  28.     archIn, archOut:Text;
  29.     dd,mm,aa,regTotal,regF,diasTotal,fecha,h1,m1,s1,h2,m2,s2,tiempo,
  30.     tiempoF,fini,ffinal:Integer;
  31.     montoTotal,monto,montoF:Real;
  32.     hayfechas:Boolean;
  33.  
  34. begin
  35.   //Procesar archivos
  36.   write('Ingrese nombre del archivo: ');
  37.   readln(nombarchin);
  38.   assign(archIn, nombarchin);
  39.   reset(archIn);
  40.   assign(archOut, 'Reporte.txt');
  41.   rewrite(archOut);
  42.  
  43.   //Crear Encabezado
  44.   makeLn(archOut,'=');
  45.   writeln(archout, 'INFORME DE PRECIPITACIONES':55);
  46.  
  47.   //Procesar por cede
  48.   while not eof(archIn) do begin
  49.         //Leer cede
  50.         readln(archin, estac);
  51.         readln(archin, ciudad);
  52.         readln(archin, depar);
  53.         //Imprimir cede
  54.         writeln(archOut, 'ESTACION', 'CIUDAD':40, 'DEPARTAMENTO':40);
  55.         writeln(archOut, estac, ciudad:40, depar:40);
  56.         makeLn(archOut,'=');
  57.         writeln(archOut, 'Fecha', 'Cantidad':20, 'Tiempo total':20,
  58.                          'Total llovido':20, 'Promedio':20);
  59.  
  60.         //Procesar fechas
  61.         hayfechas:=false;
  62.         regTotal:=0;
  63.         diasTotal:=0;
  64.         montoTotal:=0;
  65.         repeat
  66.               readln(archin,dd, mm,aa);
  67.               fecha:= aa*10000+mm*100+dd;
  68.  
  69.               //Verificar
  70.               if dd<>0 then begin
  71.  
  72.                 //Procesar datos
  73.                 regF:=0;
  74.                 tiempoF:=0;
  75.                 montoF:=0;
  76.                 while not eoln(archin) do begin
  77.                       read(archin, h1,m1,s1,h2,m2,s2,monto);
  78.                       inc(regF);
  79.                       tiempo:= (h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
  80.                       inc(tiempoF,tiempo);
  81.                       montoF:= montoF + monto;
  82.                 end;
  83.                 readln(archin);
  84.  
  85.                 //Imprimir Datos
  86.                 formato2(archout,dd,mm,aa,'/');
  87.                 write(archout,regF:15);
  88.                 h1:=tiempoF div 3600;
  89.                 m1:=(tiempoF mod 3600)div 60;
  90.                 s1:=tiempoF mod 60;
  91.                 write(archout,' ':10);
  92.                 formato2(archout,h1,m1,s1,':');
  93.                 writeln(archout, montoF:15:2,' mm', montoF/(tiempoF div 60):15:2,
  94.                                 ' mm/min');
  95.  
  96.                 if not hayfechas then begin
  97.                    fini:=fecha;
  98.                    ffinal:=fecha;
  99.                    hayfechas:=not(hayfechas);
  100.                 end
  101.                 else begin
  102.                      if fecha < fini then fini:=fecha;
  103.                      if fecha > ffinal then ffinal:=fecha;
  104.                 end;
  105.                 //Guardar Info
  106.                 inc(regTotal, regF);
  107.                 inc(diasTotal);
  108.                 montoTotal:= montoTotal + montoF;
  109.  
  110.               end;
  111.  
  112.         until dd=0;
  113.  
  114.         //Imprimir Resumen
  115.         makeLn(archOut, '-');
  116.         writeln(archout,'Resumen:');
  117.         write(archout,'Fecha inicial: ');
  118.         formato2(archout, fini mod 100, fini mod 10000 div 100, fini div 10000, '/');
  119.         write(archout,'Fecha final: ':15);
  120.         formato2(archout, ffinal mod 100, ffinal mod 10000 div 100, ffinal div 10000, '/');
  121.         writeln(archout);
  122.         writeln(archout,'Cantidad total de registros: ',regTotal,
  123.                         'Cantidad de dias registrados: ':35 ,diasTotal,
  124.                         'Total llovido en el periodo: ':35,montoTotal:0:2);
  125.         makeLn(archOut,'=');
  126.  
  127.   end;
  128.  
  129.   //Cerrar Archivo
  130.   close(archOut);
  131. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement