#include "menu.h" void Menu::print() { list::const_iterator ptr = commands.begin(); ++ptr; cout << "The valid commands are (or any valid prefix): " << endl; while ( ptr != commands.end() ) { cout << '\t' << (*ptr)->getName(); ++ptr; } cout << endl; } Command * Menu::get_command(const string & user_data) { list::const_iterator ptr = commands.begin(); list temp_list; while ( ++ptr != commands.end() ) { string temp = (*ptr)->getName(); if (user_data == temp.substr(0, user_data.size())) temp_list.push_back(*ptr); } if (temp_list.size() == 1) { list::const_iterator ptr = temp_list.begin(); return *ptr; } ptr = commands.begin(); return (*ptr); } void Menu::init() { commands.push_back(new InvalidCommand("invalid")); commands.push_back(new GiveHelpCommand("help")); commands.push_back(new ExitCommand("exit")); commands.push_back(new GetNumberCommand("get")); commands.push_back(new PutNumbersCommand("print")); commands.push_back(new SortNumbersCommand("sort")); commands.push_back(new SaveNumbersCommand("save")); commands.push_back(new LoadNumbersCommand("load")); commands.push_back(new UndoCommand("undo")); }