Ayuda Con Pascal Pilas y Colas
Publicado por Jose Gomez (4 intervenciones) el 26/11/2013 20:57:09
Buenas.. Necesito Ayuda Urgente! Con un programa en pascal... Mi profesora no nos explico nada de lo que es pilas y colas y nos mando Un trabajo Practico o como quieran llamarlo... para mañana.. Obviamente nose de pilas y colas y lo Hice en lista.. Y Alguien Me puede ayudar cn este programa.. Pasarlo de Lista a Pilas y colas..
El programa dice asi:
Hice El programa en Lista y corre todo perfectamente! mas nose nada de pilas y colas ayuda!
Un banco tiene guardados los registros de los movimientos en una lista. Los movimientos
están ordenados primero por fecha y luego por numero de cuenta.
(crear pila)
El tipo del elemento de la lista es:
TElemLista
Fecha (Clave ordenamiento 1) (TDA FECHA)
Nro_Cta (Clave ordenamiento 2)
Monto
Tipo (Deposito/Extracción)
Realizar procedimientos para este TDA que:
•Permita Calcular la cantidad de depósitos realizados entre un rango fecha
por ejemplo el 01/01/2013 y el
31/07/2013.
•
Permita Calcular el total depositado y extraído de cada cuenta en el año 2013.
•Permita Calcular el saldo de la cuenta 8894 del año 2013.
· Debe resolver el problema implementando pilas y colas
Program PilasYColas;
uses crt;
type Pila = ^nodo;
nodo = record
dia, mes, ano : longint;
ced:string;
nom:string ;
ape : string ;
mon, tipo: integer;
cuent: integer ;
depo : integer;
sig :Pila;
end;
var
primer,aux,anterior: Pila;
Seleccion: integer;
procedure registro_datosglobal;
procedure registro_datos;
begin
repeat
writeln(' Fecha : ');
write('Introduzca Dia : ');
readln(aux^.dia);
write('Introduzca Mes : ');
readln(aux^.mes);
writeln('Introduzca Ano : ');
readln(aux^.ano);
if (aux^.dia > 31) {or (aux^.mes >12) or (aux^.ano <2013> 31)then
begin
writeln ('FECHA INVALIDA');
writeln ('---------------------------------------------------');
writeln('Pulse enter para continuar');
readln;
end
else
begin
if (aux^.mes >12)then begin
writeln ('FECHA INVALIDA');
writeln ('---------------------------------------------------');
writeln('Pulse enter para continuar');
readln;
end;
end;
if (aux^.ano <=2012 ) then begin
writeln ('FECHA INVALIDA');
writeln('Pulse enter para continuar');
readln;
end;
until ( (aux^.dia <= 31) and (aux^.mes <12>= 2013)) ;
clrscr;
writeln('Introduzca el nombre');
readln (aux^.nom);
writeln('Introduzca la cedula');
readln (aux^.ced );
Writeln ('--------------------------------------------');
Writeln (' Desea crear una cuenta: ');
Writeln ('1: Ahorro 2: Corriente');
readln (aux^.tipo);
if (aux^.tipo = 1) then
begin
writeln ('Su cuenta de Ahorro esta creada');
end;
If (aux^.tipo = 2) then
begin
writeln ('Su cuenta Corriente esta creada');
end;
Writeln ('--------------------------------------------');
Writeln ('Introduzca el numero de la cuenta');
readln (aux^.cuent);
writeln ('inserte monto inicial');
readln (aux^.mon);
end;
begin
if primer = nil then
begin
new(aux);
registro_datos;
primer := aux;
aux^.sig := nil;
end
else
begin
anterior := aux;
new(aux);
registro_datos;
anterior^.sig := aux;
aux^.sig := nil;
end;
end;
procedure deposito ();
var
depos:Pila;
mondepo,nucuenta: integer;
begin
depos:=primer;
while (depos <> nil ) do begin
writeln('Introduzca El numero de Cuenta ');
readln(nucuenta);
clrscr;
if (depos^.cuent = nucuenta ) then begin
writeln ('Introduzca el Monto que desea depositar');
readln (mondepo);
depos^.mon:= (( depos^.mon)+ (mondepo));
writeln ('Su saldo es: ');
write (aux^.mon);
end;
depos:=depos^.sig;
end;
end;
procedure retiro ();
var
res:Pila;
monre,ncuenta: integer;
begin
res:=primer;
writeln('Indique el Numero de Cuenta');
readln(ncuenta);
clrscr;
if (primer = nil) then begin
writeln('ERROR no Hay Ningun Numero de Cuenta Registrado');
writeln('Pulse enter para continuar');
readln;
end;
while (res <> nil ) do begin
if (res^.cuent = ncuenta )then begin
writeln ('Introduzca el Monto que desea retirar');
readln (monre);
res^.mon:= (( res^.mon)- (monre));
writeln ('Su saldo es: '); write (aux^.mon);;
end;
res:=res^.sig;
end;
end;
procedure mostrar ();
var
mostra:Pila;
begin
clrscr;
mostra:=primer;
if (primer = nil) then begin
writeln('ERROR no Hay Ningun Numero de Cuenta o Usuario Registrado ');
writeln('Pulse enter para continuar');
readln;
end;
while mostra <> nil do
begin
writeln('ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ');
Writeln('Fecha de Apertura');
Write (' '); Write(mostra^.dia);
Write(' / '); Write(mostra^.mes);
Write(' / '); Write (mostra^.ano);
Writeln();
writeln('.............................................');
Writeln ('Numero de Cuenta:'); Writeln (mostra^.cuent);
writeln;
writeln ('Su cuenta es: ');
if (mostra^.tipo = 1) then
begin
writeln ('ahorro');
end;
if (mostra^.tipo = 2) then
begin
writeln ('corriente');
end;
writeln('.............................................');
Write('Nombre :'); Write(mostra^.nom); Writeln();
Write('cedula:');write(mostra^.ced);Writeln();
writeln ('saldo total: '); writeln (mostra^.mon);
writeln('ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ');
readkey;
mostra:=mostra^.sig;
end;
end;
BEGIN
Seleccion:=0;
repeat
begin
clrscr;
Writeln ('');
Writeln ('');
Writeln ('***** BIENVENIDOS ***** ');
Writeln ('');
Writeln ('1. Crear Cuenta');
Writeln ('2. Deposito');
Writeln ('3. Retiro ');
Writeln ('4. Mostrar ');
writeln ('. SALIR DEL SISTEMA');
Writeln ('');
writeln('Seleccione la Opcion: ');
readln(Seleccion);
clrscr;
Case Seleccion of
1:
begin
registro_datosglobal;
end;
2 :
begin
deposito ();
end;
3:
begin
retiro ();
end;
4:
begin
mostrar ();
end;
5: Writeln ('Fin.....');
Else (writeln (' Opcion incorrecta'));
end;
end;
until (Seleccion = 5);
END.
El programa dice asi:
Hice El programa en Lista y corre todo perfectamente! mas nose nada de pilas y colas ayuda!
Un banco tiene guardados los registros de los movimientos en una lista. Los movimientos
están ordenados primero por fecha y luego por numero de cuenta.
(crear pila)
El tipo del elemento de la lista es:
TElemLista
Fecha (Clave ordenamiento 1) (TDA FECHA)
Nro_Cta (Clave ordenamiento 2)
Monto
Tipo (Deposito/Extracción)
Realizar procedimientos para este TDA que:
•Permita Calcular la cantidad de depósitos realizados entre un rango fecha
por ejemplo el 01/01/2013 y el
31/07/2013.
•
Permita Calcular el total depositado y extraído de cada cuenta en el año 2013.
•Permita Calcular el saldo de la cuenta 8894 del año 2013.
· Debe resolver el problema implementando pilas y colas
Program PilasYColas;
uses crt;
type Pila = ^nodo;
nodo = record
dia, mes, ano : longint;
ced:string;
nom:string ;
ape : string ;
mon, tipo: integer;
cuent: integer ;
depo : integer;
sig :Pila;
end;
var
primer,aux,anterior: Pila;
Seleccion: integer;
procedure registro_datosglobal;
procedure registro_datos;
begin
repeat
writeln(' Fecha : ');
write('Introduzca Dia : ');
readln(aux^.dia);
write('Introduzca Mes : ');
readln(aux^.mes);
writeln('Introduzca Ano : ');
readln(aux^.ano);
if (aux^.dia > 31) {or (aux^.mes >12) or (aux^.ano <2013> 31)then
begin
writeln ('FECHA INVALIDA');
writeln ('---------------------------------------------------');
writeln('Pulse enter para continuar');
readln;
end
else
begin
if (aux^.mes >12)then begin
writeln ('FECHA INVALIDA');
writeln ('---------------------------------------------------');
writeln('Pulse enter para continuar');
readln;
end;
end;
if (aux^.ano <=2012 ) then begin
writeln ('FECHA INVALIDA');
writeln('Pulse enter para continuar');
readln;
end;
until ( (aux^.dia <= 31) and (aux^.mes <12>= 2013)) ;
clrscr;
writeln('Introduzca el nombre');
readln (aux^.nom);
writeln('Introduzca la cedula');
readln (aux^.ced );
Writeln ('--------------------------------------------');
Writeln (' Desea crear una cuenta: ');
Writeln ('1: Ahorro 2: Corriente');
readln (aux^.tipo);
if (aux^.tipo = 1) then
begin
writeln ('Su cuenta de Ahorro esta creada');
end;
If (aux^.tipo = 2) then
begin
writeln ('Su cuenta Corriente esta creada');
end;
Writeln ('--------------------------------------------');
Writeln ('Introduzca el numero de la cuenta');
readln (aux^.cuent);
writeln ('inserte monto inicial');
readln (aux^.mon);
end;
begin
if primer = nil then
begin
new(aux);
registro_datos;
primer := aux;
aux^.sig := nil;
end
else
begin
anterior := aux;
new(aux);
registro_datos;
anterior^.sig := aux;
aux^.sig := nil;
end;
end;
procedure deposito ();
var
depos:Pila;
mondepo,nucuenta: integer;
begin
depos:=primer;
while (depos <> nil ) do begin
writeln('Introduzca El numero de Cuenta ');
readln(nucuenta);
clrscr;
if (depos^.cuent = nucuenta ) then begin
writeln ('Introduzca el Monto que desea depositar');
readln (mondepo);
depos^.mon:= (( depos^.mon)+ (mondepo));
writeln ('Su saldo es: ');
write (aux^.mon);
end;
depos:=depos^.sig;
end;
end;
procedure retiro ();
var
res:Pila;
monre,ncuenta: integer;
begin
res:=primer;
writeln('Indique el Numero de Cuenta');
readln(ncuenta);
clrscr;
if (primer = nil) then begin
writeln('ERROR no Hay Ningun Numero de Cuenta Registrado');
writeln('Pulse enter para continuar');
readln;
end;
while (res <> nil ) do begin
if (res^.cuent = ncuenta )then begin
writeln ('Introduzca el Monto que desea retirar');
readln (monre);
res^.mon:= (( res^.mon)- (monre));
writeln ('Su saldo es: '); write (aux^.mon);;
end;
res:=res^.sig;
end;
end;
procedure mostrar ();
var
mostra:Pila;
begin
clrscr;
mostra:=primer;
if (primer = nil) then begin
writeln('ERROR no Hay Ningun Numero de Cuenta o Usuario Registrado ');
writeln('Pulse enter para continuar');
readln;
end;
while mostra <> nil do
begin
writeln('ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ');
Writeln('Fecha de Apertura');
Write (' '); Write(mostra^.dia);
Write(' / '); Write(mostra^.mes);
Write(' / '); Write (mostra^.ano);
Writeln();
writeln('.............................................');
Writeln ('Numero de Cuenta:'); Writeln (mostra^.cuent);
writeln;
writeln ('Su cuenta es: ');
if (mostra^.tipo = 1) then
begin
writeln ('ahorro');
end;
if (mostra^.tipo = 2) then
begin
writeln ('corriente');
end;
writeln('.............................................');
Write('Nombre :'); Write(mostra^.nom); Writeln();
Write('cedula:');write(mostra^.ced);Writeln();
writeln ('saldo total: '); writeln (mostra^.mon);
writeln('ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ');
readkey;
mostra:=mostra^.sig;
end;
end;
BEGIN
Seleccion:=0;
repeat
begin
clrscr;
Writeln ('');
Writeln ('');
Writeln ('***** BIENVENIDOS ***** ');
Writeln ('');
Writeln ('1. Crear Cuenta');
Writeln ('2. Deposito');
Writeln ('3. Retiro ');
Writeln ('4. Mostrar ');
writeln ('. SALIR DEL SISTEMA');
Writeln ('');
writeln('Seleccione la Opcion: ');
readln(Seleccion);
clrscr;
Case Seleccion of
1:
begin
registro_datosglobal;
end;
2 :
begin
deposito ();
end;
3:
begin
retiro ();
end;
4:
begin
mostrar ();
end;
5: Writeln ('Fin.....');
Else (writeln (' Opcion incorrecta'));
end;
end;
until (Seleccion = 5);
END.
Valora esta pregunta


0