Advertisement
Guest User

venta por localidad

a guest
Oct 13th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.17 KB | None | 0 0
  1. program Yerba;
  2.  
  3. uses crt;
  4. const
  5.     maxLoc = 6;
  6. type
  7.    
  8.     RLocalidad = record
  9.         codLoc : 1..6; {codigo de localidad}
  10.         totVenta : real; {total de venta}
  11.     end;
  12.     vector = array[1..MaxLoc] of real; {tipo de vector para cargar el total
  13.                                     de ventas de cada localidad}
  14.     ALocalidades = file of RLocalidad; {tipo de archivo de registro de
  15.                                         localidad}
  16. var
  17.     archivo : ALocalidades;fin : boolean;
  18.     registro : Rlocalidad;ventas:vector;
  19. var promVentas : real;desde,codLocAnt : integer; nombre:string[15];
  20.  
  21. function leer (var arch:ALocalidades;var reg:RLocalidad):boolean;
  22. begin
  23.     if eof(arch) then
  24.         leer := true
  25.     else
  26.     begin
  27.         leer:= false;
  28.         read(arch,reg);
  29.     end;
  30. end;
  31.  
  32. procedure inicializar(var v:vector);
  33. var
  34.     i : integer;
  35. begin
  36.     for i := 1 to maxLoc do
  37.         v[i] := 0;
  38. end;
  39.  
  40. procedure proceso(var reg:RLocalidad;var v:vector;var pos:integer);
  41. begin
  42.     v[pos] := reg.totVenta;
  43.     pos := pos + 1;
  44. end;
  45.  
  46. function locMayorV(v:vector):string;
  47. //detecta la localidad con mayor venta
  48. var
  49.     mayor : real;pos,i:byte;
  50. begin
  51.     mayor := 0;pos :=0;
  52.     for i := 1 to maxLoc do
  53.     begin
  54.         if v[i] > mayor then
  55.         begin
  56.             mayor := v[i];
  57.             pos := i;
  58.         end;
  59.     end;
  60.     case pos of
  61.         1 : locMayorV := 'Apostoles';
  62.         2 : locMayorV := 'Obera';
  63.         3 : locMayorV := 'Jardin America';
  64.         4 : locMayorV := 'San Pedro';
  65.         5 : locMayorV := 'San Vicente';
  66.         6 : locMayorV := 'El Soberbio';
  67.     end;   
  68. end;
  69.  
  70. function promedioV(v:vector):real;
  71. // devuelve el promedio de ventas total
  72. var
  73.     i : integer;tot:real;
  74. begin
  75.     tot := 0;
  76.     for i := 1 to maxLoc do
  77.         tot := tot + v[i];
  78.     promedioV := tot / 6;
  79. end;
  80.  
  81. BEGIN
  82.     assign(archivo,'VENTAS.dat');
  83.     reset(archivo);
  84.     inicializar(ventas);
  85.     fin := leer(archivo,registro);
  86.     while not fin do
  87.     begin
  88.         codLocAnt := registro.codLoc;
  89.         while (not fin) and (codLocAnt = registro.codLoc) do
  90.         begin
  91.             proceso(registro,ventas,desde);
  92.             fin := leer(archivo,registro);
  93.         end;
  94.     end;
  95.     nombre := locMayorV(ventas);
  96.     promVentas := promedioV(ventas);
  97.     writeln('Localidad con mayor ventas: ',nombre);
  98.     writeln('Promedio de ventas de la provincia: ',promVentas);
  99.     close(archivo);
  100.     writeln('Presione una tecla para salir');
  101.     readkey;
  102. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement