-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
217 lines (213 loc) · 6.08 KB
/
main.c
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
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash.h"
void limpiar(){
int i=0;
cliente* temp = (cliente*)malloc(sizeof(cliente));
//Itera hasta que se acabe el arreglo
while(hashArray[i].head!=NULL){
temp = hashArray[i].head;
//Itera toda la letra
while(temp!=NULL){
cliente*next = temp->next;
free(temp);
free(temp->nombre);
free(temp->apellido);
free(temp->email);
free(temp->genero);
free(temp->direccion);
temp = next;
}
i++;
}
free(temp);
}
int main(void) {
int choice = -1,i;
//Inicializa la hashtable
for(i=0;i<SIZE;i++){
hashArray[i].head=NULL;
hashArray[i].tail=NULL;
}
while(choice != 0){
//Menu/////////
printf("Administrador de personas. Banco EDA:\n================\n");
printf("1.- Cargar archivo de clientes\n");
printf("2.- Agregar cliente\n");
printf("3.- Eliminar cliente del sistema\n");
printf("4.- Buscar cliente por id, nombre o apellido\n");
printf("5.- Agregar transaccion\n");
printf("6.- Deshacer última transacción\n");
printf("7.- Generar una lista de clientes según última transacción\n");
printf("8.- Generar una lista con los clientes que tienen más dinero en el banco\n");
printf("0.- Salir\n");
///////////////
scanf("%d",&choice);
if(choice == 0){
break;
}
else if(choice == 1){
leer_archivo("data.txt");
}
else if(choice == 2){
char nom[20];
char ape[30];
char gen[6];
char email[30];
char dir[50];
int id;
char *choice;
//Ingresar datos
printf("Ingrese Id: ");
scanf("%d",&id);
printf("Ingrese nombre: ");
scanf("%s",nom);
printf("Ingrese apellido: ");
scanf("%s",ape);
printf("Ingrese email: ");
scanf("%s",email);
printf("Ingrese Genero y direccion: \n");
scanf("%s ",gen);
fgets(dir,50,stdin);
////////
//Validacion de datos
printf("Estan correctos estos datos? Ingrese 'si' si estan correctos.\n");
printf("Id: %d Nombre y apellido: %s %s Email: %s Genero: %s Direccion: %s",id,nom,ape,email,gen,dir);
scanf("%s",choice);
///////
if(strcmp(choice,"si")==0){
agregar_elemento_hash(ape[0],id,nom,ape,email,gen,dir);//Ingresa la persona
}
}
else if(choice == 3){
int numero;
//Pregunta por que opcion quiere
printf("Desea eliminar por rut, nombre o apellido?\n\t Ingrese 1 para nombre, 2 para id, 3 para apellido\n");
scanf("%d",&numero);
if(numero == 1){
//Busqueda por nombre
char nombre[20];
printf("Ingrese nombre a eliminar: ");
scanf("%s",nombre);
borrar_cliente_nombre(nombre);
}
if(numero==2){
//Busqueda por id
int id;
printf("Ingrese id a eliminar: ");
scanf("%d",&id);
borrar_cliente_id(id);
}
if(numero == 3){
//Busqueda por apellido
char apellido[20];
printf("Ingrese apellido a eliminar: ");
scanf("%s",apellido);
borrar_cliente_apellido(apellido);
}
}
else if(choice == 4){
int numero;
cliente* res;
//Pregunta por que opcion quiere
printf("Desea buscar por rut, nombre o apellido?\n\t Ingrese 1 para nombre, 2 para id, 3 para apellido\n");
scanf("%d",&numero);
if(numero==1){
//Busqueda por nombre
char nombre[20];
printf("Ingrese nombre a buscar: ");
scanf("%s",nombre);
res = search_nombre(nombre);
if(res==NULL){
printf("No se encontro\n");
}
else{
printf("Nombre: %s %s\nid: %d\n",res->nombre,res->apellido,res->id);
printf("Email: %s\n",res->email);
printf("Genero: %s\n",res->genero);
printf("Direccion: %s",res->direccion);
}
}
if(numero==2){
//Busqueda por id
int id;
printf("Ingrese id a buscar: ");
scanf("%d",&id);
res = search_id(id);
if(res==NULL){
printf("No se encontro\n");
}
else{
printf("Nombre: %s %s\nid: %d\n",res->nombre,res->apellido,res->id);
printf("Email: %s\n",res->email);
printf("Genero: %s\n",res->genero);
printf("Direccion: %s",res->direccion);
}
}
if(numero==3){
//Busqueda por apellido
char apellido[20];
printf("Ingrese apellido a buscar: ");
scanf("%s",apellido);
res = search_apellido(apellido);
if(res==NULL){
printf("No se encontro\n");
}
else{
printf("Nombre: %s %s\nid: %d\n",res->nombre,res->apellido,res->id);
printf("Email: %s\n",res->email);
printf("Genero: %s\n",res->genero);
printf("Direccion: %s",res->direccion);
}
}
}
else if(choice == 5){
//Hacer transaccion
int id,cant,client;
printf("En que cliente desea agregar una transaccion? Ingrese un id: ");
scanf("%d",&client);
printf("Desea agregar o sacar dinero?\n\t1. Agregar 2. Sacar\n");
scanf("%d",&id);
if(id == 1){
printf("Cuanto desea ingresar?\n");
scanf("%d",&cant);
ingresar_dinero(client,cant);
}
else if(id == 2){
printf("Cuanto desea sacar?\n");
scanf("%d",&cant);
sacar_dinero(client,cant);
}
else{
printf("opcion incorrecta.\n");
}
}
else if(choice == 6){
int id;
printf("A que cliente le quiere deshacer la transaccion?Ingrese su id\n");
scanf("%d",&id);
sacar_ultima(id);
}
else if(choice == 7){
int min;
printf("Cuanto es el minimo que quiere mostrar?\n");
scanf("%d",&min);
display_transacciones(min);
}
else if(choice == 8){
int cant;
crear_nueva_ordenada();
ordenar();
printf("Cuantos clientes quiere mostrar?\n");
scanf("%d",&cant);
display_saldo(cant);
}
else {
printf("Opcion incorrecta.\n\n");
}
}
limpiar();//Limpiar memoria
return 0;
}