Question: Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the

Please use this template.

In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values.

#include #include #include

using namespace std;

//Fills vector with user input until user enters 0 (does not include 0 within vector). void fillVector(vector &v);

//Searches for val within vector. //If val found, returns index of first instance of val. //If val not found, returns UINT_MAX (constant provided by the climits library). unsigned search(const vector &v, int val);

//Removes from the vector the value at index, keeping all other values in the same relative order. void remove(vector &v, unsigned index);

//Displays all values within vector, each value separated by a space. void display(const vector &v);

int main() { vector v; int value; fillVector(v); cout << "Enter value to search for: "; cin >> value; //search for value unsigned pos = search(v, value); cout << "Found: "; //if val found, output position it was found and then remove it from vector //otherwise output "NOT FOUND" //UINT_MAX is a constant provided by the climits library (see http://www.cplusplus.com/reference/climits/ for more info) if (pos != UINT_MAX) { cout << pos << endl; remove(v, pos); } else { cout << "NOT FOUND" << endl; } cout << "Result: "; //output the vector's values. display(v); cout << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!