[4] Make the program that deletes the element in the vector. The full description of the question No.4. Complete the fol
Posted: Sun May 15, 2022 1:42 pm
[4] Make the program that deletes the element in the vector. The full description of the question No.4. Complete the following function “deleteone()” to delete one element in the vector. We have a vector with 20 elements. The elements in a vector can be duplicated. We are going to make the function "deleteone” that delete the element or elements that are the same value as the user input. In the function "deleteonel)”, first we need to take one user input, and then delete all items that are the same as the user input value.
#include <iostream> #include <cstdlib> #include <ctime> #include <vector> #include <algorithm> #include <iterator> using namespace std; void makevector(vector int> &, int); void printvector(vector<int>); void deleteone(vector<int> &); int main() { vector int> number; int size = 20; srand(time(0); makevector(number, size); printvector(number); deleteone(number); } void makevector(vector<int> &vec, int size) { for(int i=0; i<size; i++) vec.push_back(rand() % 10); } void printvector(vector<int> vec) { for(int v : vec) cout << v << "\t"; cout << endl; } void deleteone(vector int> &vec) { int usernum; cin >> usernum; // Your Code « deletecnt « !! times cout << usernum << "is deleted" \n": printvector(vec) }
#include <iostream> #include <cstdlib> #include <ctime> #include <vector> #include <algorithm> #include <iterator> using namespace std; void makevector(vector int> &, int); void printvector(vector<int>); void deleteone(vector<int> &); int main() { vector int> number; int size = 20; srand(time(0); makevector(number, size); printvector(number); deleteone(number); } void makevector(vector<int> &vec, int size) { for(int i=0; i<size; i++) vec.push_back(rand() % 10); } void printvector(vector<int> vec) { for(int v : vec) cout << v << "\t"; cout << endl; } void deleteone(vector int> &vec) { int usernum; cin >> usernum; // Your Code « deletecnt « !! times cout << usernum << "is deleted" \n": printvector(vec) }