Advertisement
teknique

Untitled

Nov 4th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <iostream>
  6. #include <sstream>
  7. #include <vector>
  8. #include <algorithm>
  9. using namespace std;
  10.  
  11. void print_results(const std::vector<string> & countyNameVector, const std::vector<int> & countyNCount, const vector<int> & countyFCount, const std::vector<int> & countyOCount, int & NTotal, int & FTotal, int & OTotal)
  12. {
  13. for(int i = 0; i < countyNameVector.size(); i++)
  14. {
  15. cout << countyNameVector[i] << " " << countyNCount[i] << " " << countyFCount[i] << " " << countyOCount[i] << endl;
  16. NTotal = NTotal + countyNCount[i];
  17. FTotal = FTotal + countyFCount[i];
  18. OTotal = OTotal + countyOCount[i];
  19. }
  20. cout << NTotal << " " << FTotal << " " << OTotal << endl;
  21. }
  22.  
  23. void search_county(const std::vector<string> & countyNameVector, const std::vector<int> & countyNCount, const vector<int> & countyFCount, const std::vector<int> & countyOCount)
  24. {
  25. string searchname;
  26. cout << "Enter the county file to search for: ";
  27. cin >> searchname;
  28. for(int i = 0; i < countyNameVector.size(); i++)
  29. {
  30. if(searchname == countyNameVector[i])
  31. {
  32. cout << countyNameVector[i] << " " << countyNCount[i] << "" << countyFCount[i] << " " << countyOCount[i] << endl;
  33. }
  34. else
  35. {
  36. cout << "No county was found!" << endl;
  37. }
  38. }
  39. }
  40. void add_county_election_file(std::vector<string> & countyNameVector, std::vector<int> & countyNCount, vector<int> & countyFCount, std::vector<int> & countyOCount, int & NCount, int & FCount, int & OCount)
  41. {
  42. char vote;
  43. string filename;
  44. string countyName;
  45. NCount = 0;
  46. FCount = 0;
  47. OCount = 0;
  48.  
  49. cout << "Enter the county file to process: ";
  50. cin >> filename;
  51. std::ifstream input((filename).c_str());
  52. if(input.is_open())
  53. {
  54. input >> countyName;
  55. countyNameVector.push_back(countyName);
  56. while(input >> vote)
  57. {
  58. if(vote == 'N' || vote == 'n')
  59. {
  60. NCount = NCount + 1;
  61. }
  62. else if(vote == 'F' || vote == 'f')
  63. {
  64. FCount = FCount + 1;
  65. }
  66. else
  67. {
  68. OCount = OCount + 1;
  69. }
  70. }
  71. countyNCount.push_back(NCount);
  72. countyFCount.push_back(FCount);
  73. countyOCount.push_back(OCount);
  74. }
  75. cout << countyName << endl;
  76. }
  77.  
  78. char get_menu_choice()
  79. {
  80. char selection;
  81. cin >> selection;
  82. return selection;
  83. }
  84.  
  85. int main()
  86. {
  87. vector <string> countyNameVector;
  88. vector <int> countyNCount;
  89. vector <int> countyFCount;
  90. vector <int> countyOCount;
  91. int NCount = 0;
  92. int FCount = 0;
  93. int OCount = 0;
  94. int NTotal = 0;
  95. int FTotal = 0;
  96. int OTotal = 0;
  97. char selection;
  98.  
  99. do
  100. {
  101. cout << "Add a county election file A" << endl;
  102. cout << "Show election totals on screen P" << endl;
  103. cout << "Search for county results S" << endl;
  104. cout << "Exit the program Q" << endl;
  105. cout << "Please enter your choice: ";
  106. selection = get_menu_choice();
  107.  
  108. if(selection == 'a' || selection == 'A')
  109. {
  110. add_county_election_file(countyNameVector, countyNCount, countyFCount, countyOCount, NCount, FCount, OCount);
  111. }
  112.  
  113. if(selection == 'p' || selection == 'P')
  114. {
  115. print_results(countyNameVector, countyNCount, countyFCount, countyOCount, NTotal, FTotal, OTotal);
  116.  
  117. }
  118. if(selection == 'S' || selection == 's')
  119. {
  120. search_county(countyNameVector, countyNCount, countyFCount, countyOCount);
  121. }
  122.  
  123.  
  124. }while((selection != 'Q' && selection != 'q'));
  125. return 0;
  126.  
  127.  
  128. }a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement