Pascal/Turbo Pascal - Crear Archivo y cargarlo a partir de datos editados en un archivo

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado 1 puesto en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

Crear Archivo y cargarlo a partir de datos editados en un archivo

Publicado por Facundo (1 intervención) el 04/05/2019 17:14:37
Buenas tardes a todos! Necesito ayuda, tengo que hacer un programa que cree un archivo y que ese archivo se cargue con los datos de un .txt que previamente cree, por ej en el escritorio. No logro hacer funcionar, no puedo cargarle los datos a mi maestro con el txt, el lazarus me da muchisimos errores. Si me pueden ayudar se los agradezco. Aca dejo mi código

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
program trabajoentrega;
type
reg_libro=record
  cod_int:integer;
  ISBN:integer;
  cant_copias:integer;
  prestados:integer;
  total:integer;
end;
archivo=file of reg_libro;
var
libro:reg_libro;
arc_maestro: archivo;
arc_fisico: string;
arc_auxiliar: archivo;
opcion: integer;
 
  procedure crear_archivo (arc_fisico1: string; var arc_auxiliar1: archivo; var arc_maestro1: archivo; libro1: reg_libro);
  begin
  writeln('Ingrese nombre del archivo');
  readln;
  readln (arc_fisico1);
  assign (arc_maestro1, arc_fisico1);
  rewrite (arc_maestro1);
  assign (arc_auxiliar1,'biblioteca.txt');
  reset (arc_auxiliar1);
  while not EOF (arc_auxiliar1)do
  begin;
   readln (arc_auxiliar1, libro1.cod_int);
   readln (arc_auxiliar1,libro1.ISBN);
   readln (arc_auxiliar1,libro1.cant_copias);
   readln (arch_auxiliar1,libro1.prestados);
   readln (arc_auxiliar1,libro1.total);
   writeln (arc_maestro1, libro1);
  end;
close (arc_maestro1);
close (arc_auxiliar);
writeln;
 end;
 
procedure alta_de_libro (var arc_maestro2:archivo; var libro2:reg_libro);
var aux2:integer;
begin
reset (arc_maestro2);
seek (arc_maestro2, filesize (arc_maestro2));
writeln ('ingrese el número de código interno del libro');
readln (aux2);
libro2.cod_int:=aux2;
writeln ('ingrese el ISBN');
readln (aux2);
libro2.ISBN:=aux2;
writeln ('ingrese la cantidad de copias disponibles en la biblioteca que no se pueden retirar');
readln (aux2);
libro2.cant_copias:=aux2;
writeln ('ingrese la cantidad de libros prestados por la biblioteca');
readln (aux2);
libro2.prestados:=aux2;
writeln ('ingrese el total de libros que posee la biblioteca');
readln (aux2);
libro2.total:=aux2;
close (arc_maestro);
end;
 
procedure modificar_libro (var arc_maestro3: archivo; var libro3: reg_libro);
var cod3:integer;
    opcion3: integer;
    aux3: integer;
begin
reset (arc_maestro3);
writeln ('ingrese el código del libro que desea modificar');
readln (cod3);
while not EOF (arc_maestro3) or (cod3=libro3.cod_int) do;
  read (arc_maestro3, libro3);
if EOF (arc_maestro3) then      // no sé cómo se escribe
  writeln ('no existe el código ingresado')
else
writeln ('si desea modificar la cantidad de copias disponibles ingrese 1, cantidad de libros prestados 2, total de libros 3');
read (opcion3);
case (opcion3)of
1: begin
   writeln ('ingrese el número de copias a modificar');
   read (aux3);
   libro3.cant_copias:=aux3;
   end;
2: begin
   writeln ('ingrese el número de libros prestados a modificar');
   read (aux3);
   libro3.prestados:=aux3;
   end;
3: begin
   writeln ('ingrese el número total de libros a modificar');
   read (aux3);
   libro3.total:=aux3;
   end;
end;
close (arc_maestro3);
writeln;
end;
 
 procedure eliminar_libro (var arc_maestro4: archivo; libro4: reg_libro);
var
aux4:integer;
begin
writeln ('ingrese el código del libro que desea eliminar');
read (aux4);
 while (aux4 <> libro4.cod_int) or EOF (arc_maestro4) do;
 begin
 readln (libro4.cod_int);
  if EOF (arc_maestro4) then
  writeln ('no existe el código ingresado')
  else
  libro4.cod_int:=0
 end
end;
 
  procedure listar (var arc_maestro5: archivo; libro5: reg_libro);
var
aux5: integer;
begin
while not EOF (arc_maestro5)do;
 begin
  read (arc_maestro, libro5);
  if (libro5.cod_int=0) then
  writeln (libro5.cod_int, libro5.ISBN, libro5.cant_copias, libro5.prestados, libro5.total)
  else
  writeln (libro5.cod_int, libro5.ISBN, libro5.cant_copias, libro5.prestados, libro5.total) ;
  writeln ('si desea listar el archivo modificado ingrese 1, si desea listar los libros eliminados ingrese 2');
  readln (aux5)
 end;
end;
 
begin
  repeat
  writeln ( ' Menu ');
  writeln ( ' Ingrese su opcion ');
  writeln ( '1 - Crear Archivo');
  writeln ( '2 - Alta de libro');
  writeln ( '3 - Modificar los datos de un libro ' );
  writeln ( '4 - Eliminar libro por codigo ' );
  writeln ( '5 - Listar');
  writeln ( '0 - Salir ' );
  read (opcion);
  case (opcion) of
   1: crear_archivo (arc_fisico, arc_auxiliar, arc_maestro, libro);
   2: alta_de_libro (arc_maestro, libro);
   3: modificar_libro (arc_maestro, libro);
   4: eliminar_libro (arc_maestro, libro);
   5: listar (arc_maestro, libro);
  end;
 until (opcion=0);
readln;
End.
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