diff --git a/Winners.cpp b/Winners.cpp new file mode 100644 index 0000000..c41006e --- /dev/null +++ b/Winners.cpp @@ -0,0 +1,31 @@ +#include "Winners.h" +#include +#include + +using namespace std; + +Winners::Winners(){ + + name = " "; + age = 0; + +} + +void Winners::setname(string a){ + + name = a; + + +} + +void Winners::setage(int b){ + age = b; +} + +string Winners::getname(){ + return name; +} + +int Winners::getage(){ + return age; +} diff --git a/Winners.h b/Winners.h new file mode 100644 index 0000000..d1091fd --- /dev/null +++ b/Winners.h @@ -0,0 +1,29 @@ +#ifndef Winners_H +#define Winners_H + + +#include +#include +using namespace std; +class Winners{ + +private: string name; + int age; + +public: + Winners(); + + + void setname(string); + + + void setage(int); + + + string getname(); + + + int getage(); + +}; +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c73a6c7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include "Winners.h" + + + + +using namespace std; +void fillvector(vector&); +void printvector(vector&); +int linearSearch(vector contestants, string key);//prototype + + + +int main(){ + int result; + string search_key, input; + vector contestants; + fillvector(contestants); + printvector(contestants); + cout << "To end input type the #-character (followed by Enter)" << endl; + cout << "Enter a value to search for: " ; + + + cin >> search_key; + + while (search_key != "#")//perform searches until sentinel entered + { + result = linearSearch(contestants, search_key); + + cout << " '" << search_key << "' was "; + + if (result == -1){ + cout << "not found"; + } + else { + cout << "found at index " << result << endl; + } + + + + + + cout << "Enter a value to search for: " << endl; + cin >> search_key; + } + + cout << "Program \"search it\" is now finished." << endl; + + + + + +cout << "Program \"search it\" is now finished." << endl; + + + + + + //system("pause"); + return 0; +} +void fillvector(vector& newContestant){ + Winners contestants; + string name; + string search_key, input; + int age; + + for (int i = 0; i < 4; i++){ + + cout << "Enter the name of the contestant" << endl; + cin >> name; + contestants.setname(name); + cout << " Enter the age of the contestant" << endl; + cin >> age; + contestants.setage(age); + + newContestant.push_back(contestants); + } + +} +void printvector(vector& newContestant){ + + for (unsigned int i = 0; i < 4; i++){ + cout << " Contestant name :" << newContestant[i].getname() << endl; + cout << "Contestant age :" << newContestant[i].getage() << endl; + } +} +int linearSearch(vector win, string key) +{ +for(int i = 0; i < win.size(); i++) +{ +if (win[i].getname() == key)//we found it +{ +return i;//return its location +} +}//end for +return -1;}//element not found +