forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRacer_Driver.cpp
More file actions
120 lines (88 loc) · 2.47 KB
/
Racer_Driver.cpp
File metadata and controls
120 lines (88 loc) · 2.47 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Racer Driver file
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>//for "exit()" on some systems
using namespace std;
#include "Racer.h"
void fillVector(vector<Racer>&);
void printVector(const vector<Racer>&);
void printVector2(const vector<Racer>&); //Need help to understand this.
int linearSearch(vector<Racer>& data, auto key);//function prototype for linear search.
int main()
{
string search_key, input;
int result;
vector<Racer> racerArray;
fillVector(racerArray);
// Implemented the linear function search from the algos lab.
// Comment out from here to "printVector2" to gain back the orginal
//implementation of this program.
//Added a linear search algorithm; which searches the vector once filled for matching
//Racer's names, and returns the index of the name.
cout<<endl<<"To end input type the #-character (followed by Enter)"<<endl<<endl;
cout<<"Enter a value to search for: ";
cin>>search_key;
while(search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(racerArray,search_key);
cout<<" '"<<search_key<<"' was ";
if (result == -1)
cout<<"not found";
else
cout<<"found at index "<<result;
cout<<endl<<endl<<"Enter a value to search for: ";
cin>>search_key;
}
//printVector2(racerArray);
system("pause");
return 0;
}
void fillVector(vector<Racer>& newRacerArray)
{
for (int x = 0; x < 4; x++)
{
int category;
string name;
cout << "Enter the Bike racer's name: ";
getline(cin, name);
cout << "\nEnter the Bike racer's Category Level:";
cin >> category;
cin.ignore();
Racer newRacer(name, category);
newRacerArray.push_back(newRacer);
cout << endl;
}
cout << endl;
}
void printVector(const vector<Racer>& newprintRacer)
{
unsigned int vectorSize = newprintRacer.size();
for (unsigned int i = 0; i < vectorSize; i++)
{
cout << "Rider's name: " << newprintRacer[i].getRacerName() << endl;
cout << "Rider's category: " << newprintRacer[i].getracerCategory() << endl;
cout << endl;
}
}
void printVector2(const vector<Racer>& newprintRacer)
{
unsigned int vectorSize = newprintRacer.size();
for (unsigned int i = 0; i < vectorSize; i++)
{
newprintRacer[i].displayInfo();
}
}
int linearSearch(vector<Racer>& data, auto key)
{
for (int i = 0; i < data.size(); i++)
{
if (data[i].getRacerName() == key)
{
return i;
}
}
return -1;
}