C++ code for state machine

前端 未结 6 870
暖寄归人
暖寄归人 2020-12-04 05:49

This was an interview question to be coded in C++:

Write code for a vending machine: Start with a simple one where it just vends one type of item. So

6条回答
  •  执念已碎
    2020-12-04 06:03

    I don't know whether that would have gotten you through the interview, but I'd personally refrain from coding any state machine by hand, especially if it's in a professional setting. State machines are a well researched problem, and there exist well tested open source tools which often produce superior code to what you will produce yourself by hand, and they also help you with diagnosing problems with your state machine by eg. being able to generate state diagrams automatically.

    My goto tools for this kind of problem are:

    • Ragel
    • SMC

提交回复
热议问题