forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
63 lines (45 loc) · 1.04 KB
/
Source.cpp
File metadata and controls
63 lines (45 loc) · 1.04 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
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <vector>
#include "Phone.h"
using namespace std;
int linearSearch(auto myPhone, auto key);
int main(){
string type;
string search_key;
double cost;
int answer;
vector <phone> myPhone;
cout<<"Enter a brand of phone" ;
cin>>type;
myPhone.push_back(type);
while (type != "#"){
myPhone.push_back(type);
cin>>type;
}
cout<< "Number of types entered ="<<myPhone.size()<<endl;
cout<<" Enter search key:";
cin>>search_key;
while(search_key != "#")
{
answer = linearSearch(myPhone,search_key);
cout<<" '"<<search_key<<"' was ";
if (answer == -1)
cout<<"not found";
else
cout<<"found at index "<<answer;
cout<<endl<<endl<<"Enter a value to search for: ";
cin>>search_key;
}
/*
cout<<"My vector contains:"<<myPhone.size();
*/
}
int linearSearch(auto myPhone, auto key){
for (int i=0; i<myPhone.size(); i++){
if (myPhone[i].getPhoneType() == key){
return i;
}
}
return -1;
}