Pascal/Turbo Pascal - probled}ma simple de archivo

 
Vista:
sin imagen de perfil

probled}ma simple de archivo

Publicado por Diego (98 intervenciones) el 20/03/2014 02:32:35
Buenas noches, no pude encontrar el error por el cual me devuelve al menú principal; Les agradezco su paciencia.
este es el enunciado:

Hacer un programa con un menú principal cíclico con opciones para
a) Crear y cargar un archivo de números enteros arch: File of Integer con una cantidad de números
solicitada al usuario que se generan pseudoaleatoriamente con e:=Random( maxUIntValue ) –
maxint (antes de la generación se debe inicializar a la función generadora con Randomize). El archivo
debe llamarse por defecto ‘enteros’.
b) Abrir un archivo existente de números enteros, con un submenú cíclico para
i) Exportar los números generados a un archivo de texto por defecto ‘numeros.txt’, de a doce por
línea y en columnas de seis caracteres de ancho: Write(t, e:6), con t: Text y asignado con
‘numeros.txt’.
ii) Informar la cantidad de números positivos y negativos del archivo, con opción de exportarlos a
los archivos de texto por defecto ‘positivos.txt’ y ‘negativos.txt’, de a doce por línea y también
encolumnados.
iii) Informar la cantidad de números pares (n mod 2 = 0) e impares (n mod 2 = 1) del archivo, con
opción de exportarlos a los archivos de texto por defecto ‘pares.txt’ y ‘nones.txt’, de a doce por
línea y también encolumnados.
iv) Informar la cantidad de números pares negativos, impares negativos, pares positivos e impares
positivos con opción de exportarlos a los archivos por defecto ‘pares_neg.txt’, ‘nones_neg.txt’,
‘pares_pos.txt’ y ‘nones_pos.txt’, de a doce por línea y también encolumnados.

este en mi codigo:
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
program uno;
type
    t_arch = file of integer;
procedure cont_posi(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if (not (aux < 0)) then
          num := num + 1;
      end;
  end;
procedure cont_neg(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if (aux < 0) then
          num := num + 1;
      end;
  end;
procedure cont_par_posi(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) = 0) then
          if (not (aux < 0)) then
            num := num + 1;
      end;
  end;
procedure cont_par_neg(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) = 0) then
          if (aux < 0) then
            num := num + 1;
      end;
  end;
procedure cont_impar_posi(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) <> 0) then
          if (not (aux < 0)) then
            num := num + 1;
      end;
  end;
procedure cont_impar_neg(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) <> 0) then
          if (aux < 0) then
            num := num + 1;
      end;
  end;
procedure cont_par(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) = 0) then
 
            num := num + 1;
      end;
  end;
procedure cont_impar(var arch : t_arch; var num: integer);
  var
    aux : integer;
  begin
    num := 0;
    reset(arch);
    while (not eof(arch)) do
      begin
        read(arch, aux);
        if ((aux mod 2) <> 0) then
 
            num := num + 1;
      end;
  end;
var
    e, indice : integer;
    arch : t_arch;
    num, opc, opc2 : integer;
    arch_texto : text;
    check : char;
    arch_posi : text;
    arch_neg : text;
    arch_par : text;
    arch_impar : text;
    arch_par_posi : text;
    arch_par_neg : text;
    arch_impar_posi : text;
    arch_impar_neg : text;
begin
    Randomize;
    opc := 1;
    while (opc <> 4) do
      begin
        e := random(48);
        writeln('Elija una opción:)');
        writeln('(1)-- Crear un archivo');
        writeln('(2)-- Cargar un archivo');
        writeln('(3)-- Abrir un archivo existente');
        writeln('(4)-- Salir)');
        readln(opc);
        if (opc = 1) then
          assign(arch, 'enteros')
        else
           if (opc = 2) then
             begin
               if (e <> 0) then
                 begin
                  rewrite(arch);
                  writeln('"Debe ingresar ', e, ' numeros enteros"');
                  for indice := 1 to e do
                      begin
                        write('Ingrse un número entero: ');
                        readln(num);
                        write(arch, num);
                      end;
                 end;
             end
           else
             if (opc = 3) then
               begin
                 writeln(' elija un aopción: ');
                 writeln('(1)-- Exportar numeros a un txt');
                 writeln('(2)-- Informar la cantidad de números positivos y negativos');
                 writeln('(3)-- Informar la cantidad de números pares e impares');
                 writeln('(4)-- Informar la cantidad de números pares negativos, impares negativos, pares positivos e impares positivos');
 
                 read(opc2);
                 case  opc2 of
                   1: begin
                        assign(arch_texto, 'numeros.txt');
                        reset(arch);
                        seek(arch, 0);
                        rewrite(arch_texto);
                        while (not eof(arch)) do
                          begin
                            read(arch, num);
                            write(arch_texto, num:6);
                          end;
                        close(arch_texto);
                      end;
                   2: begin
                        cont_posi(arch, num);
                        write('Hay ', num, ' números positivos y ');
                        cont_neg(arch, num);
                        writeln(num, ' negativos');
                        write('¿Desea exportalos a positivos.txt y negativos.txt respectivamente? (s/n)');
                        readln(check);
                        if (check = 's') then
                          begin
                            assign(arch_posi, 'positvos.txt');
                            assign(arch_neg, 'negativos.txt');
                            reset(arch);
                            seek(arch,0);
                            rewrite(arch_posi);
                            rewrite(arch_neg);
                            while (not eof(arch)) do
                              begin
                                read(arch, num);
                                if (num > 0) then
                                    write(arch_posi, num:6)
                                else
                                    write(arch_neg, num:6);
                              end;
                            close(arch_posi);
                            close(arch_neg);
                            close(arch);
                          end;
                      end;
                   3:  begin
                        cont_par(arch, num);
                        write('Hay ', num, ' números pares y ');
                        cont_impar(arch, num);
                        writeln(num, ' impares');
                        write('¿Desea exportalos a pares.txt e impares.txt respectivamente? (s/n)');
                        readln(check);
                        if (check = 's') then
                          begin
                            assign(arch_par, 'pares.txt');
                            assign(arch_impar, 'impares.txt');
                            reset(arch);
                            seek(arch, 0);
                            rewrite(arch_par);
                            rewrite(arch_impar);
                            while (not eof(arch)) do
                              begin
                                read(arch, num);
                                if ((num mod 2) = 0) then
                                    write(arch_par, num:6)
                                else
                                    write(arch_impar, num:6);
                              end;
                            close(arch_par);
                            close(arch_impar);
                            close(arch);
                          end;
                      end;
                   4: begin
                        cont_par_posi(arch, num);
                        write('Hay ', num, ' números pares positivos y ');
                        cont_par_neg(arch, num);
                        writeln(num, ' pares negativos');
                        cont_impar_posi(arch, num);
                        write('Hay ', num, ' números impares positivos y ');
                        cont_impar_neg(arch, num);
                        writeln(num, ' impares negativos');
                        write('¿Desea exportalos a ‘pares_neg.txt’, ‘nones_neg.txt’,‘pares_pos.txt’ y ‘nones_pos.txt’ respectivamente? (s/n)');
                        readln(check);
                        if ((check = 's') or (check = ' ')) then
                          begin
                            assign(arch_par_posi, 'pares_pos.txt');
                            assign(arch_par_neg, 'pares_neg.txt');
                            assign(arch_impar_posi, 'nones_pos.txt');
                            assign(arch_impar_neg, 'nones_neg.txt');
                            reset(arch);
                            seek(arch, 0);
                            rewrite(arch_par_posi);
                            rewrite(arch_par_neg);
                            rewrite(arch_impar_posi);
                            rewrite(arch_impar_neg);
                            while (not eof(arch)) do
                              begin
                                read(arch, num);
                                if (num > 0) then
                                  if ((num mod 2) = 0) then
                                      write(arch_par_posi, num:6)
                                  else
                                      write(arch_par_neg, num:6)
                                else
                                  if ((num mod 2) = 0) then
                                    write(arch_par_neg, num:6)
                                  else
                                    write(arch_impar_neg, num:6);
                              end;
                            close(arch_par_posi);
                            close(arch_par_neg);
                            close(arch_impar_posi);
                            close(arch_impar_neg);
                            close(arch);
                          end;
                      end;
               end;
      end;
      end;
    readln();
    readln();
    write();
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

probled}ma simple de archivo

Publicado por ramon (2158 intervenciones) el 24/03/2014 00:03:35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{Mira esta parte esta la ejecución como te pasa no hace nada}
 
 readln(opc);
        if (opc = 1) then
          assign(arch, 'enteros')
        else
           if (opc = 2) then
             begin
               if (e <> 0) then
                 begin
                  rewrite(arch);
                  writeln('"Debe ingresar ', e, ' numeros enteros"');
                  for indice := 1 to e do
                      begin
                        write('Ingrse un número entero: ');
                        readln(num);
                        write(arch, num);
                      end;
                 end;
             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
sin imagen de perfil

probled}ma simple de archivo

Publicado por Diego (98 intervenciones) el 24/03/2014 21:20:23
No estoy seguro de lo que queres decir pero creo que está bien esa parte, aunque intenté colocando un readln(); antes de la lectura del caracter de confirmacion para la generacion del .txt(aunque aun no sé si crea uno o solo nombra al archivo con ese nombre.txt) y fuincionó al parecer ya que esta vez si me dejó ingresar el caracter de confirmación.
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