-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_tienda.cpp
More file actions
123 lines (97 loc) · 4.63 KB
/
main_tienda.cpp
File metadata and controls
123 lines (97 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <string>
#include "tienda.h"
// Asegúrate de que tienda.h incluye a su vez a lista_dinamica.h y tabla_ordenada.h
using namespace std;
int main() {
// Instanciamos una tienda de strings (nombre del producto)
Tienda<string> miTienda;
cout << "=== APERTURA DE LA TIENDA ===" << endl;
// ---------------------------------------------------------
// 1. AÑADIR PRODUCTOS
// ---------------------------------------------------------
cout << "\n[1] Llenando el almacen..." << endl;
miTienda.anadir(10, "Manzanas"); // Stock de sobra
miTienda.anadir(5, "Peras"); // Stock medio
miTienda.anadir(2, "Leche"); // Stock bajo (debería salir en reposición)
miTienda.anadir(0, "Pan"); // Sin stock (solo catálogo)
// Añadimos más stock a un producto existente
miTienda.anadir(5, "Manzanas");
try {
cout << "Stock actual de Manzanas (deberia ser 15): " << miTienda.consultar("Manzanas") << endl;
cout << "Stock actual de Peras (deberia ser 5): " << miTienda.consultar("Peras") << endl;
cout << "Stock actual de Leche (deberia ser 2): " << miTienda.consultar("Leche") << endl;
cout << "Stock actual de Pan (deberia ser 0): " << miTienda.consultar("Pan") << endl;
} catch (EProductoNoExiste &e) {
cout << "Error: " << e.mensaje() << endl;
}
// ---------------------------------------------------------
// 2. VENDER PRODUCTOS
// ---------------------------------------------------------
cout << "\n[2] Realizando ventas..." << endl;
try {
cout << "Vendiendo 1 Peras..." << endl;
miTienda.vender("Peras");
cout << "Quedan " << miTienda.consultar("Peras") << " Peras." << endl;
cout << "Vendiendo 1 Leche..." << endl;
miTienda.vender("Leche");
cout << "Quedan " << miTienda.consultar("Leche") << " de Leche." << endl;
} catch (EStockInsuficiente &e) {
cout << "Error de stock: " << e.mensaje() << endl;
} catch (EProductoNoExiste &e) {
cout << "Error de producto: " << e.mensaje() << endl;
}
// ---------------------------------------------------------
// 3. PROBAR ERRORES (EXCEPCIONES)
// ---------------------------------------------------------
cout << "\n[3] Probando errores y excepciones..." << endl;
// Caso A: Vender producto que no existe
try {
cout << "Intentando vender 'Coches'..." << endl;
miTienda.vender("Coches");
} catch (EProductoNoExiste &e) {
cout << "-> Excepcion atrapada correctamente: " << e.mensaje() << endl;
}
// Caso B: Vender producto sin stock (Pan tiene 0)
try {
cout << "Intentando vender 'Pan'..." << endl;
miTienda.vender("Pan");
} catch (EStockInsuficiente &e) {
cout << "-> Excepcion atrapada correctamente: " << e.mensaje() << endl;
}
// ---------------------------------------------------------
// 4. LISTAR INVENTARIO (Recorrer lista devuelta)
// ---------------------------------------------------------
cout << "\n[4] Generando Inventario Completo..." << endl;
// Obtenemos la lista
TListaDinamica<ParProductoCantidad<string> > listaInv = miTienda.inventario();
if (listaInv.esVacio()) {
cout << "El inventario esta vacio." << endl;
} else {
// Recorremos la lista destruyéndola (o copiándola si prefieres) para mostrar
// Como 'ParProductoCantidad' es un struct simple, imprimimos sus campos manualmente
while (!listaInv.esVacio()) {
ParProductoCantidad<string> item = listaInv.primero();
cout << " - Producto: " << item.producto
<< " \t| Stock: " << item.cantidad << endl;
listaInv.quitaPrim();
}
}
// ---------------------------------------------------------
// 5. LISTAR REPOSICION (Stock < 3)
// ---------------------------------------------------------
cout << "\n[5] Generando Lista de Reposicion (Stock < 3)..." << endl;
TListaDinamica<string> listaRep = miTienda.reposicion();
if (listaRep.esVacio()) {
cout << "No hay nada que reponer." << endl;
} else {
while (!listaRep.esVacio()) {
string prod = listaRep.primero();
cout << " (!) ALERTA: Reponer " << prod << endl;
listaRep.quitaPrim();
}
}
// Nota: Deberían salir "Leche" (quedaba 1) y "Pan" (quedaban 0).
cout << "\n=== CIERRE DE LA TIENDA ===" << endl;
return 0;
}