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
94 lines (68 loc) · 1.91 KB
/
Main.cpp
File metadata and controls
94 lines (68 loc) · 1.91 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
#include <iostream>
#include <string>
#include <vector>
#include "Student.h"
using namespace std;
void fillVector(vector<Student> newClass) ;
void printVector(const vector<Student> newClass);
int linearSearch(vector<Student> newClass, string name);
int main() {
string result;
string key;
string name;
char choice;
vector<Student> myclass;
fillVector(myclass);
printVector(myclass);
cout << "Would you like to search for a student? y = yes , n = no" << endl;
cin >> choice;
while(choice == 'y')
{
cout << "Please enter the name of the student you would like to search" << endl;
cin >> name;
result = linearSearch(myclass, name);
cout << " " << name << "was ";
if ( result == name )
cout << " found";
else
cout << " not found" << result;
cout << "Would you like to search for a student? y = yes , n = no" << endl;
cin >> choice;
}
return 0;
}
int linearSearch(vector<Student> newClass, string name)
{
for(int i = 0; i < newClass.size(); i ++)
{
if ( newClass[i].getName() == name )//we found it
{
return i;//return its location
}
}//end for
return -1;//element not found
}
void fillVector(vector<Student> newClass) {
string name;
char grade;
cout << "Please enter the amount of students in class? " << endl;
int numStudents;
cin >> numStudents;
for (int i = 0; i < numStudents; i++) {
cout << "Please enter Student's Name: ";
cin >> name;
cout << "Please enter Student's Grade: ";
cin >> grade;
Student newStudent(name, grade);
newClass.push_back(newStudent);
cout << endl;
}
cout << endl;
}
void printVector(const vector<Student> newClass) {
for (unsigned int i = 0; i < newClass.size(); i++) {
cout << "Student Name: " << newClass[i].getName() << endl;
cout << "Student Grade: " << newClass[i].getGrade() << endl;
cout << endl;
}
}