forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
57 lines (45 loc) · 1.05 KB
/
Main.cpp
File metadata and controls
57 lines (45 loc) · 1.05 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Account.cpp"
#include <iostream>
#include <vector>
using namespace std;
int linearSearch(auto data, auto key)
{
for (int i=0; i<data.size(); i++)
{
if (data[i].getNum()==key)
{
return i;
}
} //end for
return -1; //not found
}
int main( )
{
int result = 0;
int search_key = 0;
Account myAccount;
vector <Account> acctList;
myAccount.setName ("Bob");
myAccount.setNum (12);
acctList.push_back (myAccount);
myAccount.setName ("Tim");
myAccount.setNum (10);
acctList.push_back(myAccount);
myAccount.setName ("Rich");
myAccount.setNum (35);
acctList.push_back (myAccount);
myAccount.setName ("Chris");
myAccount.setNum (66);
acctList.push_back (myAccount);
/*for (int i = 0; i < acctList.size ( ); i++)
{
cout << acctList[i].getName()<< "" << acctList[i].getNum ();
}*/
cout << "Enter search key: ";
cin >> search_key;
result = linearSearch(acctList, search_key);
if (result == -1)
cout<<"not found";
else
cout<<"found at index "<<result<<endl<<endl;
}