-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrincipal.cpp
More file actions
228 lines (197 loc) · 5.04 KB
/
Principal.cpp
File metadata and controls
228 lines (197 loc) · 5.04 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
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Persona
{
private:
string nombre, direccion;
int telefono;
public:
Persona ();
Persona (string, string, int);
void SetNombre (string);
void SetDireccion (string);
void SetTelefono (int);
string GetNombre ( );
string GetDireccion ( );
int GetTelefono ( );
};
Persona::Persona ( )
{
this->nombre = this->direccion = "";
this->telefono = 0;
}
Persona::Persona (string nombre, string direccion, int telefono)
{
this->nombre = nombre;
this->direccion = direccion;
this->telefono = telefono;
}
void Persona::SetNombre (string nombre)
{
this->nombre = nombre;
}
void Persona::SetDireccion (string direccion)
{
this->direccion = direccion;
}
void Persona::SetTelefono (int telefono)
{
this->telefono = telefono;
}
string Persona::GetNombre ( )
{
return (this->nombre);
}
string Persona::GetDireccion ( )
{
return (this->direccion);
}
int Persona::GetTelefono ( )
{
return (this->telefono);
}
class Guia
{
private:
Persona *agenda;
int num_personas, max_personas;
public:
Guia (int);
int GetNum_personas ( );
int GetMax_personas ( );
bool AgregarPersona (Persona);
int Buscar (string);
string Buscar (int);
string Buscar (int, string);
};
Guia::Guia (int max_personas)
{
this->max_personas = max_personas;
this->num_personas = 0;
this->agenda = new Persona [max_personas];
}
int Guia::GetNum_personas ( )
{
return (num_personas);
}
int Guia::GetMax_personas ( )
{
return (max_personas);
}
bool Guia::AgregarPersona (Persona nueva)
{
if (this->num_personas == this->max_personas)
return (false); // No hay espacio en la agenda
else
{
this->agenda [this->num_personas] = nueva;
++ this->num_personas;
return (true);
}
}
int Guia::Buscar (string nombre)
{
int ix;
for (ix = 0; ix < this->num_personas; ++ ix)
{
if (this->agenda[ix].GetNombre ( ) == nombre)
return (this->agenda[ix].GetTelefono ( ));
}
return (-1); // Nombre no encontrado
}
string Guia::Buscar (int telefono)
{
int ix;
for (ix = 0; ix < this->num_personas; ++ ix)
{
if (this->agenda[ix].GetTelefono ( ) == telefono)
return (this->agenda[ix].GetDireccion ( ));
}
return (""); // Telefono no encontrado
}
string Guia::Buscar (int telefono, string direccion)
{
int ix;
for (ix = 0; ix < this->num_personas; ++ ix)
{
if (this->agenda[ix].GetTelefono ( ) == telefono &&
this->agenda[ix].GetDireccion ( )== direccion)
return (this->agenda[ix].GetNombre ( ));
}
return (""); // Telefono y direccion no encontrados
}
int main (int argc, char *argv [ ])
{
int max, telefono;
string opcion, nombre, direccion, valor;
bool fin;
cout << "Guia de telefonos ++\n";
cout << "Ingrese maximo de personas en la guia: ";
getline (cin, valor); stringstream (valor) >> max;
Guia blanca (max);
fin = false;
while (!fin)
{
cout << endl
<< "Opciones disponibles:" << endl
<< " a: agregar persona" << endl
<< " b: buscar telefono por nombre" << endl
<< " d: buscar direccion por telefono" << endl
<< " n: buscar nombre por direccion y telefono" << endl
<< " f: fin del proceso" << endl
<< "Ingrese opcion: ";
getline (cin, opcion);
if (opcion == "a")
{
cout << "Ingrese nombre : "; getline (cin, nombre);
cout << "Ingrese direccion: "; getline (cin, direccion);
cout << "Ingrese telefono : "; getline (cin, valor);
stringstream (valor) >> telefono;
Persona nueva (nombre, direccion, telefono);
if (blanca.AgregarPersona (nueva))
cout << ">>> Ingreso exitoso\n";
else
cout << ">>> Error en ingreso de persona\n";
}
else if (opcion == "b")
{
cout << "Ingrese nombre: "; getline (cin, nombre);
telefono = blanca.Buscar (nombre);
if (telefono == -1)
cout << ">>> Ese nombre no tiene telefono\n";
else
cout << ">>> Telefono es: " << telefono << endl;
}
else if (opcion == "d")
{
cout << "Ingrese telefono: ";
getline (cin, valor); stringstream (valor) >> telefono;
valor = blanca.Buscar (telefono);
if (valor == "")
cout << ">>> Telefono no registrado en la guia\n";
else
cout << ">>> La direccion es: " << valor << endl;
}
else if (opcion == "n")
{
cout << "Ingrese direccion: "; getline (cin, direccion);
cout << "Ingrese telefono: "; getline (cin, valor);
stringstream (valor) >> telefono;
valor = blanca.Buscar (telefono, direccion);
if (valor == "")
cout << ">>> Direccion y telefono no encontrados\n";
else
cout << ">>> El nombre es: " << valor << endl;
}
else if (opcion == "f")
fin = true;
else
cout << ">>> Opcion erronea, trate de nuevo\n";
}
cout << endl << "Numero de personas en la guia: "
<< blanca.GetNum_personas ( ) << endl;
cout << "Cerramos la Guia ++" << endl;
return (0);
}