Built from scratch · C++ Simulation

AirportSim

A terminal airport simulator written in C++17 from scratch, with hand-written queues instead of the STL ones. Below are real runs of the program played back: arrivals hold until a runway frees up, planes low on fuel jump the line, and departures queue on the taxiway and take off while the sun sets. Hover a plane to see its flight.

C++ C++17 Data Structures Priority queue Simulation OOP
00:00

Pick an airport

Right now

0
Landed
0
Took off
0
Holding
0
Waiting to leave
0
Emergency landings
0
Ran out of fuel
  • Tail colour = airline
  • Low on fuel
  • Emergency, under 20% fuel
  • Shadow distance = altitude

Latest events

    What the program printed this minute

    The animation is drawn from this screen. The C++ simulator was compiled and run with each airport's settings, and every minute's screen was recorded.

    ⚡
    Priority queue
    Sorted linked list for arrivals. Emergency planes (<20% fuel) jump to the front. Insertion O(n), dequeue O(1).
    →
    FIFO queue
    Standard linked list for departures. First in, first out. Enqueue and dequeue both O(1). No STL container used.
    🛬
    Fuel emergencies
    Arriving planes burn 1% fuel per minute while waiting. Below 20% triggers EMERGENCY priority. At 0% the plane crashes.
    🛫
    Runway state machine
    Each runway cycles: AVAILABLE → LANDING/TAKEOFF → AVAILABLE. Arrivals always take priority over departures.

    What I learned

    Owning memory by hand.

    Every plane in a queue is a node I allocate and delete myself. That means a destructor that clears the list, and no copying, because two queues pointing at the same nodes would delete them twice.

    A simple structure can be the right one.

    The landing queue is a sorted linked list, so adding a plane is O(n). With a few dozen planes that is fine, and taking the next one is O(1). A heap would be faster on paper and harder to read.

    Simulations need clear rules for each step.

    Every minute has to happen in the same order: burn fuel, free runways, then give them to waiting planes. If the order is loose, planes end up in the same place at the same time.