wheelsmanx

CPS 272 Machine Problem 2 Source.cpp

Nov 4th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include "Header.h"
  5.  
  6. using namespace std;
  7.  
  8. int totalVotes = 0;
  9. int numberOfCand = 0;
  10.  
  11. class candidate {
  12. public:
  13. string candidateName;
  14. double votes;
  15. };
  16.  
  17.  
  18.  
  19.  
  20. void main() {
  21. vector <candidate> Election;
  22.  
  23.  
  24. vector<string> inputFromFile = getInputFile(".//ElectionData.txt");
  25. vector<string> stringSplitVect = cStringSplit(inputFromFile[0], " ");
  26. for (int i = 1; i < inputFromFile.size(); i++) {
  27. vector <string> tempVector = cStringSplit(inputFromFile[i], " ");
  28. candidate tempCan;
  29. tempCan.candidateName = tempVector[0];
  30. tempCan.votes = String2Int(tempVector[tempVector.size() - 1]);
  31. Election.push_back(tempCan);
  32. }
  33.  
  34. for (int i = 0; i < Election.size(); i++) {
  35. totalVotes = totalVotes + Election[i].votes;
  36. numberOfCand++;
  37. }
  38. cout << setw(20) << stringSplitVect[0] << setw(23) << stringSplitVect[stringSplitVect.size() - 1] << setw(26) << " Percent of Vote" << endl;
  39. for (int i = 0; i < Election.size(); i++) {
  40. cout << setw(20) << Election[i].candidateName << " : " << setw(20) << Election[i].votes << " : ";
  41. cout << setw(20) << Election[i].votes / totalVotes << " % " << endl;
  42. }
  43.  
  44. system("pause");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment