forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
92 lines (70 loc) · 1.68 KB
/
client.cpp
File metadata and controls
92 lines (70 loc) · 1.68 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
#include <iostream>
#include <vector>
#include "Books.h"
#include <string>
using namespace std;
int linearSearch(auto data, auto key) //prototype
{
for (int i=0; i < data.size(); i++)
{
if (data[i].getbName() == key)
{
return i;
}
} // end for
return -1;
}
int main()
{
vector <books> Books (4);
string search_key;
string bName;
double price;
int result;
books myObj;
for (int i=0; i<4; i++)
{
cout << "Enter the Book Title:" << endl;
cin >> bName;
//cout << "Enter the Price of the Book:" << endl;
//cin >> price;
while(bName != "#") //read an unknown number of inputs from keyboard
{
myObj.setbName(bName);
Books.push_back(myObj);
cin>>bName;
}
cout<<endl<<"["<<Books.size()<<" values read from input source]"<<endl<<endl;
if(Books.size() == 0)//no input
{
cout<<endl<<"No input received, quiting..."<<endl<<endl;
exit(1);//nothing to do but quit program
}
// INSERT SERACH KEY
cout<<"Enter a value to search for: ";
cin>>search_key;
//COMPARE SEARCH KEY W/ VECTORS
while (search_key != "#") // # of searches
{
result = linearSearch (Books,search_key); //vector books -> input bName
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;
// cout << "Price:" << endl;
//cin >> price;
//Books[i].setprice (price);
}
}
cout << "Book Information: " << endl;
for (int i=0; i<4; i++)
{
bName= Books[i].getbName();
price= Books[i].getprice();
cout << bName << " " << price << endl;
}
cin >> bName;
}