1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
vector<string> emps =
{
"Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson, Jill",
"Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
"James, Jean", "Weaver, Jim", "Pore, Bob",
"Rutherford, Greg", "Javens, Renee",
"Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth"
};
string employeeName;
cout << " Enter name to be searched" << endl;
getline(cin, employeeName);
sort(emps.begin(), emps.end());
bool found = binary_search(emps.begin(), emps.end(), employeeName);
if (found)
cout << employeeName << "Found it" << endl;
else
cout << "Not found" << '\n';
cout << "\nElement names list is: " << endl;
for (size_t index = 0; index < emps.size(); index++)
cout << index + 1 << '\t' << right << setw(10) << emps[index] << endl;
}
|