#include #include #include // Write all your code here (preferably) or in separate files (if you prefer) // You will need to figure out a suitable type to store in the stack // Replace YOUR_TYPE with that type in the main program // Remember to check for memory leaks before submitting! int main() { // Keep the current state at the top of a stack std::stack< YOUR_TYPE > state_stack; // A menu should be active when we enter the game state_stack.push(Menu{"The Game"}); // Adjust according to YOUR_TYPE // Keep runnig The Game until all states are completed while ( ! state_stack.empty() ) { // Fetch the current active state YOUR_TYPE active_state = state_stack.top(); // Let the active state instruct the user active_state->print(); std::string input{}; std::cin >> input; // Let the active state handle user input and store the return value YOUR_TYPE next{ active_state->handle(input) }; if (next == nullptr) { // If handle returns nullptr the active_state is completed and should cease it's existance, pop it state_stack.pop(); } else if (next != active_state) { // If handle returns a new state we should complete that before this one, push it to the stack state_stack.push(next); } else if (next == active_state) // Not needed, included for explicit clarity { // If handle returns pointer to its own state object, keep running that state, do nothing } } return 0; }