Mostrar un Top10 en Pascal
{A ver si esto te ayuda }
program bufferes;
uses
crt;
Type
REGISTRO = Record
ID : String[10];
Score : Integer;
Rank : Integer;
end;
ARCHIVO = File Of REGISTRO;
Var
BUFFER : REGISTRO;
Top10 : ARCHIVO;
procedure guarda;
begin
assign(top10,'c:\tp\archivos.dat');
{$i-} reset(top10); {$i+}
if ioresult <> 0 then
begin
rewrite(top10);
seek(top10,0);
write(top10,buffer);
close(top10);
end
else
begin
seek(top10,filesize(top10));
write(top10,buffer);
close(top10);
end;
end;
procedure asignadatos;
var
teb : char;
begin
repeat
fillchar(buffer.ID,11,' ');
buffer.ID[0] := chr(10);
buffer.score := 0;
gotoxy(10,2);write('Entre ID : ');
gotoxy(21,2);readln(buffer.ID);
gotoxy(10,3);write('Entre Score : ');
gotoxy(24,3);readln(buffer.score);
guarda;
gotoxy(10,6);write('Mas Entradas [S/N]');
repeat
teb := readkey;
until teb in['n','N','s','S'];
clrscr;
until teb in['n','N'];
end;
procedure presentamallores;
var
tomado : array[1..1000] of integer;
identi : array[1..1000] of string[10];
ii, tama : longint;
mallor, k, t, k1 : integer;
dad : string[10];
begin
fillchar(tomado,sizeof(tomado),0);
fillchar(identi,sizeof(identi),' ');
assign(top10,'c:\tp\archivos.dat');
{$i-} reset(top10); {$i+}
if ioresult <> 0 then
begin
exit;
end
else
begin
tama := filesize(top10) - 1;
k := 1;
for ii := 0 to tama do
begin
seek(top10,ii);
read(top10,buffer);
tomado[k] := buffer.score;
identi[k] := buffer.Id;
k := k + 1;
end;
close(top10);
end;
for k1 := 1 to k do
for t := k1 + 1 to k do
begin
if tomado[k1] < tomado[t] then
begin
mallor := tomado[t];
tomado[t] := tomado[k1];
tomado[k1] := mallor;
dad := identi[t];
identi[t] := identi[k1];
identi[k1] := dad;
end;
end;
if tama < 10 then
k1 := tama + 1;
else
k1 := 10;
for t := 1 to k1 do
writeln(identi[t],' ',tomado[t]);
readln;
end;
procedure menu;
var
tecla : char;
sal : boolean;
begin
gotoxy(10,2);write('**** MENU GENERAL ****');
gotoxy(10,4);write(' 1 = Entrada Datos');
gotoxy(10,5);write(' 2 = Ver 10 Datos Mallores ');
gotoxy(10,6);write(' 3 = Anular Archivo Datos');
gotoxy(10,7);write(' 4 = Salir ');
gotoxy(10,8);write('<<<< Elija Opcion >>>>');
sal := false;
repeat
tecla := readkey;
case tecla of
#49 : begin
clrscr;
asignadatos;
end;
#50 : begin
clrscr;
presentamallores;
end;
#51 : begin
assign(top10,'c:\tp\archivos.dat');
{$i-} reset(top10); {$i+}
if ioresult <> 0 then
begin
end
else
begin
clrscr;
close(top10);
erase(top10);
gotoxy(10,3);write('ARCHIVO BORRADO');
delay(1000);
end;
end;
#52 : begin
sal := true;
end;
end;
clrscr;
gotoxy(10,2);write('**** MENU GENERAL ****');
gotoxy(10,4);write(' 1 = Entrada Datos');
gotoxy(10,5);write(' 2 = Ver 10 Datos Mallores ');
gotoxy(10,6);write(' 3 = Anular Archivo Datos');
gotoxy(10,7);write(' 4 = Salir ');
gotoxy(10,8);write('<<<< Elija Opcion >>>>');
until sal = true;
end;
begin
clrscr;
menu;
end.