The Dutch government wants to track where every car in the Netherlands is by equipping each car with a short-range transmitter. When a car passes detectors that have been installed in the road surface, the transmitter sends the license plate number (kenteken) to these detectors. All detectors are connected to a central computer, that stores these license plate numbers in a file, as well as the id of the detector that received the license plate number, and the time at which the license plate number was received.

This system can be used to detect which cars are going over the speed limit. To do so, a file with the following structure is used:

  • The first line contains the maximum speed (in km/h) for the road that the detectors are placed on.
  • All other lines start with the number of the detector that was passed (1 or 2), followed by the time on which the car passed the detector, and then followed by the license plate number of that car.

Example input (an actual input file can be found on Canvas):

50
1 09:00:00 OZ-15-ZU
2 09:00:04 WS-LP-74
1 09:00:07 97-YC-51
1 09:00:10 NV-71-PU
2 09:00:21 OZ-15-ZU
[...]
2 09:04:58 CN-70-OT

You can assume that the detectors are on a one-way road, and the distance between the two detectors is 200 meters. Write a program that does the following:

  • Print a list of the license plate numbers of all cars that went over the speed limit, as well as the average speed of each of those cars.
  • Print the license plate numbers of all cars that are still between the two sensors.

Note: It is possible that there are cars in between the two sensors at the moment that the mea- surement starts. These cars will only pass the second detector during the measurement. You don't have to check if these cars go over the speed limit.

Example output:

The following cars went over the speed limit:
GH-23-NN - 68 km/h
NV-71-PU - 56 km/h
CN-70-OT - 70 km/h
18-IP-VU - 59 km/h

The following cars are currently between the two sensors:
45-HH-97
OF-UZ-13

Tip: In order to calculate the average speed of a car, you need to be able to convert a "time string" (e.g. 09:00:00) to a number of seconds (00:00:00 would be 0 seconds, 03:02:01 would be 10921 seconds, etc.). By converting two time strings to a number of seconds, you can determine the difference in seconds between the two times. The difference in time and the difference in meters can be used to determine the speed in m/s, which can then be used to determine the speed in km/h (1 m/s = 3.6 km/h).

Bonus

For extra points for this assignment, print the cars that went over the speed limit in order from fastest to slowest.

Example output:

The following cars went over the speed limit:
CN-70-OT - 70 km/h
GH-23-NN - 68 km/h
18-IP-VU - 59 km/h
NV-71-PU - 56 km/h

The following cars are currently between the two sensors:
45-HH-97
OF-UZ-13
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.