Question: In C++ Change the attached code to display a menu: Enter one of the following F find a value R randomly shuffle the vector S
In C++
Change the attached code to display a menu: Enter one of the following F find a value R randomly shuffle the vector S sort the vector Q quit
If the user chooses F, confirm if the value is in the vector or not If the user chooses R, shuffle the vector and then display it. If the user chooses S, sort the vector and then display it. Put the above menu into a while loop which runs until the user enters Q or q to quit.You can handle the actions using an if else construct or a switch statement (the latter is preferred
#include#include #include using namespace std; void displayVector(vector myStringVector); int main() { vector studentVector; vector ::iterator myStringIterator; string proceed = "n"; string studentName; do { cout << "Enter student name: "; getline(cin, studentName); studentVector.push_back(studentName); cout << "Enter another student (Y/N): "; getline(cin, proceed); cout << endl; } while (proceed == "Y" || proceed == "y"); int studentNameIndex; //print the vector using iterators before removing the element displayVector(studentVector); //code to remove cout << "Enter the number to remove: "; cin >> studentNameIndex; cin.ignore(); studentVector.erase(studentVector.begin() + studentNameIndex - 1); //display the vector after removing the element displayVector(studentVector); //YOUR CODE BEGINS HERE system("pause"); return 0; } inline void displayVector(vector _myStringVector) { int i = 1; vector ::const_iterator _myStringIterator; for (_myStringIterator = _myStringVector.begin(); _myStringIterator != _myStringVector.end(); _myStringIterator++) { cout << i << ": " << *_myStringIterator << endl; i++; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
