Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Yerba;
- uses crt;
- const
- maxLoc = 6;
- type
- RLocalidad = record
- codLoc : 1..6; {codigo de localidad}
- totVenta : real; {total de venta}
- end;
- vector = array[1..MaxLoc] of real; {tipo de vector para cargar el total
- de ventas de cada localidad}
- ALocalidades = file of RLocalidad; {tipo de archivo de registro de
- localidad}
- var
- archivo : ALocalidades;fin : boolean;
- registro : Rlocalidad;ventas:vector;
- var promVentas : real;desde,codLocAnt : integer; nombre:string[15];
- function leer (var arch:ALocalidades;var reg:RLocalidad):boolean;
- begin
- if eof(arch) then
- leer := true
- else
- begin
- leer:= false;
- read(arch,reg);
- end;
- end;
- procedure inicializar(var v:vector);
- var
- i : integer;
- begin
- for i := 1 to maxLoc do
- v[i] := 0;
- end;
- procedure proceso(var reg:RLocalidad;var v:vector;var pos:integer);
- begin
- v[pos] := reg.totVenta;
- pos := pos + 1;
- end;
- function locMayorV(v:vector):string;
- //detecta la localidad con mayor venta
- var
- mayor : real;pos,i:byte;
- begin
- mayor := 0;pos :=0;
- for i := 1 to maxLoc do
- begin
- if v[i] > mayor then
- begin
- mayor := v[i];
- pos := i;
- end;
- end;
- case pos of
- 1 : locMayorV := 'Apostoles';
- 2 : locMayorV := 'Obera';
- 3 : locMayorV := 'Jardin America';
- 4 : locMayorV := 'San Pedro';
- 5 : locMayorV := 'San Vicente';
- 6 : locMayorV := 'El Soberbio';
- end;
- end;
- function promedioV(v:vector):real;
- // devuelve el promedio de ventas total
- var
- i : integer;tot:real;
- begin
- tot := 0;
- for i := 1 to maxLoc do
- tot := tot + v[i];
- promedioV := tot / 6;
- end;
- BEGIN
- assign(archivo,'VENTAS.dat');
- reset(archivo);
- inicializar(ventas);
- fin := leer(archivo,registro);
- while not fin do
- begin
- codLocAnt := registro.codLoc;
- while (not fin) and (codLocAnt = registro.codLoc) do
- begin
- proceso(registro,ventas,desde);
- fin := leer(archivo,registro);
- end;
- end;
- nombre := locMayorV(ventas);
- promVentas := promedioV(ventas);
- writeln('Localidad con mayor ventas: ',nombre);
- writeln('Promedio de ventas de la provincia: ',promVentas);
- close(archivo);
- writeln('Presione una tecla para salir');
- readkey;
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement