Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ventas::estadisticas(int tipo,int annoini,int annofin) ///HECHO
- {
- detalle.open(this->fichero, ios::in | ios::binary);
- ifstream fprod(this->ficheroresumen, ios::in | ios::binary);
- if (!detalle.fail() && !fprod.fail())
- {
- venta vent;
- producto prod;
- estadistica *estad=new estadistica [SALTO];
- int nestad=0, nestadmax=SALTO;
- for (int x=nestad; x<nestadmax; x++)
- {
- estad[x].codigo=-1;
- estad[x].unidades=0;
- estad[x].importe=0;
- }
- fprod.read((char *) &prod, sizeof(prod));
- while(!fprod.eof())
- {
- if (prod.tipo==tipo)
- {
- detalle.seekg(0, ios::beg);
- detalle.read((char *) &vent, sizeof(venta));
- while(!detalle.eof())
- {
- if (prod.producto==vent.producto &&(annoini<vent.fecha.anio && vent.fecha.anio<annofin))
- {
- if (nestad>=nestadmax)
- {
- nestadmax+=SALTO;
- estadistica *e=new estadistica [nestadmax];
- for (int i=0; i<nestad; i++)
- e[i]=estad[i];
- estad=e;
- for (int x=nestad; x<nestadmax; x++)
- {
- estad[x].codigo=-1;
- estad[x].unidades=0;
- estad[x].importe=0;
- }
- }
- estad[nestad].codigo=vent.producto;
- estad[nestad].unidades+=vent.unidades;
- estad[nestad].importe+=vent.importe;
- strcpy(estad[nestad].nombre, prod.nombre);
- }
- detalle.read((char *) &vent, sizeof(venta));
- }
- nestad++;
- }
- fprod.read((char *) &prod, sizeof(producto));
- }
- ///Ordenar las ventas segun el nº de unidades vendidas
- int pos,ele;
- for (pos=0; pos<nestad; pos++)
- for (ele=nestad; ele>pos; ele--)
- if(estad[ele-1].unidades>estad[ele].unidades)
- intercambiarestadistica(estad[ele-1],estad[ele]);
- int cont=0;
- cout << "*** LISTA RESUMEN ESTADISTICA ***" << endl;
- cout << " Intervalo de año elegido para la lista: " << annoini << "-" << annofin << endl;
- cout << " Tipo de Producto: " << TIPO[tipo - 1] << " (" << tipo << ")\n";
- cout << "____________________________________________" << endl;
- while(cont<nestad && estad[cont].codigo!=-1)
- {
- cout << "Nombre de Porducto: " << estad[cont].nombre << endl;
- cout << "Codigo del Producto: " << estad[cont].codigo << endl;
- cout << "Unidades Vendidas: " << estad[cont].unidades << endl;
- cout << "Importe: " << estad[cont].importe << endl;
- cout << "_____________________________________________________\n";
- cont++;
- }
- delete estad;
- }
- else
- cout << "Fallo en apertura de ficheros.\n";
- detalle.close();
- fprod.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement