This code simulates a GPS tracking system that "moves" through...
This code simulates a GPS tracking system that "moves" through a series of predefined GPS coordinates (locations like Manila, Tokyo, New York, etc.) and displays them one by one with a delay of 2 seconds between each display. Here's a breakdown:
-
Struct Definition (
GPS
): Astruct
is defined to represent a GPS coordinate with two fields:latitude
: Represents the latitude of the location.longitude
: Represents the longitude of the location.
-
showLocation
Function: A helper function that takes aGPS
object as input (passed by constant reference) and prints out the latitude and longitude values. -
Predefined GPS Path: An array of 5 predefined
GPS
coordinates is created, representing locations in Manila, Tokyo, New York, Paris, and London. -
Tracking Simulation:
- Using a loop, the program iterates through the GPS coordinates in the
path
array. - For each coordinate:
- The
showLocation
function is called to print its latitude and longitude. - The program pauses (simulates a delay) for 2 seconds using
this_thread::sleep_for(chrono::seconds(2))
.
- The
- Using a loop, the program iterates through the GPS coordinates in the
-
Output Messages:
- At the beginning, it prints
"Simulated GPS Tracking..."
to indicate the start of the simulation. - Once all coordinates are displayed, it prints
"Tracking finished!"
to indicate the end of the simulation.
- At the beginning, it prints
Example Output:
The output of the program will appear sequentially over time (with a 2-second delay between each location):
Simulated GPS Tracking...
Latitude: 14.5995, Longitude: 120.9842
Latitude: 35.6895, Longitude: 139.6917
Latitude: 40.7128, Longitude: -74.006
Latitude: 48.8566, Longitude: 2.3522
Latitude: 51.5074, Longitude: -0.1278
Tracking finished!
Purpose:
The code demonstrates the use of structures, functions, arrays, loops, and threading to simulate time-based operations, making it useful for educational purposes or basic GPS location simulation applications.