-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
269 lines (242 loc) · 9.57 KB
/
main.cpp
File metadata and controls
269 lines (242 loc) · 9.57 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include "Pedido.h"
#include "Admin.h"
//#include "Producto.h"
using namespace std;
//NO TOCAR O LOS MATO
//Variables GLOBALES //Vector con todos los pasajeros
void menuAdmin(Admin);
void menuCliente(Cliente);
vector<Producto> menuCarrito();
//Nombre:filldata
//Descripcion: Metodo para llenar los objetos y vectores PRODUCTO
//
//Entrada:
//
//Salida:
vector<Producto> Productos;
void filldata(){
//Variables Producto
string texto;
int cantidad;
int cont=0;
double precio;
Producto producto;
//Personas
//Se realiza una lectura en el archivo contenedor de productos
ifstream MyReadFile("productos.txt");
while (getline (MyReadFile, texto)) {//mientras que existan lineas en el archivo
istringstream ss(texto); //Agarra lo que haya en la linea y lo pone como string
do {
string word;
ss >> word; //se crea un string por linea y va rellenando el objeto producto
if(cont== 0){
producto.setNombre(word);
}else if(cont== 1){
precio = stoi(word);
producto.setPrecioUnitario(precio);
}else if(cont== 2){
cantidad = stoi(word); //stoi convierte de valor string a valor numerico
producto.setCantidad(cantidad);
}
cont++;
} while (ss);
Productos.push_back(producto); //añadimos el objeto producto al vector productos
cont=0;
}
MyReadFile.close(); //CERRAMOS EL ARCHIVO
}
int main(){
//filldata();
//cout << Productos[0].getNombreProducto()<< endl; //USAMOS EL METODO GET NOMBRE EN EL OBJETO GUARDADO EN EL VECTOR PRODUCTOS EN LA POSICION 0
//cout << Productos[0].getPrecioProducto()<< endl;
cout << "---------------------------------------------------------" << endl;
printf(" BIENVENIDO A NUESTRA TIENDA ONLINE: \n");
cout << "---------------------------------------------------------" << endl;
int opc;
do {
printf("Ingrese: \n1: Login \n2: Registro\n"); printf("Elija una opción: "); cin >> opc;
cout << "---------------------------------------------------------" << endl;
switch (opc){
case 1: {//LOGIN
bool clave = false, cuentaExiste = false;
User usuario;
string correo; cout << "Ingrese su correo: "; cin >> correo;
string contrasena; cout << "Ingrese su contraseña: "; cin >> contrasena;
cout << "---------------------------------------------------------" << endl;
usuario.setUserEmail(correo);
usuario.setUserPassword(contrasena);
usuario = usuario.login(usuario, clave, cuentaExiste);
if (cuentaExiste) {
if (clave){ // Si es true el usuario es Admin
printf("Bienvenido %s, eres Admin\n", usuario.getUserName().c_str());
cout << "---------------------------------------------------------" << endl;
Admin adminp(usuario.getUserID(), usuario.getUserName(), usuario.getUserEmail(), usuario.getUserPassword());
usuario.~User();
menuAdmin(adminp);
opc = 0;
} else{
printf("Bienvenido %s\n", usuario.getUserName().c_str());
Cliente cliente(usuario.getUserID(), usuario.getUserName(), usuario.getUserEmail(), usuario.getUserPassword(), "");
usuario.~User();
menuCliente(cliente);
opc = 0;
}
} else {
cout << "Datos incorrectos/repetidos, vuelva a intentarlo\n" << endl;
usuario.~User();
}
break;
}
case 2: {// REGISTRO
bool cuentaExiste = true; // No sabemos si existe su cuenta o no
User usuario;
string _clave;
string nombre; cout << "\nIngrese su nombre: "; cin >> nombre;
string correo; cout << "Ingrese su correo: "; cin >> correo;
string contrasena; cout << "Ingrese su contraseña: "; cin >> contrasena;
int userID; cout << "Ingrese su ID: "; cin >> userID;
//int userID = (rand()%(100-2) + 1); // número aleatorio del 1 al 100
// Saber si se registra una cuenta de Admin o de Cliente
if (correo[0] == 'L') {
_clave = "admin";
} else {
_clave = "client";
}
usuario.setUserEmail(correo);
usuario.setUserPassword(contrasena);
usuario.setUserName(nombre);
usuario.setUserID(userID);
usuario.setUserClave(_clave);
cuentaExiste = usuario.buscar(usuario);
if (cuentaExiste) {
printf("¡¡¡Bienvenido, ha creado su cuenta!!!\n");
ofstream file("users.txt", ios::app);
file << endl << userID << " " << correo << " " << contrasena << " " << nombre << " " << _clave << " ";
usuario.~User();
file.close();
} else {
printf("Datos incorrectos/repetidos, vuelva a intentarlo\n");
usuario.~User();
}
break;
}
}
} while (opc != 0);
//filldata();
/*
cout << Productos[0].getNombreProducto()<< endl; //USAMOS EL METODO GET NOMBRE EN EL OBJETO GUARDADO EN EL VECTOR PRODUCTOS EN LA POSICION 0
cout << Productos[0].getPrecioUnitario()<< endl;
*/
//Pedido prueba(1, "prrueba", 34.);
return 0;
}
void menuAdmin(Admin a){
int validator = 0;
do {
printf("Ingresa cual opcion quieres ejecutar como admin \n");
printf("1. Añadir producto\n2. Añadir Cliente \n3. Salir\n");
int opc; cin>>opc;
switch (opc){
case 1: {
cout << "---------------------------------------------------------" << endl;
printf("Ingresa el nombre de producto (sin espacios): "); string name; cin>>name;
printf("Ingresa el precio unitario del producto: "); int precioU; cin>>precioU;
a.addProd(name, precioU);
cout << "---------------------------------------------------------" << endl;
break;
}
case 2: {
cout << "---------------------------------------------------------" << endl;
printf("Ingresa el id del cliente: "); int id; cin >>id;
printf("Ingresa el nombre del cliente: "); string name; cin >>name;
printf("Ingresa el correo del cliente: "); string email; cin>>email;
printf("Ingresa la contrasena del cliente: "); string pass; cin>>pass;
a.addClient(id, name, email, pass);
cout << "---------------------------------------------------------" << endl;
break;
}
case 3: {
validator = 1;
break;
}
break;
}
} while (validator == 0);
}
void menuCliente(Cliente c){
int validator = 0;
vector<Producto> productosCarro;
do {
cout << "---------------------------------------------------------" << endl;
printf(" OPCIONES\n");
cout << "---------------------------------------------------------" << endl;
printf("1. Iniciar Compra\n2. Finalizar Pedido (Pagar) \n3. Salir\n"); int opc; cin>>opc;
cout << "---------------------------------------------------------" << endl;
switch (opc){
case 1: {
productosCarro = menuCarrito();
break;
}
case 2: {
Pedido p;
if (productosCarro.size() == 0) {
cout << "Su carrito está vacío" << endl;
break;
} else {
int num = p.iniciarPedido(productosCarro, c);
if (num == 1) {
EXIT_SUCCESS;
} else {
break;
}
}
}
case 3:{
validator = 1;
break;
}
break;
}
} while(validator == 0);
}
vector<Producto> menuCarrito(){
//vector<Producto> Productos;
//Productos = filldata(Productos);
filldata();
Carrito car1;
int n, opcion;
//cout << Productos[1].getNombreProducto() << endl;
do
{
cout << "1. Ingresar Productos";
cout << "\n2. Display Carrito";
cout << "\n3. Borrar Productos";
cout << "\n4. Salir" <<endl;
cin >> opcion;
switch ( opcion )
{
case 1: {
car1.addProdCar(Productos);
break;
}
case 2: {
car1.displayCarrito();
break;
}
case 3: {
car1.borrarProdCar();
break;
}
}
} while ( opcion != 4 );
// Rergresar al menú del cliente
return car1.getVectorProducto();
}