Server IP : 172.16.15.8 / Your IP : 3.142.255.23 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/jljustice/cs212/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Play with integer list and operations // - insert, output, quit..... // #include <iostream> // for endl, setw, fixed,..... #include <vector> // for vector class template #include <algorithm> // for sort(..) for vector objects using namespace std; // for cin/cout void menu(); int main() { vector<string> myList; string temp; char ch; menu(); cin >> ch; while(tolower(ch) != 'q') { cout << "You choose - " << ch; if( tolower(ch) == 'i') { cout << "\n\nInsert a word: "; cin >> temp; myList.push_back(temp); cout << "\n" << temp << " is inserted to the list.\n"; } else if(tolower(ch) == 'p') { cout << "\n The List is: "; for( int i=0; i < myList.size(); i++) cout << myList[i] << " "; cout << endl; } else if(tolower(ch) == 's') { sort(myList.begin(), myList.end() ); cout << "\n The list is sorted.\n"; } else if(tolower(ch) == 'd') { sort(myList.begin(), myList.end(), greater<string>() ); cout << "\nThe list is sorted to descending order.\n"; } menu(); cin >> ch; } cout << "\n\nYou are finished.\n\n"; return 0; } void menu() { cout << "\n\n List Game\n"; cout <<"------------------------------------\n"; cout << "I Insert a word.\n"; cout << "P Print the list.\n"; cout << "S Sort to ascending list.\n"; cout << "D Sort to descending order.\n"; cout << "Q Quit.\n"; cout << "===================================="; cout << endl; cout << "Your Choice: "; }