Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <iomanip>
- #include "Header.h"
- using namespace std;
- int totalVotes = 0;
- int numberOfCand = 0;
- class candidate {
- public:
- string candidateName;
- double votes;
- };
- void main() {
- vector <candidate> Election;
- vector<string> inputFromFile = getInputFile(".//ElectionData.txt");
- vector<string> stringSplitVect = cStringSplit(inputFromFile[0], " ");
- for (int i = 1; i < inputFromFile.size(); i++) {
- vector <string> tempVector = cStringSplit(inputFromFile[i], " ");
- candidate tempCan;
- tempCan.candidateName = tempVector[0];
- tempCan.votes = String2Int(tempVector[tempVector.size() - 1]);
- Election.push_back(tempCan);
- }
- for (int i = 0; i < Election.size(); i++) {
- totalVotes = totalVotes + Election[i].votes;
- numberOfCand++;
- }
- cout << setw(20) << stringSplitVect[0] << setw(23) << stringSplitVect[stringSplitVect.size() - 1] << setw(26) << " Percent of Vote" << endl;
- for (int i = 0; i < Election.size(); i++) {
- cout << setw(20) << Election[i].candidateName << " : " << setw(20) << Election[i].votes << " : ";
- cout << setw(20) << Election[i].votes / totalVotes << " % " << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment