Advertisement
teknique

Untitled

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