wheelsmanx

CPS 271 Machine Problem 4

Apr 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <string>
  5. #include <iomanip>
  6. using namespace std;
  7. class Precinct {
  8. public:
  9. int sum = 0;
  10. void add(int sumA) {
  11. this->sum = this->sum + sumA;
  12. }
  13. };
  14.  
  15. class ElectionData {
  16. public:
  17. string elector;
  18. int pre1;
  19. int pre2;
  20. int pre3;
  21. int ElectorSum;
  22. void setData(string tempElector, int tempPre1, int tempPre2, int tempPre3) {
  23. this->elector = tempElector;
  24. this->pre1 = tempPre1;
  25. this->pre2 = tempPre2;
  26. this->pre3 = tempPre3;
  27. this->ElectorSum = pre1 + pre2 + pre3;
  28. }
  29. void resetElector(string newTempElector) {
  30. this->elector = newTempElector;
  31. }
  32. int P1() {
  33. return this->pre1;
  34. }
  35. int P2() {
  36. return this->pre2;
  37. }
  38. int P3() {
  39. return this->pre3;
  40. }
  41. string getData() {
  42. string tempString = " ";
  43. tempString += elector;
  44. tempString += " ";
  45. tempString += to_string(pre1);
  46. tempString += " ";
  47. tempString += to_string(pre2);
  48. tempString += " ";
  49. tempString += to_string(pre3);
  50. return tempString;
  51. }
  52. };
  53.  
  54. string Elector;
  55. int a, b, c;
  56. vector <ElectionData> ElectionDataVector;
  57. int i = 0;
  58.  
  59. void main() {
  60. ifstream fileInput;
  61. fileInput.open("C:\\temp\\mp4election.txt");
  62. while (!fileInput.eof())
  63. {
  64. fileInput >> Elector >> a >> b >> c;
  65. ElectionData *tempElection = new ElectionData;
  66. tempElection->setData(Elector, a, b, c);
  67. ElectionDataVector.push_back(*tempElection);
  68. }
  69.  
  70. Precinct PreA, PreB, PreC;
  71. for (ElectionData CurrentElection : ElectionDataVector) {
  72. PreA.add(CurrentElection.P1());
  73. PreB.add(CurrentElection.P2());
  74. PreC.add(CurrentElection.P3());
  75. }
  76.  
  77. cout << "\t" << "\t" << "\t" << "\t" << "\t" << "\t" << "Total " << endl;
  78.  
  79. for (ElectionData CurrentElection : ElectionDataVector) {
  80. cout << setw(25) << left << CurrentElection.elector << CurrentElection.pre1 << "\t" << CurrentElection.pre2 << "\t" << CurrentElection.pre3 << "\t" << CurrentElection.ElectorSum << endl;
  81. }
  82. cout << setw(25) << left << "Total: " << PreA.sum << "\t" << PreB.sum << "\t" << PreC.sum << endl;
  83. system("pause");
  84. }
Advertisement
Add Comment
Please, Sign In to add comment