-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
92 lines (83 loc) · 1.87 KB
/
main.cpp
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
#include "Lista.h"
#include <iostream>
#include <string>
using namespace std;
Lista* lista = new Lista();
void Listar()
{
cout << endl << endl;
int i = 1;
Elemento* e = lista->GetPrimer();
while(e != NULL)
{
cout << i << "- " << e->GetNombre() << " " << e->GetCantidad() << endl;
e = e->GetSiguiente();
i++;
}
if(i == 1)
{
cout << endl << "** Lista vacía **" << endl;
}
cout << endl << endl;
}
void Introducir()
{
string nombre;
int cantidad;
cout << "Introducir el nombre del artículo: ";
cin >> nombre;
cout << "Introduzca la cantidad del nuevo artículo: ";
cin >> cantidad;
Elemento* elemento = new Elemento(nombre, cantidad);
lista->Agregar(elemento);
cout << "-- Artículo Agregado. Presione ENTER para regresar al menú principal--" << endl;
getline(cin, nombre);
cout << endl;
}
void Eliminar()
{
int indice = 0;
Listar();
cout << "Elija el artículo a eliminar => ";
cin >> indice;
lista->Eliminar(indice - 1);
cout << endl;
Listar();
cout << endl;
}
void MostrarMenu()
{
int opcion = 0;
do
{
cout << "1- Listar artículos" << endl;
cout << "2- Introducir artículo" << endl;
cout << "3- Eliminar Artículo" << endl;
cout << "4- Salir" << endl;
cout << "Elija una opción => ";
cin >> opcion;
switch(opcion)
{
case 1:
Listar();
break;
case 2:
Introducir();
break;
case 3:
Eliminar();
break;
case 4:
exit(0);
break;
default:
cout << "Opción inválida" << endl;
break;
}
}while(opcion != 4);
}
int main()
{
MostrarMenu();
return 0;
}