Server IP : 172.16.15.8 / Your IP : 3.141.29.202 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/bnhans/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// // CS 212 Assignment 5 // Due: 28 March 2011 // // File: assignment5.cpp // Author: Brittani Hans // Instructor: Dr. Wang // // Compiling: g++ assignment5.cpp // Executing: ./a.out // // Goal: To use vector class to ask the user to input info // and it will do what is on the list operations. #include <iostream> #include <vector> using namespace std; void Menu() { cout << " List Operations\n"; cout << "=================================================\n"; cout << "I Insert an Item.\n"; cout << "F Find out if the item is in the list.\n"; cout << "R Remove the last item in the list.\n"; cout << "V Reverse the order of the list.\n"; cout << "S Sort the list to ascending order.\n"; cout << "D Sort the list to descending order.\n"; cout << "P Print the string list.\n"; cout << "Q Quit the operation.\n"; cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; cout << "Your option is: "; } int main() { char op; string item; vector <string> v; Menu(); cin >> op; while(toupper(op) != 'Q') { if(toupper(op) == 'I') { cout << "Input item here: "; cin >> item; v.push_back(item); cout << "The list is currently: "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } else if(toupper(op) == 'F') { bool found = false; string item; cout << "Input an item you are looking for: "; cin >> item; for(int i=0; i<v.size() && !found; i++) { if ( item == v[i] ) found = true; } if ( found ) cout << "\n" << item << " is in the list.\n\n"; else cout << "\n" << item << " is not in the list.\n\n"; } else if(toupper(op) == 'V') { reverse(v.begin(), v.end() ); cout << "The list is - "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } else if(toupper(op) == 'S') { sort(v.begin(), v.end() ); cout << "The list is - "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } else if(toupper(op) == 'R') { v.pop_back(); cout << "The list is: "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } else if(toupper(op) == 'D') { sort(v.begin(), v.end(), greater<string>() ); cout << "The list is: "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } else if(toupper(op) == 'P') { cout << "The list is: "; for(int i=0; i<v.size(); i++) cout << v[i] << " "; cout << "\n\n"; } Menu(); cin >> op; } return 0; }