#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
struct Producto {
string nombre;
float precio;
int cantidad;
string lugar;
};
void maximo( const vector<Producto> v );
void mejoresLaAlameda( const vector<Producto> v );
void minimo( const vector<Producto> v );
void menosVendidoLaAlameda( const vector<Producto> v );
int main()
{
Producto p;
vector<Producto> v;
char opcion;
cout << "\nIntroducir datos:\n";
do {
cout << "\nNombre del producto: ";
getline( cin, p.nombre );
cout << "Precio de venta: ";
cin >> p.precio;
cout << "Unidades vendidas: ";
cin >> p.cantidad;
cin.ignore( 80, '\n' );
cout << "Lugar de mayor venta: ";
getline( cin, p.lugar );
v.push_back( p );
cout << "\nIntroducir datos de otro producto (S/n): ";
cin >> opcion;
opcion = toupper( opcion );
cin.ignore( 80, '\n' );
} while( opcion == 'S' );
maximo( v );
mejoresLaAlameda( v );
minimo( v );
menosVendidoLaAlameda( v );
return 0;
}
void maximo( const vector<Producto> v )
{
int max, pos;
for( int i = 0; i < v.size(); i++ ) {
if( i == 0 || v[i].cantidad > max ) {
max = v[i].cantidad;
pos = i;
}
}
cout << "\nProducto mas vendido: " << v[pos].nombre << endl;
}
void mejoresLaAlameda( const vector<Producto> v )
{
int count = 0;
for( int i = 0; i < v.size(); i++ )
if( v[i].lugar == "La Alameda" ) count++;
cout << "\nCantidad de producto que mejor se venden en La Alameda: " << count << endl;
}
void minimo( const vector<Producto> v )
{
int min, pos;
for( int i = 0; i < v.size(); i++ ) {
if( i == 0 || v[i].cantidad < min ) {
min = v[i].cantidad;
pos = i;
}
}
cout << "\nProducto menos vendido: " << v[pos].nombre << endl;
}
void menosVendidoLaAlameda( const vector<Producto> v )
{
int pos = -1;
long int min = 1000000000;
for( int i = 0; i < v.size(); i++ ) {
if( v[i].cantidad < min && v[i].lugar == "La Alameda" ) {
min = v[i].cantidad;
pos = i;
}
}
cout << "\nProducto menos vendido en La Alameda: ";
pos == -1 ? cout << "Sin venta" << endl : cout << v[pos].nombre << endl;
}