Pascal/Turbo Pascal - registro de archivo

 
Vista:

registro de archivo

Publicado por Daniel (1 intervención) el 21/04/2011 03:50:11
Hola necesito una ayudita con un ejercicio en pascal de archivo de textos y registros :
el problema es que tengo que crear una lista de alumnos y hacer un menu donde pueda dar de baja y de alta al alumno y ordenarlos por dni y nose como acerlo usando archivos de texto y registro.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

registro de archivo

Publicado por ramon (2158 intervenciones) el 25/04/2011 18:05:36
{Espero que esto te ayude en tu aprendizaje de pascal o por lo menos te encamine en tu propósito
suerte.}

program textregi;
uses
crt;
type
alumnos = record
actibo : boolean;
nombre : string[80];
dni : integer;
end;
const
menu : array[1..5] of string[9] = ('VER DATOS','BAJA','ALTA','ARDENAR','SALIR');
nombrearchi = 'ALUMNOS.dat';
architem = 'temporal.tmp';

var
registro, modifi : alumnos;
dnip, cont : integer;
nomb : string[80];
f1, f : file of alumnos;
nn, cual, n1, anulo : word;
a : array[0..10] of integer;

procedure verregistros(xl,yl : integer;no : string);
var
regi : word;
tf : file of alumnos;
datosreg : alumnos;
x, y : integer;
begin
assign(tf,no);
{$i-} reset(tf); {$i+}
if ioresult <> 0 then
begin
exit;
end
else
begin;
nn := 0;
nn := filesize(tf) - 1;
regi := 0;
y := 1;
x := 1;
textcolor(15);
repeat
seek(tf,regi);
read(tf,datosreg);
if datosreg.actibo = true then
begin
gotoxy(xl,yl + y);write('Nombre = ',datosreg.nombre);
gotoxy(20 + xl,yl + y);write('DNI = ',datosreg.dni);
y := y + 1;
end;
regi := regi + 1;
if y > (yl + 20) then
begin
y := 1;
x := x + 10;
end;
until regi > filesize(tf) - 1;
close(tf);
end;
end;

procedure temporal(v : alumnos);
var
tf : file of alumnos;
begin
assign(tf,architem);
{$i-} reset(tf); {$i+}
if ioresult <> 0 then
begin
rewrite(tf);
seek(tf,0);
write(tf,v);
close(tf);
end
else
begin
seek(tf,filesize(tf));
write(tf,v);
close(tf);
end;
end;

procedure ordenareg(nom : string);
var
cambi, pasos, ordenado : alumnos;
ri, tama : longint;
pas1, pas2 : integer;
ten : file of alumnos;
begin
assign(ten,nom);
{$i-} reset(ten); {$i+}
if ioresult <> 0 then
begin
exit;
end
else
begin
if filesize(ten) - 1 > 100 then
begin
tama := 100;
end
else
begin
tama := filesize(ten) - 1;
end;
pas1 := 0;
repeat
seek(ten,pas1);
read(ten,registro);
ordenado := registro;
for pas2 := pas1 + 1 to tama do
begin
seek(ten,pas2);
read(ten,cambi);
if ordenado.dni > cambi.dni then
begin
pasos := ordenado;
ordenado := cambi;
cambi := pasos;
seek(ten,pas1);
write(ten,ordenado);
seek(ten,pas2);
write(ten,cambi);
end;
end;
pas1 := pas1 + 1;
until pas1 > tama;
end;
close(ten);
end;

