Advertisement
teknique

Untitled

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