Pascal/Turbo Pascal - ayuda para crear archivo de indice

 
Vista:

ayuda para crear archivo de indice

Publicado por Ximena (2 intervenciones) el 06/07/2013 02:19:29
Necesito que me ayuden a entender lo que es trabajar con archivos de indice y busqueda sobre el mismo!
gracias
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 para crear archivo de indice

Publicado por ramon (2158 intervenciones) el 06/07/2013 16:21:34
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
{Mira este programa veras el uso del archivo indice.
 El cual guarda el nombre y la posición del producto a buscar.}
 
  program archivos;
  uses
    crt;
   const
    nombre = 'c:\tp\bin\indice.dat';
 
  type
     indice = record
          nombre : string[10];
          posi   : longint;
         end;
 
     registro = record
          producto : string[10];
          precio   : real;
          posicion : integer;
          cantidad : integer;
        end;
 
 
 var
   archindi : file of indice;
   dat : indice;
   product : string[10];
   cont : integer;
   regi : file of registro;
   datos : registro;
   busca : longint;
 
  procedure crea_indice(da : indice);
  begin
      assign(archindi,nombre);
      {$I-} reset(archindi); {$I+}
      if ioresult <> 0 then
      begin
          rewrite(archindi);
          seek(archindi,0);
          write(archindi,da);
          close(archindi);
      end
    else
       begin
             seek(archindi,filesize(archindi));
             write(archindi,da);
             close(archindi);
          end;
       end;
 
  procedure entrada_datos;
  var
     tec : char;
     posicion : longint;
  begin
    repeat
     clrscr;
     writeln('***** Entrada Datos Productos *****');
     writeln;
     write('   Entre Nombre Producto       : ');
     readln(datos.producto);
     write('   Entre Precio Unidad         : ');
     readln(datos.precio);
     write('   Entre Num Posicion Almacen  : ');
     readln(datos.posicion);
     write('   Entre Cantidad De Productos : ');
     readln(datos.cantidad);
     assign(regi,'c:\tp\bin\producto.dat');
  {$I-} reset(regi); {$I+}
  if ioresult <> 0 then
  begin
      rewrite(regi);
      seek(regi,0);
      write(regi,datos);
      posicion := filesize(regi) - 1;
      close(regi);
  end
 else
    begin
       seek(regi,filesize(regi));
       write(regi,datos);
       posicion := filesize(regi) - 1;
       close(regi);
    end;
    dat.nombre := datos.producto;
    dat.posi := posicion;
    crea_indice(dat);
    clrscr;
    writeln('<<<<<< Desea entrar Mas Datos [S/N] >>>>>>>');
    repeat
    tec := upcase(readkey);
    until tec in['S','N'];
    until tec = 'N';
  end;
 
  procedure toma_referencia;
  var
     nom : string[10];
     buscado : string[10];
     i : integer;
  begin
     clrscr;
     writeln('<<<<<<<<< Entre Nombre Producto >>>>>>>>>>>');
     write('    Nombre : ');
     readln(nom);
     for i := 1 to length(nom) do
     nom[i] := upcase(nom[i]);
     assign(archindi,nombre);
   {$I-} reset(archindi); {$I+}
   if ioresult <> 0 then
   begin
       writeln('*** Falta El Archivo indice Pulse Una tecla ***');
       readkey;
       exit;
   end
 else
    begin
       for busca := 0 to filesize(archindi) - 1 do
       begin
       for i := 1 to length(dat.nombre) do
       begin
       buscado[i] := upcase(dat.nombre[i]);
       buscado[0] := chr(i);
       end;
       if buscado = nom then
       begin
           clrscr;
           assign(regi,'c:\tp\bin\producto.dat');
        {$I-} reset(regi); {$I+}
        if ioresult <> 0 then
        begin
           writeln('****** El Archivo No Existe Pulse Una Tecla *******');
           readkey;
        end
     else
        begin
           seek(regi,dat.posi);
           read(regi,datos);
           close(regi);
           writeln('**** Los Datos Del Producto Son ****');
           writeln;
           writeln('   Producto      : ',datos.producto);
           writeln('   Precio Unidad : ',datos.precio:0:2);
           writeln('   Posicion En   : ',datos.posicion);
           writeln('   Cantidad      : ',datos.cantidad);
           writeln;
           writeln('>>>>>>> Pulse Una Tecla <<<<<<<<<');
           readkey;
        end;
      end;
    end;
   end;
  end;
 
  procedure menu;
  var
    sal : boolean;
    teb : char;
  begin
     sal := false;
   repeat
      clrscr;
      writeln('   ****** Menu General ******');
      writeln;
      writeln('   1 = Entrada De Productos');
      writeln('   2 = Busqueda De Producto');
      writeln('   3 = Salir');
      writeln;
      writeln('   <<<< Elija Opcion >>>>');
      repeat
          teb := readkey;
      until teb in['1','2','3'];
      clrscr;
    case teb of
  '1' : entrada_datos;
  '2' : toma_referencia;
  '3' : 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

ayuda para crear archivo de indice

Publicado por Ximena (2 intervenciones) el 07/07/2013 22:39:54
Mil Gracias!!
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