I created a Class "Car" with private attributes - make, model, year, speed_x, speed_y, fly_speed_z, x, y and z so that they can be accessed only by the member functions of the class.
Within the public access specifier, defined a constructor for easier initialization of variables and better handling of data. Also defined the methods here so that they are accessible everywhere.
Methods -
- accelerate_x - Updates speed_x according to the given increment.
- accelerate_y - Updates speed_y according to the given increment.
- rocket - Updates fly_speed_z according to the given increment.
- brake_x - Updates speed_x after brake is applied.
- brake_y - Updates speed_y after brake is applied.
- brake_z - Updates fly_speed_z after brake is applied.
- move - Updates position of the car.
Logic - Found the time after which collision will take place, if possible else. Updated coordinates of both cars accordingly. If the coordinates of the cars coincide, then they collide.