#include #include #include "command.h" using std::fstream; void ExitCommand::execute(list & my_list) { // Nothing to do! } void InvalidCommand::execute(list & my_list) { cout << '\t' << "invalid command" << endl; } void LoadNumbersCommand::execute(list & my_list) { commandStack.push(my_list); my_list.erase(my_list.begin(), my_list.end()); fstream input; input.open("data", ios::in); int number; input >> number; while(!input.eof()) { my_list.push_back(number); input >> number; } input.close(); } void SaveNumbersCommand::execute(list & my_list) { fstream output; output.open("data", ios::out); list::const_iterator ptr = my_list.begin(); while(ptr != my_list.end()) { output << *ptr << endl; ++ptr; } output.close(); } void GiveHelpCommand::execute(list & my_list) { } void UndoCommand::execute(list & my_list) { if ( commandStack.empty() ) return; my_list = commandStack.top(); commandStack.pop(); } void GetNumberCommand::execute(list & my_list) { commandStack.push(my_list); srand( time(0) ); my_list.push_back(rand() % 100); } void PutNumbersCommand::execute(list & my_list) { list::const_iterator ptr = my_list.begin(); cout << "The list contains: " << endl; while ( ptr != my_list.end() ) { cout << *ptr << '\t'; ++ptr; } cout << endl; } void SortNumbersCommand::execute(list & my_list) { commandStack.push(my_list); my_list.sort(); }