-
Notifications
You must be signed in to change notification settings - Fork 0
/
parcial2.pas
121 lines (108 loc) · 2.24 KB
/
parcial2.pas
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
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
program parcial2;
type
cadena=string[20[;
municipio=record
nombre:cadena;
descripcion:cadena;
cant_habitantes:integer;
mts2:integer;
anio:integer;
end;
archivo=file of municipio;
function ExisteMunicipio(var arch:archivo; nombre:cadena): boolean;
var
reg:municipio;
encontre:boolean;
begin
reset(arch);
encontre:=false;
read(arch,reg);
while (not eof(arch) and (reg.nombre<> nombre) do begin
if reg.nombnre=nombre then
encontre:=true
else
read(arch,reg);
end;
close(arch);
existeMunicipio:=encontre;
end;
procedure insertar(var arch:archivo; nuevoi:municipio);
var
aux:municipio;
begin
reset(arch)
read(arch,aux);
if (aux.cant_habitantes < 0) then begin
seek(arch, (aux.cant_habitantes)*-1);
read(arch,aux);
seek(arch,filepos(arch)-1);
write(arch,nuevo);
seek(arch,0);
write(arch,aux);
end
else
begin
seek(arch,filesize(arch));
write(arch,nuevo);
end;
close(arch);
end;
procedure AltaMunicipio(var arch:archivo);
var
nuevo:municipio;
begin
writeln('Nombre de municipio a insertar ');
read(nuevo.nombre);
if not ExisteMunicipio(arch,reg.nombre) then begin
with nuevo do begin
writeln('Descripcion: ');
read(descripcion);
writlen('Cantidad de habitantes: ');
read(cant_habitantes);
writeln('Metros cuadrados: ');
read(mts2);
writeln('Año de creacion: ');
read(anio);
end;
insertar(arch,nuevo);
end
else
writeln('Ya existe el municipio en el archivo ');
end;
procedure eliminar(var arch:archivo; nombre: cadena);
vaR
head:integer;
reg:municipio;
begin
reset(arch);
read(arch,reg);
head:=reg.cant_habitantes;
while (reg.nombre <> nombre) do
read(arch,reg);
reg.cant_habitantes:=head;
head:=(-1*filepos(arch)-1);
seek(arch,filepos(arch)-1);
write(arch,reg);
seek(arch,0);
reg.cant_habitantes:=head;
write(arch,reg);
close(arch);
end;
procedure BajaMunicipio(var arch:archivo);
var
nombre:cadena;
begin
writeln('Ingrese nombre de municipio a eliminar ');
read(nombre);
if ExisteMunicipio(arch,nombre) then
eliminar(arch,nombre)
else
writeln('Municipio no existente');
end;
{programa principal}
var
arch:archivo;
begin
assign(arch,'municipios.arch');
end.
{no hay llamada al resto de los modulos porque solo era necesario iomplementarlos pero no usarlos}