// vendingmachine.hh written by Andreas Bauer #ifndef VENDING_HH #define VENDING_HH #include using namespace std; // Undef if you want no output on the console. See comments for STEPS // regarding a sensible test run of this automaton. #ifdef VERBOSE #define PRINTLN(msg) cout << msg << endl #else #define PRINTLN(msg) #endif // If machine works automatically, STEPS defines the number of // transitions of a single run. 10000 is enough to bomb the stack on // an ordinary Intel PC, optimized versions of GCC will remove the // indirect tail calls and, thus, work fine regardless of STEPS. #define STEPS 10000 class Vendingmachine; typedef void (Vendingmachine :: *fn_ptr) (void); class Vendingmachine { private: bool manual; fn_ptr action (void); // States void s_zero (void); void s_nickel (void); void s_dime (void); void s_15_cents (void); void s_20_cents (void); // Transitions void t_5_cents (void); void t_10_cents (void); public: Vendingmachine (void); void start (void); void automatic (void); }; #endif