/** * Represent a shopping store * * @author Programacion Concurrente * @version 2025/Oct/10 * * Primer examen parcial * * Grupo 3 * **/ #include // std::string #include // calloc #include "tienda.h" /** * Default contructor * Create a store with random filled values for prices and weights * **/ Tienda::Tienda( int items, int capacidadCarrito ) { int item; srand( getpid() ); this->articulos = items; this->capacidadCarrito = capacidadCarrito; this->pesos = (int *) calloc( items, sizeof( int ) ); this->precios = (int *) calloc( items, sizeof( int ) ); for ( item = 0; item < items; item++ ) { this->pesos[ item ] = 1 + (random() & 15); this->precios[ item ] = 10 + (random() & 15); } } /** * Parameter constructor * @param int items quantity * @param int * array with items' weights * @param int * array with items' values * **/ Tienda::Tienda( int capacidadCarrito, int items, const int * pesos, const int * precios ) { int item; this->capacidadCarrito = capacidadCarrito; this->articulos = items; this->pesos = (int *) calloc( items, sizeof( int ) ); this->precios = (int *) calloc( items, sizeof( int ) ); for ( item = 0; item < items; item++ ) { this->pesos[ item ] = pesos[ item ]; this->precios[ item ] = precios[ item ]; } } /** * * **/ Tienda::~Tienda() { free( this->pesos ); free( this->precios ); } /** * Return a String with store items **/ std::string Tienda::toString() { std::string result = ""; int item; result += "Tienda con " + std::to_string( this->articulos ) + " artículos y capacidad de carrito " + std::to_string( this->capacidadCarrito ) + "\n"; result += "Pesos = { "; for ( item = 0; item < this->articulos; item++ ) { result += std::to_string( this->pesos[ item ] ); if ( item < this->articulos - 1 ) { result += ", "; } } result += " }\nPrecios = { "; for ( item = 0; item < articulos; item++ ) { result += std::to_string( this->precios[ item ] ); if ( item < this->articulos - 1 ) { result += ", "; } } result += " }\n"; return result; } /** * * Coloca artículos en el carrito para maximizar ganancias sin pasarse de un peso establecido * **/ int llenarCarrito() { return 0; }