Está en la página 1de 5

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
/**************************************************************
EJEMPLO DE LISTA ENLAZADA CON CLASES Y OBJETOS
LOS REPORTES SOLICITADOS NO SON DESARROLLADOS COMO
METODOS DE LAS CLASES
**************************************************************/
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<ctype.h>
#include<string.h>
#define DELTA 5
class CuentaAhorro
{
//Campos o atributos privados: private
char NroCta[10];
char Usuario[20];
char Clave[10];
float Saldo;
CuentaAhorro *Sgte; //puntero de enlace
//Campos y metodos publicos
public:
CuentaAhorro(); //Constructor
void Leer_Cuenta();
void Mostrar_Cuenta();
float Deposito(float &Monto);
float Retiro(float &Monto);
//Metodos u operaciones para devolver datos
float GetSaldo();
char *GetNroCta();
char *GetClave();
//Permitiendo que clase amiga acceda a los miembros
friend class ListaCuentas;
};
class ListaCuentas
{
private:
int N;
CuentaAhorro *Movil, *Cab;
public:
ListaCuentas(); //Constructor
void Insertar(CuentaAhorro *A);
void Mostrar();
CuentaAhorro *BuscarCuentaClave(char NC[],char C[]);
CuentaAhorro *BuscarCuenta(char NC[]);
~ListaCuentas(); //Destructor
int GetN();
};
/******** FUNCIONES QUE NO PERTENECEN A LAS CLASES ***********/
char DeseaContinuar(char Msje[])
{
char Rpta;
do
{
cout<<Msje;
cin>>Rpta;
Rpta=toupper(Rpta);
}while(!(Rpta=='S'||Rpta=='N'));
return Rpta;
}
float Leer_Real(char Msje[],float Min,float Max)
{
float Opc;
do
{
cout<<Msje;
cin>>Opc;
enlaz_2.cpp 09/03/2011 10:58 p.m.
Page 1 of 5
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
}while(!(Opc>=Min&&Opc<=Max));
return Opc;
}
int Leer_Entero(char Msje[],int Min,int Max)
{
int Opc;
do
{
cout<<Msje;
cin>>Opc;
}while(!(Opc>=Min&&Opc<=Max));
return Opc;
}
/*********** METODOS U OPERACIONES DE LA CLASE CUENTAAHORRO *************/
CuentaAhorro::CuentaAhorro()
{
Usuario[0]=NULL;
NroCta[0]=NULL;
Clave[0]=NULL;
Saldo=0.0;
}
void CuentaAhorro::Leer_Cuenta()
{
clrscr();
cout <<"---- DATOS DE NUEVA CUENTA ----" << endl;;
cout<<"Nombre Del usuario: ";
cin >> Usuario;
cout<<"Numero de cuenta: ";
cin >> NroCta;
cout<<"Clave: ";
cin >> Clave;
cout<<"Saldo inicial: ";
cin >> Saldo;
}
void CuentaAhorro::Mostrar_Cuenta()
{
cout << "----- DATOS DE CUENTA ------" << endl;
cout<<"Usuario: " << Usuario << endl;
cout<<"Num. de cuenta: " << NroCta << endl;
cout<<"Clave: " << Clave << endl;
cout<<"Saldo: " << Saldo << endl;
}
float CuentaAhorro::GetSaldo()
{
return Saldo;
}
char *CuentaAhorro::GetNroCta()
{
return NroCta;
}
char *CuentaAhorro::GetClave()
{
return Clave;
}
float CuentaAhorro::Deposito(float&Monto)
{
Saldo+=Monto;
return Saldo;
}
float CuentaAhorro::Retiro(float&Monto)
{
Saldo-=Monto;
return Saldo;
}
/*********** METODOS U OPERACIONES DE LA CLASE LISTACUENTAS *************/
ListaCuentas::ListaCuentas()
{
N = 0;
Cab = Movil = NULL;
enlaz_2.cpp 09/03/2011 10:58 p.m.
Page 2 of 5
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
}
ListaCuentas::~ListaCuentas()
{

}
int ListaCuentas::GetN()
{
return N;
}
void ListaCuentas::Insertar(CuentaAhorro *A)
{
A->Sgte = NULL;
if (N == 0)
Cab = A;
else
{
A->Sgte = Movil->Sgte;
Movil->Sgte = A;
}
Movil = A;
N++;
}
CuentaAhorro *ListaCuentas::BuscarCuentaClave(char NC[],char C[])
{
//Utilizacion de los metodos GET
CuentaAhorro *Temp = Cab;
while(Temp != NULL)
{
if (strcmp(Temp->GetNroCta(), NC) == 0
&& strcmp(Temp->GetClave(), C) == 0)
return Temp;
Temp = Temp->Sgte;
}
return NULL;
}
CuentaAhorro *ListaCuentas::BuscarCuenta(char NC[])
{
//Utilizacion de los metodos GET
CuentaAhorro *Temp = Cab;
while(Temp != NULL)
{
if (strcmp(Temp->GetNroCta(), NC) == 0)
return Temp;
Temp = Temp->Sgte;
}
return NULL;
}
void ListaCuentas::Mostrar()
{
CuentaAhorro *Temp = Cab;
if (N > 0)
{
cout << "**** DATOS DE LA LISTA ****" << endl;
while(Temp != NULL)
{
Temp->Mostrar_Cuenta();
Temp = Temp->Sgte;
}
}
else
cout<<"Lista vacia...." << endl;
getch();
}
//REPORTE 1: Mostrar datos de una cuenta especifica
void Reporte1(ListaCuentas &LC)
{
enlaz_2.cpp 09/03/2011 10:58 p.m.
Page 3 of 5
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
char Num[10];
CuentaAhorro *Pos;
if(LC.GetN()>0)
{
cout<<"Ingrese Numero De Cuenta: ";
cin >> Num;
Pos=LC.BuscarCuenta(Num);
if(Pos != NULL)
Pos->Mostrar_Cuenta();
else
cout<<"Numero De Cuenta no existe...";
}
else
cout<<"Lista vacia... ";
getch();
}
//REPORTE 2: Realizar deposito sobre una cuenta
void Reporte2(ListaCuentas &LC)
{
float Monto,NSaldo;
CuentaAhorro *Pos;
char Num[10],Pass[10];
if(LC.GetN() > 0)
{
cout<<"Ingrese Numero De Cuenta: ";
cin >> Num;
cout<<"\n\n\t Ingrese Clave: ";
cin >> Pass;
Pos=LC.BuscarCuentaClave(Num,Pass);
if(Pos!=NULL)
{
Monto=Leer_Real("Ingrese Nuevo Deposito: ",0.0,1000);
//Utilizando el metodo de la clase CuentaAhorro
NSaldo=Pos->Deposito(Monto);
cout<<"Su Nuevo Saldo Es: " << NSaldo;
}
else
cout<<"Error en cuenta o clave...";
}
else
cout<<"Lista vacia... ";
getch();
}
/***** OTRAS OPERACIONES NECESARIAS QUE NO PERTENECEN A LAS CLASES
PERO SON NECESARIAS, POR LO TANTO DEBE PASARSE COMO PARAMETRO LA
LISTA DE CUENTASAHORRO ****/
//OPERACION PARA REGISTRAR CUENTAS: recibe como parametro
//la lista de cuentas, por que no PERTENECE a la clase
void Lectura(ListaCuentas&LD)
{
//Definiendo un objeto y asignando espacio de memoria
CuentaAhorro *OC = new CuentaAhorro();
// Utilizando metodo de clase CuentaAhorro
OC->Leer_Cuenta();
//Utilizando metodo de clase ListaCuenta
LD.Insertar(OC);
}
int Menu()
{
int Opc;
clrscr();
cout<<"--- MENU PRINCIPAL --- " << endl;
cout<<"[1]Registro de nueva cuenta" << endl;
cout<<"[2]Mostrar Todas Las Cuentas" << endl;
cout<<"[3]Mostrar Una Cuenta" << endl;
enlaz_2.cpp 09/03/2011 10:58 p.m.
Page 4 of 5
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
cout<<"[4]Realizar Deposito" << endl;
cout<<"[5]Realizar Retiro" << endl;
cout<<"[6]Salir" << endl;
Opc=Leer_Entero("INGRESE OPCION: ",1,6);
return Opc;
}
// Menu de opciones: observese como se hacen las llamadas a las operaciones
// que estan dentro o fuera de la clase
void ProcesarMenu(ListaCuentas&LD)
{
int Opc;
do
{
Opc=Menu();
switch(Opc)
{
case 1:Lectura(LD);break;
case 2:LD.Mostrar();break;
case 3:Reporte1(LD);break;
case 4:Reporte2(LD);break;
case 5:
;break;
}
}while(!(Opc==6));
}
//FUNCION PRINCIPAL: se declara el objeto principal de la lista y se usa
// una operacion (PROCESAR) que no pertence a la clase, por lo que se le
// envia como parametro el objeto de la listacuentas
void main()
{
ListaCuentas OLD;
ProcesarMenu(OLD);
}
enlaz_2.cpp 09/03/2011 10:58 p.m.
Page 5 of 5

También podría gustarte