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
68 lines (57 loc) · 1.29 KB
/
client.cpp
File metadata and controls
68 lines (57 loc) · 1.29 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
#include <iostream>
#include "myclass.cpp"
#include <string>
#include <vector>
using namespace std;
int linearSearch(auto data, auto key);
int main ()
{
string name = "";
string search_key;
//int grade (0);
int result = 0;
vector <Class> Student (8);
for (int i = 0; i<Student.size(); ++i)
{
/*if (i>0)
{
cin.ignore();
}*/
cout << "Please enter the name: ";
getline (cin, name);
Student[i].setName(name);
/*cout << "Please enter the grade: ";
cin >> grade;
while ((grade<0) || (grade>100))
{
cout << "Please enter a value between 0 and 100: ";
cin >> grade;
}
Student[i].setGrade(grade);*/
}
cout<<endl<<"["<<Student.size()<<" values read from input source]"<<endl<<endl;
/*for (int i = 0; i<Student.size(); ++i)
{
cout << "Name: " << Student[i].getName() << "\tGrade: " << Student[i].getGrade() << endl;;
}
cout <<endl;*/
cout<< "Enter a value to search for: ";
cin >> search_key;
result = linearSearch(Student, search_key);
cout<<" '"<<search_key<<"' was ";
if (result == -1)
cout<<"not found";
else
cout<<"found at index "<<result<<endl<<endl;
system("pause");
return 0;
}
int linearSearch(auto data, auto key)
{
for (int i=0; i<data.size(); ++i)
{
if (data[i].getName()==key)
return i;
}
return -1; //not found
}