Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Matias Proietti 160.096-5
- // pablosz@gmail.com
- #ifndef _MAIN
- #define _MAIN
- #include <iostream>
- #include "biblioteca/tads/Arr.hpp"
- #include "biblioteca/tads/Map.hpp"
- #include "biblioteca/tads/List.hpp"
- #include "biblioteca/tads/Stack.hpp"
- #include "biblioteca/tads/Queue.hpp"
- #include "biblioteca/funciones/strings.hpp"
- #include "biblioteca/funciones/tokens.hpp"
- #include "biblioteca/funciones/files.hpp"
- using namespace std;
- /* listNext empieza por el valor 0. Es decir listNext devuelve 0 y despues
- * se mueve a 1
- *
- * Seek empieza por el valor 0
- * fileSize retorna la cantidad de elementos de tipo T que contiene el file
- */
- template <typename T>
- T tail(Node<T>*& p, Node<T>*& q)
- {
- // retorna (sin desencolar) el valor del ultimo elemento de la cola
- return q->info;
- }
- // Estructuras por defecto
- struct FechaHora
- {
- };
- struct Llamada
- {
- int nroOri;
- int nroDes;
- int min;
- FechaHora fec;
- };
- struct Abonado
- {
- // ordenado x idAbo
- int idAbo;
- int nroCel;
- int idPlan;
- string nombre;
- string direcc;
- };
- struct Plan
- {
- int idPlan;
- string desc;
- double valor;
- int minLibres;
- double minExed;
- bool comunidad;
- };
- // Estructuras propias
- struct Titular
- {
- int nroOri;
- int mins;
- string nombre;
- };
- struct Inconsistente
- {
- int nroOri;
- Arr<int> celulares;
- Arr<FechaHora> fechas;
- };
- string fechaToString(FechaHora a)
- {
- return "hardcodeado";
- }
- int fechaHoraCmp(FechaHora a, FechaHora b)
- {
- return 1;
- }
- template<typename T,typename K>
- int cmpInt(T a, K b)
- {
- return a.nroOri - b;
- }
- int main()
- {
- // Se abren los archivos y se crean las listas necesarias
- FILE* fLlam = fopen("LLAMADAS.DAT", "r+b");
- FILE* fAbon = fopen("ABONADOS.DAT", "r+b");
- FILE* fPlan = fopen("PLANES.DAT", "r+b");
- List<Titular> titulares = listCreate<Titular>();
- List<Inconsistente> inconsistentes = listCreate<Inconsistente>();
- // Se inicializan las variables a utilizar (algunas se podrian reusar pero
- // para ayudar a la legibilidad se dejan separadas).
- // Algunas podrian no llegar a usarse segun los datos de la compania telefonica
- // se inicializan todas para ayudar a la legibilidad del codigo.
- FechaHora ultimaFecha;
- bool pertenece = false;
- bool primerRun = true;
- Llamada llamada;
- Abonado abonado;
- Titular* aux1;
- Titular* nuevo;
- Inconsistente* aux2;
- Inconsistente* nuevoInc;
- Arr<int> nuevocelulares;
- Arr<FechaHora> nuevofechas;
- Titular* aux3;
- Inconsistente* aux4;
- int length;
- int celular;
- FechaHora fecha;
- for (int i=0; i<fileSize<Llamada>(fLlam);i++)
- {
- // Workaround para evitar un skip de llamada.
- // En el primer loop lee el proximo y asigna la ultfecha
- if (primerRun)
- {
- llamada = read<Llamada>(fLlam);
- ultimaFecha = llamada.fec;
- primerRun = false;
- }
- // Lee las llamadas y opera hasta que la fecha cambie
- while ((fechaHoraCmp(ultimaFecha, llamada.fec)==0) and (i<fileSize<Llamada>(fLlam)))
- {
- // Buscar el numero de origen de la llamada en la lista de abonados
- // para ver si pertenece a la compania
- for (int j=0; j<fileSize<Abonado>(fAbon);j++)
- {
- abonado = read<Abonado>(fAbon);
- if (abonado.nroCel == llamada.nroOri)
- {
- pertenece = true;
- break;
- }
- }
- seek<Abonado>(fAbon, 0);
- if (pertenece)
- {
- pertenece = false;
- // Revisar que no este en la lista de titulares
- aux1 = listFind<Titular, int>(titulares, llamada.nroOri, cmpInt);
- if (aux1!=NULL)
- {
- // Si ya esta en la lista, solo sumar minutos
- aux1->mins = aux1->mins + llamada.min;
- }
- else
- {
- // Si no esta en la lista, agregar a la lista
- nuevo = new Titular();
- nuevo->mins = llamada.min;
- nuevo->nombre = abonado.nombre;
- nuevo->nroOri = llamada.nroOri;
- listAdd<Titular>(titulares, *nuevo);
- }
- }
- else
- {
- // Si no pertenece debo registrar los llamados y las fechas
- // Revisar que no este en la lista de inconsistentes
- aux2 = listFind<Inconsistente, int>(inconsistentes, llamada.nroOri, cmpInt);
- if (aux2!=NULL)
- {
- // Si ya esta en la lista, solo agregar llamada y fecha a los arrays
- arrAdd<int>(aux2->celulares, llamada.nroDes);
- arrAdd<FechaHora>(aux2->fechas, llamada.fec);
- }
- else
- {
- // Si no esta en la lista, agregar a la lista
- nuevocelulares = arrCreate<int>(50);
- nuevofechas = arrCreate<FechaHora>(50);
- arrAdd<int>(nuevocelulares, llamada.nroDes);
- arrAdd<FechaHora>(nuevofechas, llamada.fec);
- nuevoInc = new Inconsistente();
- nuevoInc->nroOri = llamada.nroOri;
- nuevoInc->celulares = nuevocelulares;
- nuevoInc->fechas = nuevofechas;
- listAdd<Inconsistente>(inconsistentes, *nuevoInc);
- }
- }
- // Pasar a la siguiente llamada
- llamada = read<Llamada>(fLlam);
- }
- // Si llegue aca es porque cambio la fecha.
- // Hago output de la lista de titulares.
- cout << "Fecha: " << fechaToString(ultimaFecha) << endl;
- cout << "+-------+--------+-------+" << endl;
- cout << "|Titular|Nro. Cel|Sum Min|" << endl;
- cout << "+-------+--------+-------+" << endl;
- while (listHasNext<Titular>(titulares))
- {
- aux3 = listNext<Titular>(titulares);
- cout << "|" << aux3->nombre << "|" << aux3->nroOri << "|" << aux3->mins << "|" << endl;
- }
- cout << "+-------+--------+-------+" << endl;
- cout << endl << endl;
- listReset<Titular>(titulares);
- // Vacio la lista para comenzar con la siguiente fecha
- listFree<Titular>(titulares);
- }
- // Una vez que termino, imprimo la lista de inconsistentes
- cout << endl << endl << endl;
- cout << "+----------+--------------------------------+" << endl;
- cout << "|Numero Cel|Llamadas Realizadas |" << endl;
- cout << "+----------+--------------------------------+" << endl;
- while (listHasNext<Inconsistente>(inconsistentes))
- {
- aux4 = listNext<Inconsistente>(inconsistentes);
- cout << "|" << aux4->nroOri << "|";
- length = arrLength<int>(aux4->celulares);
- for (int i=0; i<length;i++)
- {
- celular = *arrGet<int>(aux4->celulares, i);
- fecha = *arrGet<FechaHora>(aux4->fechas, i);
- cout << "(" << celular << "," << fechaToString(fecha) << ")";
- if (i<length-1)
- cout << ", ";
- }
- cout << "|" << endl;
- }
- cout << "+----------+--------------------------------+" << endl;
- cout << endl << endl;
- fclose(fLlam);
- fclose(fAbon);
- fclose(fPlan);
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement