From ec022fff6d36f630e16211caf6d6357595052a79 Mon Sep 17 00:00:00 2001 From: KirRupteD Date: Thu, 16 Feb 2017 22:38:45 -0400 Subject: [PATCH 1/4] Added header file --- Winners.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Winners.h 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 From c0826464b9dcfdfc7aee6f4c4a05a3368124b54e Mon Sep 17 00:00:00 2001 From: KirRupteD Date: Thu, 16 Feb 2017 22:39:53 -0400 Subject: [PATCH 2/4] Added implementation file --- Winners.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Winners.cpp 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; +} From a9b8694bbe1a35e866ab63403e20528331c33665 Mon Sep 17 00:00:00 2001 From: KirRupteD Date: Thu, 16 Feb 2017 22:41:01 -0400 Subject: [PATCH 3/4] Added client file --- main.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6e18f42 --- /dev/null +++ b/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include "Winners.h" + + + + +using namespace std; +void fillvector(vector&); +void printvector(vector&); + + + +int main(){ + vector contestants; + fillvector(contestants); + printvector(contestants); + + 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; + } +} + From 7758a611ae4aa571e20f0ee791b5f6a22ec4c79b Mon Sep 17 00:00:00 2001 From: KirRupteD Date: Thu, 16 Feb 2017 23:18:10 -0400 Subject: [PATCH 4/4] added linear search to hellogit project --- main.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 6e18f42..c73a6c7 100644 --- a/main.cpp +++ b/main.cpp @@ -9,15 +9,56 @@ 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; + - system("pause"); + + + +cout << "Program \"search it\" is now finished." << endl; + + + + + + //system("pause"); return 0; } void fillvector(vector& newContestant){ @@ -46,4 +87,14 @@ void printvector(vector& newContestant){ 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