diff --git a/Candidate.cpp b/Candidate.cpp new file mode 100644 index 0000000..48d8863 --- /dev/null +++ b/Candidate.cpp @@ -0,0 +1,34 @@ +#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; +} diff --git a/Candidate.h b/Candidate.h new file mode 100644 index 0000000..befdf52 --- /dev/null +++ b/Candidate.h @@ -0,0 +1,25 @@ +#ifndef CANDIDATE_H +#define CANDIDATE_H +#include + +class Candidate +{ + private: + std::string candName; + int numVotes; + + public: + //default constructor + Candidate() + { + candName = " "; + numVotes = 0; + } + + Candidate(std::string, int); + std::string getCandName(); + int getNumVotes(); + void setCandName(std::string cand); + void setNumVotes(int votes); +}; +#endif diff --git a/client.cpp b/client.cpp new file mode 100644 index 0000000..b45a312 --- /dev/null +++ b/client.cpp @@ -0,0 +1,70 @@ +// CLIENT FUNCTIONS + +#include "Candidate.h" +#include +#include +#include + +using namespace std; + +void addVector(vector&); +void printVector(vector &); + +int linearSearch(vector &newCandidate, auto key);//prototype + +int linearSearch(vector &newCandidate, auto key) +{ + for (int i=0; i < newCandidate.size(); i++) + { + if (newCandidate[i] == key) + { + return i; + } + } + return -1; +} + +int main() +{ + auto k; + + vector newCandidate; // vector declaration + + linearSearch(&newCandidate, k); + addVector(newCandidate); + printVector(newCandidate); + + system("pause"); + + return 0; +} + +// add objects to vector +void addVector(vector &newCandidate) +{ + std::string cand; + int votes; + + for (int i = 0; i < 4; i++) + { + cout << "Enter Candidate's name: "; + std::getline(cin>>ws,cand); + + cout << "Enter number of votes: "; + cin >> votes; + + newCandidate.push_back(Candidate(cand, votes)); + + cout << endl; + } +} + +//print contents of vector +void printVector(vector &newCandidate) +{ + for (size_t i = 0; i < newCandidate.size(); i++) + { + cout << "Candidate Name: " << newCandidate[i].getCandName() << endl; + cout << "Number of Votes: " << newCandidate[i].getNumVotes() << endl; + } +}