Projects Inventory

Simulation of Simple Traffic Light Gaming Project in C++

Explanation

  1. LightState Enum:
    • Purpose: Represents the possible states of the traffic light.
    • Advertisement
    • States: RED, YELLOW, GREEN.
  2. TrafficLight Class:
    • Attributes:
      • currentState: The current state of the traffic light.
    • Methods:
      • update(): Changes the traffic light to the next state in the sequence: RED -> GREEN -> YELLOW -> RED.
      • Advertisement
      • printStatus(): Prints the current state of the traffic light.
  3. Main Function:
    • Traffic Light Creation: Initializes a TrafficLight object.
    • Simulation Loop:
      • Print Status: Displays the current light state.
      • Wait: Pauses execution for a duration depending on the current light state.
      • Update State: Advances the traffic light to the next state.

Usage

Exit mobile version