From 7ec6bf9546748b260389f386ee87d440dc28694d Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 10:57:53 -0400 Subject: [PATCH 01/14] Create headerfile --- headerfile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 headerfile diff --git a/headerfile b/headerfile new file mode 100644 index 0000000..a8958ee --- /dev/null +++ b/headerfile @@ -0,0 +1,28 @@ +// CLASS DEFINITION + +#ifndef CANDIDATE_H +#define CANDIDATE_H +#include + +class Candidate +{ + private: + std::string candName; + int numVotes; + + public: + // default constructor + Candidate(); + + // overload constructor + Candidate(std::string, int); + + // accessors + std::string getCandName(); + int getNumVotes(); + + // mutators + void setCandName(std::string cand); + void setNumVotes(int votes); +}; +#endif From c9084ce24dfbfc784867671d9751475c01e89c5a Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:00:02 -0400 Subject: [PATCH 02/14] Create implementationfile --- implementationfile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 implementationfile diff --git a/implementationfile b/implementationfile new file mode 100644 index 0000000..5559fda --- /dev/null +++ b/implementationfile @@ -0,0 +1,38 @@ +//IMPLEMENTATION FILE + +#include "Candidate.h" +#include +#include + +using namespace std; + + +Candidate::Candidate(string cand, int votes) +{ + candName = cand; + numVotes = votes; +} + +// sets candidate name +void Candidate :: setCandName(string cand) +{ + candName = cand; +} + +// gets candidate name +string Candidate::getCandName() +{ + return candName; +} + +// sets number of votes +void Candidate::setNumVotes( int votes) +{ + numVotes = votes; +} + +//gets number of votes +int Candidate::getNumVotes() +{ + return numVotes; +} From 8a7277187414096a6f4d6ec5d6f36d57e0b6787f Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:00:26 -0400 Subject: [PATCH 03/14] Create clientfile --- clientfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 clientfile diff --git a/clientfile b/clientfile new file mode 100644 index 0000000..0208591 --- /dev/null +++ b/clientfile @@ -0,0 +1,50 @@ +// CLIENT FUNCTIONS + +#include "Candidate.h" +#include +#include +#include + +using namespace std; + +void addVector(vector&); +void printVector(const vector &); +int i = 0; + +int main() +{ + vector candidates(4); + + addVector(candidates); + printVector(candidates); + + return 0; +} + + +// add objects to vector +void addVector(vector& newCandidate) +{ + for (i = 0; i < newCandidate.size(); i++) + { + cout << "Enter Candidate Name: "; + cin >> cand; + + cout << "Enter Number of Votes: "; + cin >> votes; + + Candidate newCandidate(cand, votes); + newCandidate.push_back(newCandidate); + cout << endl; + } +} + +//print contents of vector +void printVector(const vector & newCandidate) +{ + for (i = 0; i < newCandidate.size(); i++ ) + { + cout << "Candidate Name: " << candidates[i].getCandName() << endl; + cout << "Number of Votes: " << candidates[i].getNumVotes() << endl; + } +} From c39eb96feb554a2d183ac15ee3b6cca1ca544b11 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:32:15 -0400 Subject: [PATCH 04/14] Delete clientfile --- clientfile | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 clientfile diff --git a/clientfile b/clientfile deleted file mode 100644 index 0208591..0000000 --- a/clientfile +++ /dev/null @@ -1,50 +0,0 @@ -// CLIENT FUNCTIONS - -#include "Candidate.h" -#include -#include -#include - -using namespace std; - -void addVector(vector&); -void printVector(const vector &); -int i = 0; - -int main() -{ - vector candidates(4); - - addVector(candidates); - printVector(candidates); - - return 0; -} - - -// add objects to vector -void addVector(vector& newCandidate) -{ - for (i = 0; i < newCandidate.size(); i++) - { - cout << "Enter Candidate Name: "; - cin >> cand; - - cout << "Enter Number of Votes: "; - cin >> votes; - - Candidate newCandidate(cand, votes); - newCandidate.push_back(newCandidate); - cout << endl; - } -} - -//print contents of vector -void printVector(const vector & newCandidate) -{ - for (i = 0; i < newCandidate.size(); i++ ) - { - cout << "Candidate Name: " << candidates[i].getCandName() << endl; - cout << "Number of Votes: " << candidates[i].getNumVotes() << endl; - } -} From ee237716b2abcedf30ef6987320314e37a10bd99 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:32:30 -0400 Subject: [PATCH 05/14] Delete headerfile --- headerfile | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 headerfile diff --git a/headerfile b/headerfile deleted file mode 100644 index a8958ee..0000000 --- a/headerfile +++ /dev/null @@ -1,28 +0,0 @@ -// CLASS DEFINITION - -#ifndef CANDIDATE_H -#define CANDIDATE_H -#include - -class Candidate -{ - private: - std::string candName; - int numVotes; - - public: - // default constructor - Candidate(); - - // overload constructor - Candidate(std::string, int); - - // accessors - std::string getCandName(); - int getNumVotes(); - - // mutators - void setCandName(std::string cand); - void setNumVotes(int votes); -}; -#endif From 1e819b413e92107c82be6d252b05adbd3ecd8fd5 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:32:41 -0400 Subject: [PATCH 06/14] Delete implementationfile --- implementationfile | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 implementationfile diff --git a/implementationfile b/implementationfile deleted file mode 100644 index 5559fda..0000000 --- a/implementationfile +++ /dev/null @@ -1,38 +0,0 @@ -//IMPLEMENTATION FILE - -#include "Candidate.h" -#include -#include - -using namespace std; - - -Candidate::Candidate(string cand, int votes) -{ - candName = cand; - numVotes = votes; -} - -// sets candidate name -void Candidate :: setCandName(string cand) -{ - candName = cand; -} - -// gets candidate name -string Candidate::getCandName() -{ - return candName; -} - -// sets number of votes -void Candidate::setNumVotes( int votes) -{ - numVotes = votes; -} - -//gets number of votes -int Candidate::getNumVotes() -{ - return numVotes; -} From d079760caa1099ea42219d4f686d9ad78167d4b1 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:41:04 -0400 Subject: [PATCH 07/14] Added header file. --- HEADER | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 HEADER diff --git a/HEADER b/HEADER new file mode 100644 index 0000000..ff5668d --- /dev/null +++ b/HEADER @@ -0,0 +1,29 @@ +// CLASS DEFINITION + +#ifndef CANDIDATE_H +#define CANDIDATE_H +#include + +class Candidate +{ + private: + std::string candName; + int numVotes; + + public: + //default constructor + Candidate(); + + // overload constructor + Candidate(std::string, int); + + //accessors + std::string getCandName(); + int getNumVotes(); + + //mutators + void setCandName(std::string cand); + void setNUmVotes(int votes); + +}; +#endif From e0614653d0e730b7dd463d527869ae5abef1c162 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:52:18 -0400 Subject: [PATCH 08/14] Added implementation file. --- IMPLEMENTATION | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 IMPLEMENTATION diff --git a/IMPLEMENTATION b/IMPLEMENTATION new file mode 100644 index 0000000..9f82bc3 --- /dev/null +++ b/IMPLEMENTATION @@ -0,0 +1,37 @@ +// IMPLEMENTATION FILE + +#include "Candidate.h" +#include +#include + +using namespace std; + +Candidate::Candidate(string cand, int votes) +{ + candName = cand; + numVotes = votes; +} + +//sets candidate name +void Candidate:: setCandName(string, cand) +{ + candName = cand; +} + +//gets candidate name +string Candidate::getCandName() +{ + return candName; +} + +//sets number of votes +void Candidate::setNumVotes(int votes) +{ + numVotes = votes; +} + +//gets number of votes +int Candidate::getNumVotes() +{ + return numVotes; +} From bf91ac0cd00479e1d6c08c7a96bd72d130a27301 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 25 Jan 2017 11:58:34 -0400 Subject: [PATCH 09/14] Added client file. --- CLIENT | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 CLIENT diff --git a/CLIENT b/CLIENT new file mode 100644 index 0000000..ed0aa22 --- /dev/null +++ b/CLIENT @@ -0,0 +1,55 @@ +// CLIENT FUNCTIONS + +#include "Candidate.h" +#include +#include +#include + +using namespace std; + +void addVector(vector&); +void printVector(const vector &); +int i = 0; + +int main() +{ + vector candidates(4); + + addVector(candidates); + printVector(candidates); + + return 0; +} + + +// add objects to vector +void addVector(vector& newCandidate) +{ + for (i = 0; i < newCandidate.size(); i++) + { + cout << "Enter Candidate Name: "; + cin >> cand; + + cout << "Enter Number of Votes: "; + cin >> votes; + + Candidate newCandidate(cand, votes); + newCandidate.push_back(newCandidate); + cout << endl; + } +} + + +//print contents of vector +void printVector(const vector & newCandidate) +{ + for (i = 0; i < newCandidate.size(); i++) + { + cout << "Candidate Name: " << candidates[i].getCandName() << endl; + cout << "Number of Votes: " << candidates[i].getNumVotes() << endl; + } +} + + + + From f49857a73099ac7400a54b3e95c6482dcce9e96f Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 8 Feb 2017 10:44:34 -0400 Subject: [PATCH 10/14] Added linear search function to client file --- CLIENT | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CLIENT b/CLIENT index ed0aa22..e9f45f3 100644 --- a/CLIENT +++ b/CLIENT @@ -9,7 +9,20 @@ using namespace std; void addVector(vector&); void printVector(const vector &); -int i = 0; + +int linearSearch(auto data, auto key);//prototype + +int linearSearch(auto data, auto key) +{ + for (int i=0; i < data.size(); i++) + { + if (data[i] == key) + { + return i; + } + } + return -1; +} int main() { @@ -25,7 +38,7 @@ int main() // add objects to vector void addVector(vector& newCandidate) { - for (i = 0; i < newCandidate.size(); i++) + for (int i = 0; i < newCandidate.size(); i++) { cout << "Enter Candidate Name: "; cin >> cand; @@ -43,7 +56,7 @@ void addVector(vector& newCandidate) //print contents of vector void printVector(const vector & newCandidate) { - for (i = 0; i < newCandidate.size(); i++) + for (int i = 0; i < newCandidate.size(); i++) { cout << "Candidate Name: " << candidates[i].getCandName() << endl; cout << "Number of Votes: " << candidates[i].getNumVotes() << endl; From 511996af7ae5885e5775465a7b48bf9b3d65d6f6 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 8 Feb 2017 11:24:08 -0400 Subject: [PATCH 11/14] Changes to client file --- HEADER => Candidate.h | 0 CLIENT => client.cpp | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) rename HEADER => Candidate.h (100%) rename CLIENT => client.cpp (65%) diff --git a/HEADER b/Candidate.h similarity index 100% rename from HEADER rename to Candidate.h diff --git a/CLIENT b/client.cpp similarity index 65% rename from CLIENT rename to client.cpp index e9f45f3..3880bad 100644 --- a/CLIENT +++ b/client.cpp @@ -26,18 +26,22 @@ int linearSearch(auto data, auto key) int main() { - vector candidates(4); + vector newCandidate(4); - addVector(candidates); - printVector(candidates); + addVector(newCandidate); + printVector(newCandidate); return 0; } // add objects to vector -void addVector(vector& newCandidate) +void addVector() { + vector newCandidate; + string cand; + int votes; + for (int i = 0; i < newCandidate.size(); i++) { cout << "Enter Candidate Name: "; @@ -47,19 +51,19 @@ void addVector(vector& newCandidate) cin >> votes; Candidate newCandidate(cand, votes); - newCandidate.push_back(newCandidate); + newCandidate.push_back(cand, votes); cout << endl; } } //print contents of vector -void printVector(const vector & newCandidate) +void printVector(const vector newCandidate) { for (int i = 0; i < newCandidate.size(); i++) { - cout << "Candidate Name: " << candidates[i].getCandName() << endl; - cout << "Number of Votes: " << candidates[i].getNumVotes() << endl; + cout << "Candidate Name: " << newCandidate[i].getCandName() << endl; + cout << "Number of Votes: " << newCandidate[i].getNumVotes() << endl; } } From 6467acbef992db882bfb0b2efdc4c1bc13a230b0 Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Wed, 8 Feb 2017 11:48:15 -0400 Subject: [PATCH 12/14] Changes to files --- IMPLEMENTATION => Candidate.cpp | 6 ++++++ client.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) rename IMPLEMENTATION => Candidate.cpp (89%) diff --git a/IMPLEMENTATION b/Candidate.cpp similarity index 89% rename from IMPLEMENTATION rename to Candidate.cpp index 9f82bc3..cc51417 100644 --- a/IMPLEMENTATION +++ b/Candidate.cpp @@ -12,6 +12,12 @@ Candidate::Candidate(string cand, int votes) numVotes = votes; } +Candidate::Candidate() +{ + string candName; + int numVotes{0}; +} + //sets candidate name void Candidate:: setCandName(string, cand) { diff --git a/client.cpp b/client.cpp index 3880bad..c9d62d7 100644 --- a/client.cpp +++ b/client.cpp @@ -8,7 +8,7 @@ using namespace std; void addVector(vector&); -void printVector(const vector &); +void printVector(vector &); int linearSearch(auto data, auto key);//prototype @@ -36,9 +36,9 @@ int main() // add objects to vector -void addVector() +void addVector(vector & newCandidate) { - vector newCandidate; + string cand; int votes; @@ -50,15 +50,15 @@ void addVector() cout << "Enter Number of Votes: "; cin >> votes; - Candidate newCandidate(cand, votes); - newCandidate.push_back(cand, votes); + Candidate candidates(cand, votes); + newCandidate.push_back({cand, votes}); cout << endl; } } //print contents of vector -void printVector(const vector newCandidate) +void printVector( vector newCandidate) { for (int i = 0; i < newCandidate.size(); i++) { From a13aa7879a288adcc10dd679bf48aa31e91a15ef Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Thu, 23 Feb 2017 01:16:50 -0400 Subject: [PATCH 13/14] Added linear search algorithm to client file --- Candidate.cpp | 15 +++------------ Candidate.h | 16 ++++++---------- client.cpp | 35 +++++++++++++++-------------------- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/Candidate.cpp b/Candidate.cpp index cc51417..48d8863 100644 --- a/Candidate.cpp +++ b/Candidate.cpp @@ -1,9 +1,6 @@ -// IMPLEMENTATION FILE - #include "Candidate.h" -#include -#include - +#include +#include using namespace std; Candidate::Candidate(string cand, int votes) @@ -12,14 +9,8 @@ Candidate::Candidate(string cand, int votes) numVotes = votes; } -Candidate::Candidate() -{ - string candName; - int numVotes{0}; -} - //sets candidate name -void Candidate:: setCandName(string, cand) +void Candidate::setCandName(string cand) { candName = cand; } diff --git a/Candidate.h b/Candidate.h index ff5668d..befdf52 100644 --- a/Candidate.h +++ b/Candidate.h @@ -1,5 +1,3 @@ -// CLASS DEFINITION - #ifndef CANDIDATE_H #define CANDIDATE_H #include @@ -12,18 +10,16 @@ class Candidate public: //default constructor - Candidate(); + Candidate() + { + candName = " "; + numVotes = 0; + } - // overload constructor Candidate(std::string, int); - - //accessors std::string getCandName(); int getNumVotes(); - - //mutators void setCandName(std::string cand); - void setNUmVotes(int votes); - + void setNumVotes(int votes); }; #endif diff --git a/client.cpp b/client.cpp index c9d62d7..4367d0f 100644 --- a/client.cpp +++ b/client.cpp @@ -26,47 +26,42 @@ int linearSearch(auto data, auto key) int main() { - vector newCandidate(4); + vector newCandidate; // vector declaration addVector(newCandidate); printVector(newCandidate); + system("pause"); + return 0; } - -// add objects to vector -void addVector(vector & newCandidate) +// add objects to vector +void addVector(vector &newCandidate) { - - string cand; + std::string cand; int votes; - - for (int i = 0; i < newCandidate.size(); i++) + + for (int i = 0; i < 4; i++) { - cout << "Enter Candidate Name: "; - cin >> cand; + cout << "Enter Candidate's name: "; + std::getline(cin>>ws,cand); - cout << "Enter Number of Votes: "; + cout << "Enter number of votes: "; cin >> votes; - Candidate candidates(cand, votes); - newCandidate.push_back({cand, votes}); + newCandidate.push_back(Candidate(cand, votes)); + cout << endl; } } - //print contents of vector -void printVector( vector newCandidate) +void printVector(vector &newCandidate) { - for (int i = 0; i < newCandidate.size(); i++) + for (size_t i = 0; i < newCandidate.size(); i++) { cout << "Candidate Name: " << newCandidate[i].getCandName() << endl; cout << "Number of Votes: " << newCandidate[i].getNumVotes() << endl; } } - - - - From 1e57a890e8f32dae0b9b8233360c0c52ef92844c Mon Sep 17 00:00:00 2001 From: namastayinschool Date: Thu, 23 Feb 2017 02:11:24 -0400 Subject: [PATCH 14/14] Changes made to client file --- client.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client.cpp b/client.cpp index 4367d0f..b45a312 100644 --- a/client.cpp +++ b/client.cpp @@ -10,13 +10,13 @@ using namespace std; void addVector(vector&); void printVector(vector &); -int linearSearch(auto data, auto key);//prototype +int linearSearch(vector &newCandidate, auto key);//prototype -int linearSearch(auto data, auto key) +int linearSearch(vector &newCandidate, auto key) { - for (int i=0; i < data.size(); i++) + for (int i=0; i < newCandidate.size(); i++) { - if (data[i] == key) + if (newCandidate[i] == key) { return i; } @@ -26,8 +26,11 @@ int linearSearch(auto data, auto key) int main() { + auto k; + vector newCandidate; // vector declaration - + + linearSearch(&newCandidate, k); addVector(newCandidate); printVector(newCandidate);