Skip to content

Instantly share code, notes, and snippets.

@matipan
Created March 31, 2016 14:11
Show Gist options
  • Save matipan/d5cda1300818343757b1619bbe1eddef to your computer and use it in GitHub Desktop.
Save matipan/d5cda1300818343757b1619bbe1eddef to your computer and use it in GitHub Desktop.
Program ejer3;
uses Crt;
type
fecha = record
dia: integer;
mes: integer;
anio: integer;
end;
actReparto = record
apellido: string[20];
nombre: string[20];
id: string[5];
dni: longint;
nacionalidad: string[50];
fechaNac: fecha;
end;
archivo = file of actReparto;
{ Escribe los actores al archivo }
procedure agregar(var actores: archivo);
var
act: actReparto;
ok: boolean;
begin
ok := true;
readln(act.apellido);
while (ok) do
begin
write('Apellido: '); readln(act.apellido);
if act.apellido = '' then
ok := false
else
begin
write('Nombre: '); readln(act.nombre);
write('ID: '); readln(act.id);
write('DNI: '); readln(act.dni);
write('Nacionalidad: '); readln(act.nacionalidad);
write('Fecha de nacimiento, dia - mes - año: ');
readln(act.fechaNac.dia); readln(act.fechaNac.mes); readln(act.fechaNac.anio);
end;
if ok then
write(actores, act);
end;
end;
{ Agregar actores al final del archivo }
procedure agregarActores(var actores: archivo);
begin
reset(actores);
seek(actores, filesize(actores));
agregar(actores);
close(actores);
end;
{ Sobreescribe el archivo con actores }
procedure escribir(var actores: archivo);
begin
rewrite(actores);
agregar(actores);
close(actores);
end;
{ Reporta la cantidad de actores con año de nacimiento previo al 1980 }
procedure rep1980(var actores: archivo);
var
cant: integer;
act: actReparto;
begin
reset(actores); cant := 0;
while(not eof(actores)) do
begin
read(actores, act);
if act.fechaNac.anio < 1980 then
cant := cant + 1;
end;
close(actores);
writeln('Cantidad de actores con fecha previa a 1980: ', cant);
end;
{ Reporta la cantidad de actores con nacionalidad venezolana }
procedure venezolanos(var actores: archivo);
var
cant: integer;
act: actReparto;
begin
reset(actores); cant := 0;
while(not eof(actores)) do
begin
read(actores, act);
if act.nacionalidad = 'venezolano' then
cant := cant + 1;
end;
close(actores);
writeln('Cantidad de actores venezolanos: ', cant);
end;
{ Reporta la cantidad de actores con DNI superior a 30.000.000 }
procedure dnisup(var actores: archivo);
var
cant: integer;
act: actReparto;
begin
reset(actores); cant := 0;
while(not eof(actores)) do
begin
read(actores, act);
if act.dni > 30000000 then
cant := cant + 1;
end;
close(actores);
writeln('Cantidad de actores con dni superior a 30.000.000: ', cant);
end;
{ Lista todos los actores }
procedure todos(var actores: archivo);
var
act: actReparto;
begin
reset(actores);
while(not eof(actores)) do
begin
read(actores, act);
writeln('nombre: ', act.nombre, '| apellido: ', act.apellido, '| id: ', act.id, '| dni: ', act.dni, '| nacionalidad: ', act.nacionalidad, '| fecha: ', act.fechaNac.dia, '/', act.fechaNac.mes, '/', act.fechaNac.anio)
end;
close(actores);
end;
procedure modificarActor(var actores: archivo);
var
act: actReparto;
auxdni: longint;
tmp: string[50];
begin
act.dni := 0;
write('DNI del actor: '); readln(auxdni);
reset(actores);
while(not eof(actores)) do
while(act.dni <> auxdni) do
read(actores, act);
write('Nueva nacionalidad del actor: '); readln(tmp);
act.nacionalidad := tmp;
seek(actores, filepos(actores)-1);
write(actores, act);
writeln('Nueva nacionalidad es: ', tmp);
close(actores);
end;
var
actores: archivo;
decision: integer;
ok: boolean;
begin
assign(actores, 'actores.txt');
decision := 9;
ok := true;
while (ok) do
begin
writeln('');
writeln('***** 1. Escribir actores al archivo');
writeln('***** 2. Reportar actores con fecha de nacimiento previa a 1980');
writeln('***** 3. Reportar actores venezolanos');
writeln('***** 4. Reportar actores con DNI > 30.000.000');
writeln('***** 5. Modificar nacionalidad de actor');
writeln('***** 6. Agregar actores');
writeln('***** 7. Listar actores');
writeln('***** 0. Salir');
write('Que accion desea realizar? ');
read(decision);
writeln('');
ClrScr;
case decision of
0: ok := false;
1: escribir(actores);
2: rep1980(actores);
3: venezolanos(actores);
4: dnisup(actores);
5: modificarActor(actores);
6: agregarActores(actores);
7: todos(actores);
otherwise writeln('Selecciona una de la lista.');
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment