/*
maps.cpp

	Ejemplo de uso de mapas, lee productos y va acumulando las cantidades y precios,
	al final imprime el resumen de todos los producto leídos con el costo total(factura)

	Ariel Medina
*/

#include <iostream>
#include <string>
#include <map>

using namespace std;

struct producto	{
string descripcion;
double precio;
double cantidad;
double total;
};

int main()
{
map<string,producto> factura;
string clave;
char descripcion[256];
double cantidad,total_factura=0.00;

cerr<<"Clave (CTRL+Z para terminar): ";
while(cin>>clave)
	{
	if(factura[clave].descripcion.empty())
		{
		cerr<<"Descripción: ";
		cin.get();
		cin.getline(descripcion,256);
		factura[clave].descripcion=descripcion;
		cerr<<"Precio: ";
		cin>>factura[clave].precio;
		factura[clave].cantidad=0.00;
		}
	cerr<<"Cantidad: ";
	cin>>cantidad;
	factura[clave].cantidad+=cantidad;
	factura[clave].total=factura[clave].cantidad*factura[clave].precio;
	cerr<<"Clave (CTRL+Z para terminar): ";
	}

cout<<"\nClave\tDescripción\tCantidad\tPrecio\tSubtotal\n";
for(map<string,producto>::iterator it=factura.begin(); it!=factura.end(); ++it)
	{
	cout<<it->first<<'\t'<<it->second.descripcion<<'\t'<<it->second.cantidad<<'\t'<<it->second.precio<<'\t'<<it->second.total<<'\n';
	total_factura+=it->second.total;
	}
cout<<"\nTotal de factura: "<<total_factura<<'\n';

return 0;
}