01: #include <iostream>
02: #include <vector>
03: 
04: using namespace std;
05: 
06: #include "ccc_empl.cpp"
07: 
08: /** 
09:    Finds an employee in a sorted vector.
10:    @param v the sorted vector with the employees to search
11:    @param from the start of the range to search
12:    @param to the end of the range to search
13:    @param n the employee name to search for
14:    @return the index of the first match, or -1 if not found
15: */
16: int binary_search(vector<Employee> v, int from, int to, string n)
17: {  
18:    if (from > to)
19:       return -1;
20:    int mid = (from + to) / 2;
21:    if (v[mid].get_name() == n)
22:       return mid;
23:    else if (v[mid].get_name() < n)
24:       return binary_search(v, mid + 1, to, n);
25:    else
26:       return binary_search(v, from, mid - 1, n);
27: }
28: 
29: int main()
30: {  
31:    vector<Employee> staff(5);
32:    staff[0] = Employee("Cracker, Carl", 48000.0);
33:    staff[1] = Employee("Hacker, Harry", 35000.0);
34:    staff[2] = Employee("Lam, Larry", 78000.0);
35:    staff[3] = Employee("Reindeer, Rudolf", 63000.0);
36:    staff[4] = Employee("Sandman, Susan", 51500.0);
37: 
38:    cout << "Enter name of employee to search for: ";
39:    string name;
40:    getline(cin, name);
41: 
42:    int i = binary_search(staff, 0, staff.size() - 1, name);
43: 
44:    if (i >= 0)
45:       cout << staff[i].get_name() << " "
46:          << staff[i].get_salary() << "\n";
47:    else
48:       cout << "Not found.\n";
49: 
50:    return 0;
51: }
52: