Advertisement
xlujiax

Lab2_2016_2_v2

Sep 7th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.02 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /*
  8.  * File:   main.cpp
  9.  * Author: alulab14
  10.  *
  11.  * Created on 7 de septiembre de 2016, 10:28 AM
  12.  */
  13.  
  14. #include <cstdlib>
  15. #include <cstdio>
  16.  
  17. #define MaxNombreEstacion 35
  18.  
  19. using namespace std;
  20.  
  21. double calcularTiempo(int hrI, int minI, int segI, int hrF, int minF, int segF) {
  22.     double tiempo;
  23.     if (hrI > hrF) tiempo = (23 - hrI)*3600 + (59 - minI)*60 + (60 - segI);
  24.     else if (minI > minF) tiempo = (hrF - hrI)*3600 + (59 - minI)*60 + (60 - segF) + minF * 60 + segF;
  25.     else if (segI > segF) tiempo = (hrF - hrI - 1)*3600 + (minF - minI - 1)*60 + (60 - segF) + segF;
  26.     else tiempo = (hrF * 3600 + minF * 60 + segF)-(hrI * 3600 + minI * 60 + segI);
  27.     return tiempo;
  28. }
  29.  
  30. int main(int argc, char** argv) {
  31.     char c;
  32.     int codigo, tamanoNombre, hayfecha, contadorReg, contadorTotalReg;
  33.     int dd, mm, aaaa, ddAux, mmAux, aaaaAux, horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux, horaA, minA, segA;
  34.     int tamanoHoraI, tamanoHoraF, horaI, minI, segI, horaF, minF, segF;
  35.     int acumuladoTReg;
  36.     float precipitacion, precipitacionAux, precipitacionReg;
  37.     float promedio;
  38.     for (int i = 0; i < 80; i++) printf("=");
  39.     printf("\n");
  40.     printf("%-35s%s\n", " ", "INFORME DE PRECIPITACIONES");
  41.     for (int i = 0; i < 80; i++) printf("=");
  42.  
  43.     contadorTotalReg = 0;
  44.     while (1) {
  45.         printf("\n");
  46.         printf("%-36s%-32s%-10s", "  ESTACION", "CIUDAD", "DEPARTAMENTO");
  47.         printf("\n");
  48.         for (int i = 0; i < 80; i++) printf("-");
  49.         printf("\n");
  50.         tamanoNombre = 0;
  51.         while ((c = getchar()) != ',') { //Estacion
  52.             if (tamanoNombre < MaxNombreEstacion) {
  53.                 putchar(c);
  54.                 tamanoNombre++;
  55.             }
  56.         }
  57.         while (tamanoNombre < MaxNombreEstacion) {
  58.             putchar(' ');
  59.             tamanoNombre++;
  60.         }
  61.  
  62.         tamanoNombre = 0;
  63.         while ((c = getchar()) != ',') { //Ciudad
  64.             if (tamanoNombre < MaxNombreEstacion) {
  65.                 putchar(c);
  66.                 tamanoNombre++;
  67.             }
  68.         }
  69.         while (tamanoNombre < MaxNombreEstacion - 3) {
  70.             putchar(' ');
  71.             tamanoNombre++;
  72.         }
  73.  
  74.         tamanoNombre = 0;
  75.         while ((c = getchar()) != ':') { //Departamento
  76.             if (tamanoNombre < MaxNombreEstacion) {
  77.                 putchar(c);
  78.                 tamanoNombre++;
  79.             }
  80.         }
  81.         if (c == ':') printf("\n");
  82.         printf("\n%-15s%-15s%-20s%-20s%-5s\n", "    Fecha", "cantidad", "Tiempo Total", "Total Llovido", "Promedio");
  83.  
  84.         //printf("\n");
  85.  
  86.         scanf("%d/%d/%d", &dd, &mm, &aaaa); //Lectura Fecha Inicial    
  87.         //printf("  %d/%d/%-2d",dd,mm,aaaa);        
  88.         horaI = minI = segI = horaF = minF = segF = 0;
  89.         scanf("%d:%d:%d", &horaI, &minI, &segI);
  90.         scanf("%d:%d:%d", &horaF, &minF, &segF);
  91.         scanf("%fl", &precipitacion);
  92.  
  93.         contadorReg = 1;
  94.         acumuladoTReg = 0;
  95.         precipitacionReg = precipitacion;
  96.         while (1) {
  97.             hayfecha = scanf("%d/%d/%d", &ddAux, &mmAux, &aaaaAux); //Lectura Fecha Secundaria
  98.             if (hayfecha == 3) { // Si encuentra fecha
  99.                 scanf("%d:%d:%d", &horaIaux, &minIaux, &segIaux);
  100.                 scanf("%d:%d:%d", &horaFaux, &minFaux, &segFaux);
  101.                 scanf("%fl", &precipitacionAux);
  102.                 if ((dd == ddAux) && (mm = mmAux) && (aaaa == aaaaAux)) { //Si encontro fecha igual
  103.                     contadorReg++;
  104.                     acumuladoTReg += calcularTiempo(horaI, minI, segI, horaF, minF, segF) + calcularTiempo(horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux);
  105.                     //acumuladoTReg += ((horaF*3600 + minF*60 + segF) - (horaI*3660 + minI*60 + segI)) + ((horaFaux*3600 + minFaux*60 + segFaux) - (horaIaux*3660 + minIaux*60 + segIaux));                      
  106.                     precipitacionReg += precipitacionAux;
  107.                 } else {
  108.                     horaA = (int) acumuladoTReg / 3600;
  109.                     minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  110.                     segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  111.                     promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  112.                     printf("  %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  113.                     dd = ddAux;
  114.                     mm = mmAux;
  115.                     aaaa = aaaaAux;
  116.                     horaI = horaIaux;
  117.                     minI = minIaux;
  118.                     segI = segIaux;
  119.                     horaF = horaFaux;
  120.                     minF = minFaux;
  121.                     segF = segFaux;
  122.                     precipitacion = precipitacionAux;
  123.                 }
  124.  
  125.             }
  126.             if (hayfecha == 0) { //Fin de linea
  127.                 horaA = (int) acumuladoTReg / 3600;
  128.                 minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  129.                 segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  130.                 promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  131.                 printf("  %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  132.                 break;
  133.             } else if (hayfecha == EOF) {
  134.                 horaA = (int) acumuladoTReg / 3600;
  135.                 minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  136.                 segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  137.                 promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  138.                  printf("  %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  139.                 break;
  140.             }
  141.         }
  142.         if (hayfecha == EOF)
  143.             break;
  144.     }
  145.    
  146.  
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement