Pascal/Turbo Pascal - Array de registro de comercio

 
Vista:
sin imagen de perfil

Array de registro de comercio

Publicado por Horacio (53 intervenciones) el 19/10/2012 03:26:22
Hola a todos,Ayuda con este ejercicio:

Un comercio tiene el inventario de productos en una base de datos que contiene algo
menos de 8000 ítems. Los registros de la base de datos tienen el siguiente diseño:
Nro Item, Producto, Marca, Tipo, Costo, Stock Mínimo, Stock Actual
Se quiere realizar las siguientes operaciones:

a) Insertar nuevos productos
b) Borrar productos
c) Modificar productos
d) Buscar un producto

Simular la base de datos con un arreglo de 10000 elementos, de modo que siempre se
encuentren ordenados por Nro Item y que las ultimas posiciones se encuentren disponibles. Si
se alcanzara la capacidad máxima del vector, debe indicarse con un mensaje.

aca les dejo la codificacion que hize yo:

http://pastebin.com/D36QA6zS

la idea es que me puedan decir si esta bien planteado el ejercicio y si hay que corregir algo.desde ya 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

Array de registro de comercio

Publicado por ramon (2158 intervenciones) el 19/10/2012 20:01:51
Disculpa pero pascal no te permitirá manejar esa longitud de array excepto que uses punteros.
Por tamaño de memoria no por otra causa cosas del dos.
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

Array de registro de comercio

Publicado por Horacio (53 intervenciones) el 20/10/2012 01:21:22
ah eso no lo sabia,y ramon modificando el tamaño del arreglo lo demas estaria bien?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

Array de registro de comercio

Publicado por ramon (2158 intervenciones) el 20/10/2012 13:30:41
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
{Comprueba tu mismo los errores después de realizar cada labor presenta los datos y lo veras.}
 
 program comercio;
  uses
     crt;
  const
       max = 100;
 
  type
   {// tipo de registro de producto }
   Rproducto = record
        Nro : integer;
        Producto: string[20];
        Marca : string[20];
        Tipo : string[10];
        Costo : real;
        Stockmin : integer;
        Stockact : integer;
   end;
   {// tipo de array de registro }
   Tarray = array[1..max] of Rproducto;
   var
       len : integer;
       registro : Tarray;
       reg : Tarray;
   procedure insertar(var reg:Tarray;var len:integer);
   var
        opc : char;i : integer;
     begin
        opc := 'S';
         if (len = 0) then
         i := 1
       else
          i := len;
      writeln('Insertar nuevos productos');
    while (opc = 'S') and (i <= max) do
    begin
        clrscr;
        write('Numero de producto: ');
        readln(reg[i].Nro);
        write('Producto: ');
        readln(reg[i].Producto);
        write('Marca: ');
        readln(reg[i].Marca);
        write('Tipo: ');
        readln(reg[i].Tipo);
        write('Costo: ');
        readln(reg[i].Costo);
        write('Stock minimo: ');
        readln(reg[i].Stockmin);
        write('Stock Actual: ');
        readln(reg[i].Stockact);
        writeln;
        len := len + 1;
        writeln('Desea agregar otro producto (S/N): ');
        repeat
           opc := upcase(readkey);
        until (opc in ['S','N']);
        clrscr;
        i := i + 1;
     end;
  end;
 
procedure ordenar(var reg:Tarray;len:integer);
var ordenado:boolean; j : integer;
var aux : Rproducto;
begin
    ordenado := false;
    while (not ordenado)  do begin
                ordenado := true;
         for j := 1 to (len-1) do begin
                if (reg[j].Nro > reg[j+1].Nro) then begin
                aux := reg[j+1];
               reg[j+1] := reg[j];
               reg[j] := aux;
               ordenado := false;
            end;
         end;
    end;
end;
 
function busquedabinaria(len:integer;x:integer):integer;
var i,j,k : integer;
var encontrado : boolean;
begin
    encontrado:= false;
    i := 1;
    j := len;
    while (i <= j) and (not encontrado) do begin
                k := (i+j) div 2;
         if (reg[k].Nro = x) then begin
                encontrado:= true;
         end else begin
                if (reg[k].Nro > x) then begin
                i := k + 1;
            end  else begin
                j := k - 1;
            end;
         end;
    end;
    if (i > j) then begin
                busquedaBinaria := -1;
    end else begin
                busquedaBinaria := k;
    end;
end;
 
procedure Busqueda(len:integer);
var  num,pos : integer;
begin
    clrscr;
    writeln('Busqueda de productos');
    write('Ingrese numero de producto: ');
    readln(num);
    pos := busquedaBinaria(len,num);
    if (pos < 0) then begin
                writeln('El producto no existe');
         exit;
    end else begin
        write('Numero de producto: ');
        writeln(reg[pos].Nro);
        write('Producto: ');
        writeln(reg[pos].Producto);
        write('Marca: ');
        writeln(reg[pos].Marca);
        write('Tipo: ');
        writeln(reg[pos].Tipo);
        write('Costo: ');
        writeln(reg[pos].Costo);
        write('Stock minimo: ');
        writeln(reg[pos].Stockmin);
        write('Stock Actual: ');
        writeln(reg[pos].Stockact);
    end;
end;
 
procedure eliminar(var reg:Tarray;pos:integer;var len:integer);
var i : integer;
begin
     for i := pos to (len-1) do begin
                reg[i] := reg[i+1];
     end;
     len := len - 1;
end;
 
procedure borrar(var reg:Tarray;len:integer);
var num : integer; pos : integer;
    opc : char;
begin
        repeat
    clrscr;
    writeln('Borrar registro de un producto');
    writeln('Ingrese numero de producto: ');
    readln(num);
    pos := busquedaBinaria(len,num);
    if (pos < 0) then begin
                writeln('El producto no se encuentra');
    end else begin
                writeln('Producto: ',reg[pos].Producto);
         writeln('Marca: ',reg[pos].Marca);
    end;
    repeat
                writeln('Esta seguro de borrar el registro (S/N): ');
                opc := readkey;
                opc := upcase(opc);
    until (opc in ['S','N']);
    if (opc = 'S') then begin
                eliminar(reg,pos,len);
    end;
    repeat
        writeln('Desea borrar otro producto (S/N): ');
        opc := readkey;
      opc := upcase(opc);
    until (opc in ['S','N']);
        until (opc = 'N');
end;
 
procedure modificar(var reg:Tarray;len:integer);
var  Producto,Marca,Tipo : string;opc : char;
var Costo : real; Stockmin,Stockact : integer;
var num,pos:integer;
begin
        repeat
        clrscr;
    writeln('Modificacion de productos');
    writeln('Ingrese el numero de producto: ');
    readln(num);
    pos := busquedaBinaria(len,num);
    if (pos < 0) then begin
                writeln('El producto no existe');
         exit;
    end else begin
        write('Producto: ');
        readln(Producto);
        write('Marca: ');
        readln(Marca);
        write('Tipo: ');
        readln(Tipo);
        write('Costo: ');
        readln(Costo);
        write('Stock minimo: ');
        readln(Stockmin);
        write('Stock Actual: ');
        readln(Stockact);
        reg[pos].Producto := Producto;
        reg[pos].Marca := Marca;
        reg[pos].Tipo := Tipo;
        reg[pos].Costo := Costo;
        reg[pos].Stockmin := Stockmin;
        reg[pos].Stockact := Stockact;
    end;
    writeln('El registro se ha modificado');
    repeat
        writeln('Desea modificar otro producto (S/N): ');
        opc := readkey;
      opc := upcase(opc);
    until (opc in ['S','N']);
        until (opc = 'N');
  end;
 
  procedure presentadatos;
  var
    y, nn : integer;
  begin
      clrscr;
      gotoxy(2,1);write('N§    Producto    Marca     Tipo     Costo');
      y := 2;
      for nn := 1 to len do
      begin
      gotoxy(2,y);write(reg[nn].Nro);
      gotoxy(8,y);write(reg[nn].Producto);
      gotoxy(20,y);write(reg[nn].Marca);
      gotoxy(30,y);write(reg[nn].Tipo);
      gotoxy(39,y);write(reg[nn].Costo:0:2);
      y := y + 1;
      if y > 24 then
      y := 24;
  end;
     gotoxy(3,y + 1);write('***** Pulse [Enter] *****');
     readln;
 end;
 
procedure menu;
var  fin:boolean;opc:char;
begin
        fin := false;
    repeat
                clrscr;
         writeln('************MENU GENERAL*************');
         writeln('Insertar nuevos productos.....[1]');
         writeln('Borrar productos..............[2]');
         writeln('Modificar productos...........[3]');
         writeln('Buscar un producto............[4]');
         writeln('Presenta Datos................[5]');
         writeln('Salir.........................[6]');
         repeat
                writeln('Escoja una opcion:  ');
                opc := readkey;
         until (opc in ['1'..'6']);
         case opc of
         '1' : begin
               insertar(reg,len);
               ordenar(reg,len);
                        end;
         '2' : begin
               borrar(reg,len);
               ordenar(reg,len);
               end;
         '3' : modificar(reg,len);
         '4' : busqueda(len);
         '5' : presentadatos;
         '6' : fin := true;
         end;
    until fin;
  end;
 
 
   begin
        len := 0;
        clrscr;
        menu;
    end.
 
{Lo tienes que mejorar bastante funciona mal}
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