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
100 lines (66 loc) · 1.96 KB
/
main.cpp
File metadata and controls
100 lines (66 loc) · 1.96 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <string>
#include <vector>
#include "Winners.h"
using namespace std;
void fillvector(vector<Winners>&);
void printvector(vector<Winners>&);
int linearSearch(vector<Winners> contestants, string key);//prototype
int main(){
int result;
string search_key, input;
vector<Winners> contestants;
fillvector(contestants);
printvector(contestants);
cout << "To end input type the #-character (followed by Enter)" << endl;
cout << "Enter a value to search for: " ;
cin >> search_key;
while (search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(contestants, search_key);
cout << " '" << search_key << "' was ";
if (result == -1){
cout << "not found";
}
else {
cout << "found at index " << result << endl;
}
cout << "Enter a value to search for: " << endl;
cin >> search_key;
}
cout << "Program \"search it\" is now finished." << endl;
cout << "Program \"search it\" is now finished." << endl;
//system("pause");
return 0;
}
void fillvector(vector<Winners>& newContestant){
Winners contestants;
string name;
string search_key, input;
int age;
for (int i = 0; i < 4; i++){
cout << "Enter the name of the contestant" << endl;
cin >> name;
contestants.setname(name);
cout << " Enter the age of the contestant" << endl;
cin >> age;
contestants.setage(age);
newContestant.push_back(contestants);
}
}
void printvector(vector<Winners>& newContestant){
for (unsigned int i = 0; i < 4; i++){
cout << " Contestant name :" << newContestant[i].getname() << endl;
cout << "Contestant age :" << newContestant[i].getage() << endl;
}
}
int linearSearch(vector<Winners> win, string key)
{
for(int i = 0; i < win.size(); i++)
{
if (win[i].getname() == key)//we found it
{
return i;//return its location
}
}//end for
return -1;}//element not found