PROGRAM InfraccionesTraficoRadarTramo ; USES SysUtils, Crt ; CONST iCATEGORIASVEH = 4 ; TYPE tsMatricula = String[10] ; tsNombre = String[40] ; trgInstante = trgDatosVehiculo tfbrgDatosRadar RECORD ihoras, iminutos, isegundos: Integer ; END ; = = taiArrayEstadisticas trgInfractor PROCEDURE CrearArrayEstadisticas ( sNomFich: tsNombre ; VAR aiComputoVehiculos: taiArrayEstadisticas ); VAR fbrgDatosVehiculos : tfbrgDatosRadar ; rgVehiculo : trgDatosVehiculo ; i : Integer ; BEGIN { inicializar array a cero } FOR i := 1 to iCATEGORIASVEH DO aiComputoVehiculos[i] := 0 ; = tfbrgInfracciones = Assign (fbrgDatosVehiculos, sNomFich) ; Reset (fbrgDatosVehiculos) ; WHILE NOT EOF(fbrgDatosVehiculos) DO BEGIN Read (fbrgDatosVehiculos, rgVehiculo) ; RECORD sMatricula : tsMatricula ; cCategoriaV : Char ; rgInstante : trgInstante ; rVelocidad : Real ; END ; FILE OF trgDatosVehiculo ; = ARRAY[1..iCATEGORIASVEH] OF Integer ; RECORD sMatricula : tsMatricula ; rgInstante : trgInstante ; rVelocidadMedia : Real ; END ; FILE OF trgInfractor ; ; ; ; ; { mostrar estadisticas } cCategoria := 'A' ; FOR i := 1 to iCATEGORIASVEH DO BEGIN Writeln(' - NºVehículos categoría ',cCategoria, ': ', aiEstadisticas[i]) ; cCategoria := CHR( ORD(cCategoria)+1 ) ; END ; END ; FUNCTION fncMenu : Char ; VAR cOpcion : Char ; BEGIN Clrscr ; Writeln(' PROGRAMA DGT CONTROL VELOCIDAD EN TRAMO') ; Writeln(' 1- Estadísticas') ; Writeln(' 2- Cálculo infracciones') ; Writeln(' 3- Mostrar infracciones') ; Writeln(' 0- Salir del programa') ; Writeln(' *************************************') ; REPEAT Write(' Pulse una opcion: ') ; Readln (cOpcion) ; UNTIL ('0' <= cOpcion) AND (cOpcion <= '3') ; FUNCTION fnrPasarASegundos (CONST rgDatoInstante:trgInstante): Real ; VAR rDatoTiempo : Real ; BEGIN WITH rgDatoInstante DO rDatoTiempo := iHoras * 3600 + iMinutos * 60 + iSegundos ; fnrPasarASegundos := rDatoTiempo ; END ; fncMenu := cOpcion ; END ; INFORMATICA aiComputoVehiculos[1]+1 aiComputoVehiculos[2]+1 aiComputoVehiculos[3]+1 aiComputoVehiculos[4]+1 PROCEDURE Estadisticas (sfich: tsNombre) ; VAR aiEstadisticas : taiArrayEstadisticas ; i : Integer ; cCategoria : Char ; BEGIN Writeln(' Estadísticas de paso de vehículos') ; Writeln(' *********************************') ; CrearArrayEstadisticas (sfich, aiEstadisticas) ; VAR cOpcion, cEspera : Char ; rLongitudTramo, rLimiteVelocidad : Real ; sNombreFicheroRadarA, sNombreFicheroRadarB, sNombreFicheroInfracciones : tsNombre ; JULIO 2011 CASE rgVehiculo.cCategoriaV OF 'A': aiComputoVehiculos[1]:= 'B': aiComputoVehiculos[2]:= 'C': aiComputoVehiculos[3]:= 'D': aiComputoVehiculos[4]:= END ; END ; { fin bucle while } Close (fbrgDatosVehiculos) ; END ; ETSI BILBAO JULIO 2011 INFORMATICA ETSI BILBAO FUNCTION fnrCalculoVelocidadMedia (CONST rgInstante1,rgInstante2: trgInstante ; rKmTramo: Real): Real ; VAR rVelMediaKmh, rTiempoSegundos : Real ; BEGIN rTiempoSegundos := fnrPasarASegundos(rgInstante2) – fnrPasarASegundos(rgInstante1) ; rVelMediaKmh := rKmTramo * 3600/rTiempoSegundos ; fnrCalculoVelocidadMedia := rVelMediaKmh ; END ; PROCEDURE BusquedaInstanteSalidaTramo ( sMatBuscada: CONST rgInstanteEntrada: sNomFich: VAR rgInstanteSalida: VAR boCodigoError: tsMatricula ; trgInstante ; tsNombre ; trgInstante ; Boolean) ; sNombreFichInfracciones := sNomFich1 sNombreFichInfracciones [1] := 'I' ; ; Assign (fbrgInfracciones, sNombreFichInfracciones) ; Rewrite (fbrgInfracciones) ; { crear fichero } VAR fbrgDatosVehiculos : tfbrgDatosRadar ; rgVehiculo : trgDatosVehiculo ; boEncontrado : boolean ; BEGIN Assign (fbrgDatosVehiculos, sNomFich) ; Reset (fbrgDatosVehiculos) ; WHILE NOT EOF(fbrgDatosUno) DO BEGIN Read (fbrgDatosUno, rgVehiculoPorRadarUno) ; BusquedaInstanteSalidaTramo(rgVehiculoPorRadarUno.sMatricula, rgVehiculoPorRadarUno.rgInstante, sNomFich2, rgInstantePorRadarDos, boError) ; boEncontrado := FALSE ; WHILE NOT EOF(fbrgDatosVehiculos) AND NOT boEncontrado DO BEGIN Read (fbrgDatosVehiculos, rgVehiculo) ; IF ( rgVehiculo.sMatricula = sMatBuscada AND ( fnrPasarASegundos(rgVehiculo.rgInstante) > fnrPasarASegundos(rgInstanteEntrada) THEN boEncontrado:=TRUE ; END ; PROCEDURE CreacionFicheroInfracciones (rLimiteVelocidad, rLongitudTramo: Real ; sNomFich1, sNomFich2 : tsNombre); VAR fbrgDatosUno : tfbrgDatosRadar ; fbrgInfracciones : tfbrgInfracciones ; rgVehiculoPorRadarUno : trgDatosVehiculo ; rgInstantePorRadarDos : trgInstante ; boError : boolean ; rVelocidadMediaCalc : Real ; rgVehiculoInfractor : trgInfractor ; sNombreFichInfracciones : tsNombre ; BEGIN Assign (fbrgDatosUno, sNomFich1) ; Reset (fbrgDatosUno) ; ) ) IF boEncontrado THEN BEGIN boCodigoError := FALSE ; rgInstanteSalida := rgVehiculo.rgInstante ; END rVelocidadMediaCalc := fnrCalculoVelocidadMedia (rgVehiculoPorRadarUno.rgInstante, rgInstantePorRadarDos, rLongitudTramo) ; IF (NOT boError) AND(rVelocidadMediaCalc > rLimiteVelocidad) THEN BEGIN rgVehiculoInfractor.sMatricula := rgVehiculoPorRadarUno.sMatricula ; rgVehiculoInfractor.rgInstante := rgVehiculoPorRadarUno.rgInstante ; ELSE rgVehiculoInfractor.rVelocidadMedia:=rVelocidadMediaCalc ; boCodigoError := TRUE ; Write(fbrgInfracciones,rgVehiculoInfractor) ; END ; Close (fbrgDatosVehiculos) ; END ; END ; Close (fbrgDatosUno) ; Close (fbrgInfracciones) ; END ; JULIO 2011 INFORMATICA ETSI BILBAO JULIO 2011 INFORMATICA ETSI BILBAO PROCEDURE MostrarInfracciones (sNombreFicheroInfracciones: tsNombre) ; VAR fbrgFichInfracciones : tfbrgInfracciones ; rgDato : trgInfractor ; BEGIN IF FileExists (sNombreFicheroInfracciones) THEN BEGIN Assign (fbrgFichInfracciones, sNombreFicheroInfracciones) ; Reset (fbrgFichInfracciones) ; Writeln(' Listado vehículos infractores ') ; Writeln(' ***************************** ') ; WHILE NOT EOF(fbrgFichInfracciones) DO BEGIN Read (fbrgFichInfracciones, rgDato) ; WITH rgDato, rgInstante DO Writeln (' - Matricula: ', sMatricula, ' - Instante: ', iHoras, ':', iMinutos, ':', iSegundos, ' - VelocidadMedia: ',rVelocidadMedia:3:0) ; END ; Close(fbrgFichInfracciones) ; END ELSE Writeln ('El fichero de infracciones no existe') ; END ; BEGIN {**************** PROGRAMA PRINCIPAL ***********************} Writeln(' Gestión de infracciones en tramo controlado') ; Writeln(' *******************************************') ; Writeln ; Writeln(' Introduzca los siguientes datos: ') ; Write (' - Distancia entre radares (Km): ') ; Readln (rLongitudTramo) ; Write (' - Limite de velocidad (Km/h): ') ; Readln (rLimiteVelocidad) ; Write (' - Nombre fichero radar portico A: ') ; Readln (sNombreFicheroRadarA) ; Write (' - Nombre fichero radar portico B: ') ; Readln (sNombreFicheroRadarB) ; REPEAT cOpcion := fncMenu ; CASE cOpcion OF '1': Estadisticas(sNombreFicheroRadarA) ; '2': CreacionFicheroInfracciones (rLimiteVelocidad, rLongitudTramo, sNombreFicheroRadarA, sNombreFicheroRadarB) ; '3': BEGIN Write(' Introduzca nombre fichero infracciones: ') ; Readln(sNombreFicheroInfracciones) ; MostrarInfracciones(sNombreFicheroInfracciones) ; END ; '0': BEGIN Writeln ('Saliendo programa, pulse una tecla') ; cEspera := Readkey ; END ; END ; { fin case } UNTIL (cOpcion='0') ; END. JULIO 2011 INFORMATICA ETSI BILBAO