diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..13f59e3 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include "Student.h" + +using namespace std; + +void fillVector(vector newClass) ; +void printVector(const vector newClass); +int linearSearch(vector newClass, string name); + +int main() { + + + + string result; + string key; + string name; + char choice; + vector 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 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 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 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; + + } +} \ No newline at end of file diff --git a/Student.cpp b/Student.cpp new file mode 100644 index 0000000..b66aa1d --- /dev/null +++ b/Student.cpp @@ -0,0 +1,32 @@ +#include +#include "Student.h" + + +Student::Student() { + newGrade = ' '; +} + +Student::Student(string name, char grade) { + newName = name; + newGrade = grade; +} + +string Student::getName() const { + return newName; +} + +char Student::getGrade() const { + return newGrade; +} + +void Student::setName(string name) { + newName = name; +} + +void Student::setGrade(char grade) { + newGrade = grade; +} + + + + diff --git a/Student.h b/Student.h new file mode 100644 index 0000000..0148240 --- /dev/null +++ b/Student.h @@ -0,0 +1,25 @@ +#ifndef STUDENT_H +#define STUDENT_H + +#include +#include +using namespace std; + +class Student { + private: + string newName; + char newGrade; + + public: + Student(); + + Student(string, char); + + string getName() const; + char getGrade() const; + + void setName (string); + void setGrade(char); +}; +#endif // !STUDENT_H +