信号:
灯的信号(红绿);
起落杆的信号;
传感器的信号(外部输入);
状态机信号:
车辆进入
车辆出去
#include <iostream> using namespace std; enum State { in,out }; enum Lever{ lever_up, lever_down }; enum Light { red, green }; struct signal { bool car_in, car_out; Lever lever; Light light; }signal_in, signal_out; struct carstate { State state; }state; void light_change() { if (signal_in.lever == lever_down) { signal_out.light = red; } else if (signal_in.lever == lever_up) { signal_out.light = green; } } void lever_change() { if (signal_in.car_in == true) { signal_out.lever = lever_up; state.state = in; } else if (signal_in.car_in == false) { signal_out.lever = lever_down; } if (signal_out.car_out == true) { signal_out.lever = lever_down; state.state = out; } else if (signal_out.car_out == false) { } } int main() { while (1) { lever_change(); light_change(); } }