Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <limits.h>
- #include "funcionesAuxiliares.h"
- #include "ordenacion.h"
- #define EOF -1
- #define MAX_CARACTERES 30
- #define MAXDATOS 500
- using namespace std;
- int main(int argc, char** argv) {
- char a,b,c, tipoClima, tipoT, tipoH, tipoP;
- int codigo, cantCarac, dd, mm, aa;
- double temp, humedad, precip, vol;
- int FECHAS[MAXDATOS], cantDatos, indices[MAXDATOS];
- double CELSIUS[MAXDATOS], FAHRENHEIT[MAXDATOS], PRECIPITACIONES[MAXDATOS], HUMEDAD[MAXDATOS], VOLUMEN[MAXDATOS];
- //La primera linea indica como debe estar cordenado el reporte
- //Contiene uno o dos caracteres
- cin >> a;
- b = cin.peek();
- if(c != '\n')
- cin >> b;
- impEncabePrincipal(a);
- //El archivo
- while(1){
- impC('=',118);
- cout << endl;
- //Leo e nombre de la cuidad y el codigo
- cantCarac = 0;
- while(!(cin >> codigo)){
- cin.clear();
- while((c = cin.get()) != ' '){
- cantCarac++;
- cout.put(c);
- }
- cantCarac++;
- cout.put(c);
- }
- impC(' ',MAX_CARACTERES - cantCarac);
- cout << codigo;
- cantDatos = 0;
- while(1){
- for(int i=0; i<3; i++){
- cin >> tipoClima;
- if(tipoClima == 'T'){
- if(cin >> temp){
- tipoT = cin.get();
- if(tipoT == 'C'){
- CELSIUS[cantDatos] = temp;
- FAHRENHEIT[cantDatos] = temp*9/5 + 32;
- }
- else{
- FAHRENHEIT[cantDatos] = temp;
- CELSIUS[cantDatos] = (temp - 32)*5/9;
- }
- }
- else{
- cin.clear();
- CELSIUS[cantDatos] = INT_MIN;
- FAHRENHEIT[cantDatos] = INT_MIN;
- tipoT = cin.get();
- }
- }
- else if(tipoClima == 'H'){
- if(cin >> humedad){
- tipoH = cin.get();
- if(tipoH != '%')
- HUMEDAD[cantDatos] = humedad*100;
- else
- HUMEDAD[cantDatos] = humedad;
- }
- else{
- HUMEDAD[cantDatos] = INT_MIN;
- cin.clear();
- tipoH = cin.get();
- }
- }
- else if(tipoClima == 'P'){
- if(cin >> precip){
- tipoP = cin.get();
- if(tipoP == 'H')
- precip *= 60;
- else if(tipoP == 'S')
- precip /= 60;
- cin >> vol;
- PRECIPITACIONES[cantDatos] = vol/precip;
- }
- else{
- cin.clear();
- PRECIPITACIONES[cantDatos] = INT_MIN;
- tipoP = cin.get();
- }
- }
- }//fin del for
- //Leo la fecha
- dd = 0;
- mm = 0;
- aa = 0;
- cin >> aa;
- c=cin.peek();
- if(c == '/'){
- cin.get();
- mm = aa;
- cin >> aa;
- c = cin.peek();
- if(c == '/'){
- cin.get();
- dd = mm;
- mm = aa;
- cin >> aa;
- }
- }
- int fecha = aa*10000 + mm*100 + dd;
- FECHAS[cantDatos] = fecha;
- if(cin.get() == '\n') break;
- cantDatos++;
- }//fin del while(1)
- //Termino de leer todos los datos por cuidad
- //Toca ordenar
- inicializacionIndices(indices, cantDatos);
- if(a == 'T'){
- if(b == 'C')
- ordenar(CELSIUS, indices, cantDatos);
- else
- ordenar(FAHRENHEIT, indices, cantDatos);
- }
- else if(a == 'F')
- ordenar(FECHAS, indices, cantDatos);
- else if(a == 'H')
- ordenar(HUMEDAD, indices, cantDatos);
- else
- ordenar(PRECIPITACIONES, indices, cantDatos);
- impresion(FECHAS, CELSIUS, FAHRENHEIT, HUMEDAD, PRECIPITACIONES, cantDatos, indices);
- impC('-',118);
- cout << endl << setw(40) << "Promedio: " << setw(25) << " ";
- cout.precision(2);
- cout << fixed << setw(5) << promedio(CELSIUS, cantDatos);
- cout << fixed << setw(12) << promedio(FAHRENHEIT, cantDatos);
- cout << fixed << setw(12) << promedio(HUMEDAD, cantDatos);
- cout << fixed << setw(12) << promedio(PRECIPITACIONES, cantDatos);
- cout << endl;
- c = cin.peek();
- if(c == EOF) break;
- }
- return 0;
- }
- #ifndef FUNCIONESAUXILIARES_H //FuncionAuxiliar.h
- #define FUNCIONESAUXILIARES_H
- void impEncabePrincipal(char a);
- void impC(char , int);
- void impresion(int [], double [], double [], double [], double [], int , int []);
- double promedio(double [], int );
- #endif /* FUNCIONESAUXILIARES_H */
- #include <iomanip> //FuncionAuxiliar.cpp
- #include <iostream>
- #include <limits.h>
- #include "funcionesAuxiliares.h"
- using namespace std;
- void impEncabePrincipal(char a){
- cout << setw(65) << "REGISTRO CLIMATICO DEL PAIS" << endl;
- cout << setw(55) << "ORDENADO POR ";
- if( a == 'F') cout << "FECHA" << endl;
- else if( a == 'T') cout << "TEMPERATURA" << endl;
- else if( a == 'H') cout << "HUMEDAD" << endl;
- else if( a == 'P') cout << "PRECIPITACIONES" << endl;
- impC('=',118);
- cout << endl;
- cout << setw(12) << "CUIDAD";
- cout << setw(24) << "CODIGO";
- cout << setw(20) << "FECHA";
- cout << setw(23) << "TEMPERATURA";
- cout << setw(16) << "HUMEDAD";
- cout << setw(15) << "PRECIPITACION";
- cout << endl;
- cout << setw(80) << "C F";
- cout << setw(12) << "%";
- cout << setw(23) << "CANTIDAD/TIEMPO(min)";
- cout << endl;
- }
- void impC(char c, int n){
- for(int i=0; i<n; i++)
- cout.put(c);
- }
- void imprimirFecha(int fecha){
- int aa, mm, dd;
- aa = fecha/10000;
- mm = (fecha - aa*10000)/100;
- dd = fecha - (aa*10000 + mm*100);
- cout.fill('0');
- if(dd == 0)
- cout << "--/";
- else
- cout << setw(2) << dd << "/";
- if(mm == 0)
- cout << "--/";
- else
- cout << setw(2) << mm << "/";
- cout << setw(4) << aa;
- cout.fill(' ');
- }
- void imprimirDouble(double a){
- cout.precision(2);
- if(a == INT_MIN)
- cout << setw(12) << "--.--";
- else
- cout << fixed << setw(12) << a;
- }
- void impresion(int FECHAS[], double CELSIUS[], double FAHRENHEIT[], double HUMEDAD[], double PRECIPITACIONES[], int cantDatos, int indices[]){
- int dd, mm, aa;
- cout << setw(14) << " ";
- imprimirFecha(FECHAS[indices[0]]);
- imprimirDouble(CELSIUS[indices[0]]);
- imprimirDouble(FAHRENHEIT[indices[0]]);
- imprimirDouble(HUMEDAD[indices[0]]);
- imprimirDouble(PRECIPITACIONES[indices[0]]);
- cout << endl;
- for(int i=1; i<cantDatos; i++){
- //Imprimo la fecha
- cout << setw(48) << " ";
- imprimirFecha(FECHAS[indices[i]]);
- imprimirDouble(CELSIUS[indices[i]]);
- imprimirDouble(FAHRENHEIT[indices[i]]);
- imprimirDouble(HUMEDAD[indices[i]]);
- imprimirDouble(PRECIPITACIONES[indices[i]]);
- cout << endl;
- }
- }
- double promedio(double X[], int n){
- double suma = 0.0;
- for(int i=0; i<n ; i++)
- if(X[i] != INT_MIN)
- suma += X[i];
- return suma/n;
- }
- #ifndef ORDENACION_H //Ordenacion.H
- #define ORDENACION_H
- void inicializacionIndices(int [], int );
- template <typename T>
- void ordenar(T [], int [], int);
- template <typename T>
- void quickSort(T [], int [], int, int);
- void swap(int [], int , int);
- #endif /* ORDENACION_H */
- #include "ordenacion.h" //Ordenacion.cpp
- void inicializacionIndices(int X[], int n){
- for(int i=0; i<n; i++)
- X[i] = i;
- }
- template <typename T>
- void ordenar(T X[], int ind[], int n){
- quickSort(X, ind, 0, n-1);
- }
- template void ordenar(int [], int [], int );
- template void ordenar(double [], int [], int );
- template <typename T>
- void quickSort(T X[], int ind[], int izq, int der){
- int limite,i;
- if(izq>=der) return; //Condición de salida
- swap(ind,izq,(izq+der)/2); //Con el pivote se intercambia
- limite = izq;
- for(i=izq+1;i<=der;i++)
- if(X[ind[izq]] > X[ind[i]])
- swap(ind,++limite,i); //Condición de intercambio
- swap(ind,izq,limite);
- quickSort(X, ind, izq, limite-1);
- quickSort(X, ind, limite+1, der);
- }
- template void quickSort(int [], int [], int , int );
- template void quickSort(double [], int [], int , int );
- void swap(int X[], int i, int j){
- int temp = X[i];
- X[i] = X[j];
- X[j] = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement