Pascal/Turbo Pascal - Ayuda a un novato con un programa básico de guardar archivos en un texto (pascal)

 
Vista:

Ayuda a un novato con un programa básico de guardar archivos en un texto (pascal)

Publicado por Takumorinkashi (1 intervención) el 14/10/2013 23:01:33
Buenas, paso por aquí porque en la universidad la profesora se enfermó todo el año y ahora al volver nos está exigiendo realizar un programa que vale mas de la mitad de la nota y como comprenderán no tengo la practica suficiente para el plazo que nos dio (1 semana)

El enunciado dice así:

Elabore un programa en pascal que cree un archivo de datos llamado estudiante.dat de 5 registros con la siguiente información: Cédula (campo clave), nombre, edad, fecha de nacimiento.

Luego cree un menu de opciones que permita:

1- Ingresar nuevo estudiante.
2- Eliminar estuidante.
3- Consultar: 1 estudiante, todos los estudiantes.
4- Modificar cedula.

Esto es todo, de antemano muchas gracias al que pueda ayudarme, mi familia y yo se lo agradeceremos el resto de la vida por ayudarme a salvar el año.
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

Ayuda a un novato con un programa básico de guardar archivos en un texto (pascal)

Publicado por ramon (2158 intervenciones) el 18/10/2013 11:24:27
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
{A ver si esto te sirve}
 
program estudiantes;
  uses
     crt;
  type
    estudi = record
           ncedula : longint;
           nombre  : string[100];
           direcc  : string[150];
           edad    : integer;
           nacimi  : string[10];
         end;
 
  var
    f : file of estudi;
    datos : estudi;
    tecla : char;
 
   function presente(dd : longint) : boolean;
   var
    f3 : file of estudi;
    dat : estudi;
    ii : longint;
    esta : boolean;
    begin
       assign(f3,'Estudint.dat');
     {$I-} reset(f3); {$I+}
     if ioresult <> 0 then
   begin
      writeln('*** El Archivo No Esta Pulse Una Tecla ***');
      readln;
   end
  else
      begin
       presente := false;
       esta := false;
       ii := 0;
     repeat
       seek(f3,ii);
       read(f3,dat);
       if dat.ncedula = dd then
       esta := true
     else
       ii := ii + 1;
     until (ii > filesize(f3) - 1) or (esta = true);
     if esta = true then
     presente := true;
    end;
  end;
 
   procedure entradadatos;
   begin
      clrscr;
      writeln('***** Entrada Datos Estudiantes *****');
      writeln;
      write('   Entre Num. Cedula  : ');
      readln(datos.ncedula);
      if presente(datos.ncedula) = true then
      begin
         clrscr;
         writeln('??? El Numero Cedular Entrado Existe Pulse Una Tecla ???');
         readkey;
      end
   else
      begin
      write('   Entre Nombre       : ');
      readln(datos.nombre);
      write('   Entre Direccion    : ');
      readln(datos.direcc);
      write('   Entre Edad         : ');
      readln(datos.edad);
      write('   Entre Fecha Nacim. : ');
      readln(datos.nacimi);
      assign(f,'Estudint.dat');
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
       rewrite(f);
       seek(f,0);
       write(f,datos);
       close(f);
   end
 else
    begin
       seek(f,filesize(f));
       write(f,datos);
       close(f);
    end;
  end;
 end;
 
  procedure elimina;
  var
    f1 : file of estudi;
    temp : estudi;
    i, gg, pp, cedu : longint;
    anul : boolean;
  begin
      clrscr;
      writeln('***** Eliminacion estudiante *****');
      writeln;
      write('   Entre Num. Cedula : ');
      readln(cedu);
      assign(f,'Estudint.dat');
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
      writeln('  ???? Archivo No Existente Pulse Una Tecla ????');
      readkey;
   end
  else
     begin
        pp := 0;
        anul := false;
        repeat
          seek(f,pp);
          read(f,datos);
          if datos.ncedula = cedu then
          anul := true
        else
          pp := pp + 1;
        until (pp > filesize(f) - 1) or (anul = true);
        if anul = true then
        begin
           assign(f1,'Tempor.ggg');
           rewrite(f1);
           gg := 0;
           i := 0;
        repeat
            seek(f,i);
            read(f,datos);
            if i <> pp then
            begin
               temp := datos;
               seek(f1,gg);
               write(f1,temp);
               gg := gg + 1;
            end;
            i := i + 1;
        until i > filesize(f) - 1;
        end;
        close(f);
        close(f1);
        erase(f);
        rename(f1,'Estudint.dat');
     end;
  end;
 
  procedure Consultar;
  var
    ar, codi : longint;
    tt : char;
    enco : boolean;
  begin
     clrscr;
     writeln('***** Consulta De Datos *****');
     writeln;
     writeln('   Elija [U]=Uno  [T]=Todos');
     repeat
          tt := upcase(readkey);
     until tt in['U','T'];
     assign(f,'Estudint.dat');
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
      writeln('  ???? Archivo No Existente Pulse Una Tecla ????');
      readkey;
   end
  else
     begin
     ar := 0;
     enco := false;
     case tt of
  'U' : begin
           write('   Entre Num. Cedula : ');
           readln(codi);
          repeat
             seek(f,ar);
             read(f,datos);
             if datos.ncedula = codi then
             enco := true
           else
             ar := ar + 1;
          until (ar > filesize(f) - 1) or (enco = true);
          clrscr;
          if enco = true then
          begin
              writeln('**** Los Datos Solicitados Son ****');
              writeln;
              writeln('   Num. Cedula      : ',datos.ncedula);
              writeln('   Nombre           : ',datos.nombre);
              writeln('   Direccion        : ',datos.direcc);
              writeln('   Edad             : ',datos.edad);
              writeln('   Fecha Nacimiento : ',datos.nacimi);
              writeln;
              writeln('   Pulse Una Tecla ');
          end
        else
           begin
             writeln('  Num. Cedula No Encontrado Pulse Una Tecla ');
           end;
           readkey;
        end;
  'T' : begin
             ar := 0;
           repeat
              clrscr;
              seek(f,ar);
              read(f,datos);
              writeln('   Num. Cedula      : ',datos.ncedula);
              writeln('   Nombre           : ',datos.nombre);
              writeln('   Direccion        : ',datos.direcc);
              writeln('   Edad             : ',datos.edad);
              writeln('   Fecha Nacimiento : ',datos.nacimi);
              writeln;
              writeln('   Pulse  [',chr(24),'] [',chr(25),']  [ESC] Fin ');
              repeat
                   tt := readkey;
              until tt in[#72,#80,#27];
              if tt = #27 then
              enco := true;
              if tt = #72 then
              begin
              ar := ar - 1;
              if ar < 0 then
              ar := 0;
              end;
              if tt = #80 then
              begin
              ar := ar + 1;
              if ar > filesize(f) - 1 then
              ar := filesize(f) - 1;
              end;
              clrscr;
          until enco = true;
        end;
     end;
       close(f);
    end;
   end;
 
   procedure Modificar_num_cedula;
   var
     u, cedu1, modi1 : longint;
     sal : boolean;
   begin
       clrscr;
       writeln('**** Modificacion Num. Cedula ****');
       writeln;
       write('  Entre Num. A Modificar : ');
       readln(cedu1);
       u := 0;
       sal := false;
       assign(f,'Estudint.dat');
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
      writeln('  ???? Archivo No Existente Pulse Una Tecla ????');
      readkey;
   end
  else
     begin
     clrscr;
     repeat
       seek(f,u);
       read(f,datos);
       if datos.ncedula = cedu1 then
       sal := true
     else
      u := u + 1;
      until (u > filesize(f) - 1) or (sal = true);
      if sal = true then
      begin
         write('   Entre Nuevo Num. : ');
         readln(modi1);
         datos.ncedula := modi1;
         seek(f,u);
         write(f,datos);
      end
    else
      begin
         writeln('  Num. Cedula No Encontrado Pulse Una Tecla ');
         readkey;
      end;
      close(f);
     end;
   end;
 
 
  procedure menu;
  var
    opc, teb : char;
    sal : boolean;
  begin
      sal := false;
    repeat
       clrscr;
       writeln('***** Menu Principal *****');
       writeln;
       writeln('  1 = Entradas Datos Estudiante');
       writeln('  2 = Eliminar Estudiante ');
       writeln('  3 = Consultar Estudiante/s');
       writeln('  4 = Modificar Num. Cedula');
       writeln('  5 = Salir');
       writeln;
       writeln('<<<<<< Elija Opcion >>>>>>');
       repeat
           teb := readkey;
       until teb in['1','2','3','4','5'];
       clrscr;
     case teb of
  '1' : entradadatos;
  '2' : elimina;
  '3' : Consultar;
  '4' : Modificar_num_cedula;
  '5' : sal := true;
    end;
    until sal = true;
  end;
 
   begin
      menu;
   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