Pascal/Turbo Pascal - Ayuda para realizar un programa en Pascal para registrar ventas de un producto

 
Vista:
sin imagen de perfil

Ayuda para realizar un programa en Pascal para registrar ventas de un producto

Publicado por Héctor (8 intervenciones) el 28/04/2013 21:22:49
"Ventas"
El registro de las ventas diarias de un producto es una labor cotidiana en cualquier empresa, negocio o actividad que ofrezca bienes y servicio. El cálculo del monto total de venta, unidades vendidas, permite conocer el funcionamiento del negocio al identificar el producto que más se vende, el producto que genera mayor ganancia, etc. Los sistemas informáticos que más demanda tienen son aquellos que dan informacion de ventas, también conocidos como Business intelligence.

Archivo ventas.dat:
El archivo ventas. dat contiene varios renglones de datos que corresponden al registro de ventas de un negocio particular. Cada renglón (registro) está compuesto por 3 columnas, la primera corresponde al código del producto, la segunda a las unidades vendidas y la tercera al precio unitario. El archivo puede contener renglones en los que se repite el dato de la primera columna (campo) correspondiente al código del artículo. Esto significa que durante un periodo de venta, dicho artículo repitió su venta. Por tanto ventas. dat contiene varios productos y la venta que tuvo en el periodo al que corresponde el archivo.

Programa:
Tu programa leerá el archivo ventas.dat y agruparará los datos de cada producto mostrando la suma total de unidades, y la venta acumulada. Se mostrará en pantalla, una tabla con el código de cada producto y las unidades y venta total por producto, además de la venta total de la empresa correspondiente a los datos de ventas.

Ejemplo:
El archivo puede contener varias líneas del producto 117 con unidades y tal vez precio de venta variable:
117 12 10.5
117 4 11.0
117 3 10.5
El resultado puede verse que para el primer renglón la venta fue 12*10.5=126, para el segundo renglón fue 44 y para el tercero 31.5. Entonces el acumulado será:
117 19 201.5
Así tendrás que hacer para cada artículo y finalmente hacer la suma total de ventas.

Hint:
Debes leer el archivo, tal vez más de una ocasión. Es importante que guardes en memoria, los productos y sus datos para poder hacer las sumas acumuladas.

Aqui los datos del archivo "ventas.dat"
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 5 10.5
124 7 12
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 5 10.5
124 8 12
318 4 16
322 2 18.5
455 3 19
172 7 14
221 8 13.2
217 9 11
422 2 14.5
101 3 21
117 5 10.5
124 7 12
318 4 16
322 5 18.5
455 6 19
172 7 14
117 6 10.5
124 8 12
318 5 16
322 3 18.5
455 7 19
172 7 14
221 9 13.2
217 10 11
422 2 14.5
101 5 21
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 6 10.5
124 6 12
318 3 16
322 1 18.5
455 5 19
172 8 14
221 7 13.2
217 8 11
422 2 14.5
101 4 21
117 6 10.5
124 8 12
318 5 16
322 3 18.5
455 7 19
172 8 14
221 9 13.2
217 8 11
422 5 14.5
101 2 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
117 4 10.5
124 6 12
318 5 16
322 2 18.5
455 5 19
172 3 14
221 7 13.2
217 8 11
422 5 14.5
101 3 21
322 2 18.5
455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 6 10.5
124 7 12
318 6 16
322 3 18.5
455 9 19
172 2 14
221 5 13.2
217 4 11
422 5 14.5
101 9 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
117 9 10.5
124 8 12
318 6 16
322 4 18.5
455 9 19
172 9 14
221 9 13.2
217 2 11
422 3 14.5
101 5 2
1455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 5 19
172 7 14
221 8 13.2
217 9 11
422 5 14.5
101 4 21
117 9 10.5
124 8 12
318 5 16
322 4 18.5
455 8 19
172 9 14
221 8 13.2
217 9 11
422 5 14.5
101 6 21
117 7 10.5
124 7 12
318 8 16
322 8 18.5
455 8 19
172 7 14
221 8 13.2
217 9 11
422 2 14.5
101 6 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
422 1 14.5
101 4 21
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
172 7 14
221 8 13.2
117 5 10.5
124 7 12
318 4 16
322 2 18.5
455 6 19
172 7 14
221 8 13.2
217 9 11
422 1 14.5
101 4 21
117 3 10.5
124 8 12
318 4 16
322 5 18.5
455 5 19
172 7 14
221 8 13.2
217 9 11
422 8 14.5
101 4 21
117 5 10.5
124 7 12
318 4 16
221 8 13.2
217 9 11
422 1 14.5

espero me puedan ayudar, ya que con puedo relaizar ninguna accion requerida, les agradesco de natemano y que tengas suerte en todo lo que realizen.
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 realizar un programa en Pascal para registrar ventas de un producto

Publicado por franco sanguedolce (32 intervenciones) el 30/04/2013 20:14:55
Hector te hago una pregunta, en la consigna e lo que debe realizar tu programa se da por sobreentendido que ya sabes trabajar con archivos, es asi??? O necesitas esa info tamb?
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 realizar un programa en Pascal para registrar ventas de un producto

Publicado por ramon (2158 intervenciones) el 30/04/2013 21:05:59
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
{A ver si esto ayuda}
 
 program acomercio;
 uses
    crt;
  type
    regbentas = record
            codigo : word;
            ventas : real;
            precio : real;
          end;
   const
       max = (60000 div sizeof(regbentas));
       archivo = 'ventas.dat';
 datit : array[0..99,1..3] of real = (
(117,5,10.5),(124,7,12),(318,4,16),(322,2,18.5),(455,6,19),
(172,7,14),(221,8,13.2),(217,9,11),(422,1,14.5),(101,4,21),
(117,5,10.5),(124,7,12),(172,7,14),(221,8,13.2),(217,9,11),
(422,1,14.5),(101,4,21),(117,5,10.5),(124,8,12),(318,4,16),
(322,2,18.5),(455,3,19),(172,7,14),(221,8,13.2),(217,9,11),
(422,2,14.5),(101,3,21),(117,5,10.5),(124,7,12),(318,4,16),
(322,5,18.5),(455,6,19),(172,7,14),(117,6,10.5),(124,8,12),
(318,5,16),(322,3,18.5),(455,7,19),(172,7,14),(221,9,13.2),
(217,10,11),(422,2,14.5),(101,5,21),(221,8,13.2),(217,9,11),
(422,1,14.5),(101,4,21),(117,6,10.5),(124,6,12),(318,3,16),
(322,1,18.5),(455,5,19),(172,8,14),(221,7,13.2),(217,8,11),
(422,2,14.5),(101,4,21),(117,6,10.5),(124,8,12),(318,5,16),
(322,3,18.5),(455,7,19),(172,8,14),(221,9,13.2),(217,8,11),
(422,5,14.5),(101,2,21),(117,5,10.5),(124,7,12),(318,4,16),
(322,2,18.5),(455,6,19),(172,7,14),(221,8,13.2),(217,9,11),
(422,1,14.5),(101,4,21),(117,5,10.5),(124,7,12),(318,4,16),
(322,2,18.5),(455,6,19),(117,4,10.5),(124,6,12),(318,5,16),
(322,2,18.5),(455,5,19),(172,3,14),(221,7,13.2),(217,8,11),
(422,5,14.5),(101,3,21),(322,2,18.5),(455,6,19),(172,7,14),
(221,8,13.2),(217,9,11),(422,1,14.5),(101,4,21),(117,6,10.5));
 
   var
    bentas : array[1..max] of regbentas;
    dis, cont : word;
    f : file of regbentas;
    ini : char;
  procedure entradatos;
  var
    sal : boolean;
    se, gu, rt : longint;
    tec : char;
  begin
     clrscr;
     sal := false;
     writeln('***** Entrada De Datos *****');
     writeln;
     rt := 1;
   repeat
       write(' Codigo        : ');
       readln(bentas[rt].codigo);
       write(' Unidades      : ');
       readln(bentas[rt].ventas);
       write(' Precio Unidad : ');
       readln(bentas[rt].precio);
       writeln;
       writeln(' Desea Entrar Mas [S/N]');
       repeat
           tec := upcase(readkey);
       until tec in['S','N'];
       if tec = 'S' then
       rt := rt + 1;
       if tec = 'N' then
       sal := true;
   until (sal = true) or (rt > max);
    assign(f, archivo);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
       rewrite(f);
       for gu := 0 to rt do
       begin
       seek(f,gu);
       write(f,bentas[gu]);
       end;
       close(f);
    end
  else
     begin
        gu := filesize(f) - 1;
        for se := 1 to rt do
        begin
           seek(f,gu + se);
           write(f,bentas[se]);
        end;
        close(f);
     end;
   end;
 
   procedure genera_archivo;
   begin
       assign(f, archivo);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
       rewrite(f);
       for dis := 0 to 99 do
       begin
         bentas[dis].codigo := round(datit[dis,1]);
         bentas[dis].ventas := datit[dis,2];
         bentas[dis].precio := datit[dis,3];
         seek(f,dis);
         write(f,bentas[dis]);
        end;
        close(f);
      end
   else
      close(f);
      clrscr;
   end;
 
   procedure presentadatos;
   var
     tom : word;
     q, t, k : longint;
     vent : real;
     totalp, totalv : real;
   begin
       clrscr;
       writeln('**** Muesta Contenido Archivo [ ',archivo,' ] ****');
       writeln;
       writeln(' Codigo      Unidades     Total Productos');
       assign(f, archivo);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
        writeln;
        writeln('   El Archivo ',archivo,' No Encontrado Pulse Una Tecla');
        exit;
    end
  else
      begin
         k := 0;
         vent := 0;
         totalp := 0;
         totalv := 0;
       repeat
          seek(f,k);
          read(f,bentas[k + 1]);
          k := k + 1;
       until (k > filesize(f) - 1) or (k > max);
        close(f);
        for t := 1 to k - 1 do
        if bentas[t].codigo > 0 then
        begin
            tom := bentas[t].codigo;
            vent := vent + bentas[t].ventas;
            totalp := totalp + (bentas[t].precio * bentas[t].ventas);
            bentas[t].codigo := 0;
             for q := 1 to k - 1 do
             begin
                if bentas[q].codigo = tom then
                begin
                   vent := vent + bentas[q].ventas;
                   totalp := totalp + (bentas[q].precio * bentas[q].ventas);
                   bentas[q].codigo := 0;
                end;
             end;
              writeln('  ',tom,'        ',vent:0:2,'         ',totalp:0:2);
              totalv := totalv + totalp;
              vent := 0;
              totalp := 0;
              tom := 0;
           end;
           writeln;
           writeln('  Total Ventas Realizadas = ',totalv:0:2);
        end;
      end;
 
  procedure buscapresenta;
  var
    codig : word;
    kk : longint;
    mues : regbentas;
  begin
     writeln('**** Ver Ventas De Codigo ****');
     writeln;
     write('  Entre Codigo A Buscar : ');
     readln(codig);
     assign(f, archivo);
    {$I-} reset(f); {$I+}
    if ioresult = 0 then
    begin
       writeln(' Codigo      Unidades     Total Productos');
       for kk := 0 to filesize(f) - 1 do
       begin
          seek(f,kk);
          read(f,mues);
          if mues.codigo = codig then
 writeln('  ',mues.codigo,'         ',mues.ventas:0:2,
                                     '           ',mues.precio:0:2);
       end;
       writeln;
       writeln('    Punse Una Tecla');
       close(f);
    end
  else
     begin
        writeln('  El Archivo [ ',archivo,' ] No Esta Creado');
        writeln('  Pulse Una Tecla');
        readkey;
     end;
  end;
 
  procedure anulacion;
  begin
     assign(f, archivo);
    {$I-} reset(f); {$I+}
    if ioresult = 0 then
    begin
       close(f);
       erase(f);
    end;
  end;
 
  procedure menu;
  var
    fin : boolean;
    pul : char;
  begin
     fin := false;
   repeat
      clrscr;
      writeln('    ***** Menu General *****');
      writeln;
      writeln('    1 = Entrada De Datos');
      writeln('    2 = Busca Codigo y Presenta');
      writeln('    3 = Visualizar Resultados');
      writeln('    4 = Anula Archivo ventas.dat');
      writeln('    5 = Salir');
      writeln;
      writeln('   >>>>>> Elija Opcion <<<<<<<');
      repeat
          pul := readkey;
      until pul in[#49..#53];
  case pul of
 #49 : begin
       clrscr;
       entradatos;
       end;
 #50 : begin
       clrscr;
       buscapresenta;
       readkey;
       end;
 #51 : begin
       clrscr;
       presentadatos;
       writeln;
       writeln('>>>> Pulse Una Tecla <<<<');
       readkey;
       end;
 #52 : begin
          clrscr;
          anulacion;
          writeln('***** Archivo [ ',archivo,' ] Anulado Pulse Una Tecla *****');
          readkey;
       end;
 #53 : fin := true;
   end;
   until fin = true;
  end;
 
  begin
     clrscr;
     writeln('¨¨¨¨ Desea Crear El Archivo Para Ver Ejemplo [S/N] ????');
     repeat
     ini := upcase(readkey);
     until ini in['S','N'];
     if ini = 'S' then
     genera_archivo;
     menu;
  end.
 
{Fíjate que creo un archivo con tus datos como prueba si quieres y sino entra los a mano.}
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

Ayuda para realizar un programa en Pascal para registrar ventas de un producto

Publicado por Hector (8 intervenciones) el 02/05/2013 17:49:53
Muchas gracias ya comprendo mejor esta parte de áscal, no sabia que se podian hacer menus y submenus, gracias de antemano.
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 realizar un programa en Pascal para registrar ventas de un producto

Publicado por franco sanguedolce (32 intervenciones) el 03/05/2013 17:46:25
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
{A ver si.esto te da una mas clara}
Program ventas;
 
Uses crt;
 
Type
  productos = Record
    cod: byte;
    cv: byte;
    pr: real;
  End;
 
Const ubar = 'C:/ventas.dat';
 
Var
  prod: productos;
  arch: file Of productos;
  tec: char;
 
Procedure ingresoproducto;
 
Var tecla: char;
Begin
  assign(arch,ubar);
     {$I-}
  reset(arch);{$I+}
  If ioResult<>0 Then
    Begin
      rewrite(arch);
    End;
  Repeat
    Begin
      clrscr;
      write('Ingrese codigo: ');
      readln(prod.cod);
      write('Ingrese cantidad vendida: ');
      readln(prod.cv);
      write('Ingrese precio unitario: ');
      readln(prod.pr);
      seek(arch,filesize(arch));
      write(arch,prod);
      writeln;
      write('Ingresar otro Producto? [S/N]');
      tecla := readkey;
    End;
  Until (tecla='N') Or (tecla='n');
  close(arch);
End;
 
Procedure leeregistro;
Begin
  assign(arch,ubar);
  reset(arch);
  While Not eof(arch) Do
    Begin
      read(arch,prod);
      writeln('Codigo: ',prod.cod);
      writeln('Unidades Vendidas: ',prod.cv);
      writeln('Precio Unitario: ',prod.pr:0:2);
      writeln;
    End;
  close(arch);
  readkey;
End;
 
Procedure buscaproducto;
 
Var codigo,cantv: byte;
  precio,unitario: real;
Begin
  write('Ingrese Codigo a Buscar: ');
  readln(codigo);
  assign(arch,ubar);
  reset(arch);
  cantv := 0;
  While Not (eof(arch)) Do
  begin
      read(arch,prod);
      If (codigo=prod.cod) Then
      begin
        cantv := cantv+prod.cv;
      precio := prod.pr*cantv;
      unitario:=prod.pr;
      end;
      end;
  writeln;
  writeln('Codigo: ',codigo);
  writeln('Cantidad Vendidas: ',cantv);
  writeln('Precio Unitario: ',unitario:0:2);
  writeln('Precio Total de Ventas: ',precio:0:2);
  close(arch);
  readkey;
End;
 
Procedure borraregistro;
Begin
  assign(arch,ubar);
  rewrite(arch);
  close(arch);
  clrscr;
  writeln;
  write('Archivo [VENTAS] ha sido borrado Correctamente!');
  readkey;
End;
 
Procedure menu;
Begin
  clrscr;
  writeln('|----------Menu----------|');
  writeln;
  writeln;
  writeln('1: Ingreso Nueva Venta!.');
  writeln('2: Ver Lista Ventas!.');
  writeln('3: Ver Producto por Codigo!.');
  writeln('4: Borrar Archivo VENTAS!.');
  writeln;
  write('Ingrese N° de Opcion: ');
  tec := readkey;
  Case tec Of
    '1':
         Begin
           clrscr;
           ingresoproducto;
           menu;
         End;
    '2':
         Begin
           clrscr;
           leeregistro;
           menu;
         End;
    '3':
         Begin
           clrscr;
           buscaproducto;
           menu;
         End;
    '4':
         Begin
           clrscr;
           borraregistro;
           menu;
         End;
  End;
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