Server IP : 172.16.15.8 / Your IP : 3.15.211.71 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 (0705) : /home/bsjackson/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// CS212 CS II Assignment 5 // Due: Monday Mar. 29, 2011 // // File Name: hw5.cpp // Author: Brittany Jackson // Instructor: Dr. Wang // // Compile: g++ hw5.cpp // Run: ./a.out // // Goal: Using the vestor class ONLY, write the program to prompt a // menu and ask the user to input #include <iostream> #include <vector> using namespace std; void menu() { cout << " String List Operations\n"; cout << "==============================\n"; cout << "I Insert an item.\n"; cout << "F Find item in list.\n"; cout << "R Remove the last item.\n"; cout << "V Reverse the order of the list.\n"; cout << "A Ascending order.\n"; cout << "D Descending order.\n"; cout << "P Print List.\n"; cout << "Q Quit.\n"; cout << "-------------------------------\n"; cout << "Your option is: "; } int main() { vector<string> v; char op; string item; menu(); cin >> op; while(toupper(op) != 'Q') { if (toupper(op) == 'I') { cout << "Input the item: "; cin >> item; v.push_back(item); cout << "The list is - "; for( int i=0; i< v.size(); i++) { cout << v[i] << " "; } } if(toupper(op) == 'P') { cout << "The list is: "; for( int i=0; i< v.size(); i++) { cout << v[i] << " "; } } else if(toupper(op) == 'R') { v.pop_back(); cout << "The list is: "; for( int i=0; i< v.size(); i++) { cout << v[i] << " "; } } else if(toupper(op) == 'V') { reverse(v.begin(), v.end() ); cout << "The list reversed is: "; for (int i= 0; i< v.size(); i++) cout << v[i] << " "; } else if(toupper(op) == 'A') { sort(v.begin(), v.end() ); cout << "The list ascending is: "; for (int i= 0; i< v.size(); i++) cout << v[i] << " "; } else if(toupper(op) == 'D') { sort(v.begin(), v.end(), greater<string>() ); cout << "The list descending is: "; for (int i= 0; i< v.size(); i++) cout << v[i] << " "; // for( int i=0; i< v.size(); i++) // { cout << v[i] << " "; // // } } else if(toupper(op) == 'F') { bool found = false; cout << "Input the item to be found - "; cin >> item; for ( int i=0; i<v.size(); i++) { if( item ==v[i] ) found = true; } if (found) cout << "\n\n" << item << " is in the list.\n\n"; else cout << "\n\n" << item << " is not in the list.\n\n"; } menu(); cin >> op; } return 0; }