Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. void ventas::estadisticas(int tipo,int annoini,int annofin) ///HECHO
  2. {
  3.     detalle.open(this->fichero, ios::in | ios::binary);
  4.     ifstream fprod(this->ficheroresumen, ios::in | ios::binary);
  5.     if (!detalle.fail() && !fprod.fail())
  6.     {
  7.         venta vent;
  8.         producto prod;
  9.         estadistica *estad=new estadistica [SALTO];
  10.         int nestad=0, nestadmax=SALTO;
  11.         for (int x=nestad; x<nestadmax; x++)
  12.         {
  13.             estad[x].codigo=-1;
  14.             estad[x].unidades=0;
  15.             estad[x].importe=0;
  16.         }
  17.         fprod.read((char *) &prod, sizeof(prod));
  18.         while(!fprod.eof())
  19.         {
  20.             if (prod.tipo==tipo)
  21.             {
  22.                 detalle.seekg(0, ios::beg);
  23.                 detalle.read((char *) &vent, sizeof(venta));
  24.                 while(!detalle.eof())
  25.                 {
  26.                     if (prod.producto==vent.producto &&(annoini<vent.fecha.anio && vent.fecha.anio<annofin))
  27.                     {
  28.                         if (nestad>=nestadmax)
  29.                         {
  30.                             nestadmax+=SALTO;
  31.                             estadistica *e=new estadistica [nestadmax];
  32.                             for (int i=0; i<nestad; i++)
  33.                                 e[i]=estad[i];
  34.                             estad=e;
  35.                             for (int x=nestad; x<nestadmax; x++)
  36.                             {
  37.                                 estad[x].codigo=-1;
  38.                                 estad[x].unidades=0;
  39.                                 estad[x].importe=0;
  40.                             }
  41.                         }
  42.                         estad[nestad].codigo=vent.producto;
  43.                         estad[nestad].unidades+=vent.unidades;
  44.                         estad[nestad].importe+=vent.importe;
  45.                         strcpy(estad[nestad].nombre, prod.nombre);
  46.                     }
  47.                     detalle.read((char *) &vent, sizeof(venta));
  48.                 }
  49.                 nestad++;
  50.             }
  51.             fprod.read((char *) &prod, sizeof(producto));
  52.         }
  53.         ///Ordenar las ventas segun el nº de unidades vendidas
  54.         int pos,ele;
  55.         for (pos=0; pos<nestad; pos++)
  56.             for (ele=nestad; ele>pos; ele--)
  57.                 if(estad[ele-1].unidades>estad[ele].unidades)
  58.                     intercambiarestadistica(estad[ele-1],estad[ele]);
  59.         int cont=0;
  60.         cout << "*** LISTA RESUMEN ESTADISTICA ***" << endl;
  61.         cout << " Intervalo de año elegido para la lista: " << annoini << "-" << annofin << endl;
  62.         cout << " Tipo de Producto: " << TIPO[tipo - 1] << " (" << tipo << ")\n";
  63.         cout << "____________________________________________" << endl;
  64.         while(cont<nestad && estad[cont].codigo!=-1)
  65.         {
  66.             cout << "Nombre de Porducto: " << estad[cont].nombre << endl;
  67.             cout << "Codigo del Producto: " << estad[cont].codigo << endl;
  68.             cout << "Unidades Vendidas: " << estad[cont].unidades << endl;
  69.             cout << "Importe: " << estad[cont].importe << endl;
  70.             cout << "_____________________________________________________\n";
  71.             cont++;
  72.         }
  73.         delete estad;
  74.     }
  75.     else
  76.         cout << "Fallo en apertura de ficheros.\n";
  77.     detalle.close();
  78.     fprod.close();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement