Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started