procedure menualumnos;
var
tet, tecla : char;
ct : integer;
anulado, salir : boolean;
begin
for cont := 1 to 5 do
begin
gotoxy(10,10 + (cont + 1));write(menu[cont]);
end;
gotoxy(10,13 + (cont + 1));write('ELIJA OPCION CON LAS [ ][ ]');
gotoxy(32,13 + (cont + 1));write(#24);
gotoxy(35,13 + (cont + 1));write(#25);
cont := 1;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
salir := false;
repeat
tecla := readkey;
textcolor(15);
for ct := 1 to 5 do
begin
gotoxy(10,10 + (ct + 1));write(menu[ct]);
end;
if tecla = #72 then
begin
cont := cont - 1;
if cont < 1 then
cont := 1;
end;
if tecla = #80 then
begin
cont := cont + 1;
if cont > 5 then
cont := 5;
end;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
if tecla = #13 then
begin
case cont of
1 : begin
clrscr;
gotoxy(2,1);write('LOS REGISTROS ACTUALES SON');
verregistros(2,4,nombrearchi);
gotoxy(2,nn + 7);write('PULSE UNA TECLA.....');
repeat until keypressed;
clrscr;
for ct := 1 to 5 do
begin
gotoxy(10,10 + (ct + 1));write(menu[ct]);
end;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
gotoxy(10,13 + (ct + 1));write('ELIJA OPCION CON LAS [ ][ ]');
gotoxy(32,13 + (ct + 1));write(#24);
gotoxy(35,13 + (ct + 1));write(#25);
gotoxy(10 + length(menu[cont]),10 + (cont + 1));
end;
2 : begin
clrscr;
gotoxy(10,2);write('ANULAR ALIMNO');
gotoxy(10,4);write('ENTRE NUMERO DNI :');
readln(dnip);
assign(f,nombrearchi);
{$i-} reset(f); {$i+}
if ioresult <> 0 then
begin
exit;
end
else
begin
anulo := 0;
repeat
seek(f,anulo);
read(f,modifi);
if modifi.dni = dnip then
begin
gotoxy(10,10);write('REGISTRO A ANULAR ES');
gotoxy(10,13);write(modifi.nombre);
gotoxy(10,14);write(modifi.dni);
gotoxy(10,16);write('DESEA ANULARLO [S/N]');
repeat
tet := readkey;
until tet in ['s','S','n','N'];
if tet in['s','S'] then
begin
modifi.actibo := false;
modifi.nombre := ' ';
modifi.dni := 0;
seek(f,anulo);
write(f,modifi);
close(f);
end
else
begin
close(f);
end;
anulado := true;
end;
anulo := anulo + 1;
until (anulado = true) or (anulo > filesize(f) - 1);
end;
clrscr;
for ct := 1 to 5 do
begin
gotoxy(10,10 + (ct + 1));write(menu[ct]);
end;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
gotoxy(10,13 + (ct + 1));write('ELIJA OPCION CON LAS [ ][ ]');
gotoxy(32,13 + (ct + 1));write(#24);
gotoxy(35,13 + (ct + 1));write(#25);
gotoxy(10 + length(menu[cont]),10 + (cont + 1));
end;
3 : begin
clrscr;
gotoxy(10,3);write('ENTRAR ALUMNO');
gotoxy(10,5);write('NOMBRE : ');
readln(nomb);
gotoxy(10,6);write('DNI : ');
readln(dnip);
registro.nombre := nomb;
registro.dni := dnip;
registro.actibo := true;
assign(f,nombrearchi);
{$i-} reset(f); {$i+}
if ioresult <> 0 then
begin
rewrite(f);
seek(f,0);
write(f, registro);
close(f);
end
else
begin
seek(f,filesize(f));
write(f,registro);
close(f);
end;
clrscr;
for ct := 1 to 5 do
begin
gotoxy(10,10 + (ct + 1));write(menu[ct]);
end;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
gotoxy(10,13 + (ct + 1));write('ELIJA OPCION CON LAS [ ][ ]');
gotoxy(32,13 + (ct + 1));write(#24);
gotoxy(35,13 + (ct + 1));write(#25);
gotoxy(10 + length(menu[cont]),10 + (cont + 1));
end;
4 : begin
clrscr;
ordenareg(nombrearchi);
for ct := 1 to 5 do
begin
gotoxy(10,10 + (ct + 1));write(menu[ct]);
end;
TextBackground(7);
textcolor(1);
gotoxy(10,10 + (cont + 1));write(menu[cont]);
TextBackground(0);
textcolor(15);
gotoxy(10,13 + (ct + 1));write('ELIJA OPCION CON LAS [ ][ ]');
gotoxy(32,13 + (ct + 1));write(#24);
gotoxy(35,13 + (ct + 1));write(#25);
gotoxy(10 + length(menu[cont]),10 + (cont + 1));
end;
5 : begin
clrscr;
salir := true;
end;
end;
end;
until salir = true;
end;



begin
clrscr;
menualumnos;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar