Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- #include <iostream>
- #include <sstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- 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)
- {
- for(int i = 0; i < countyNameVector.size(); i++)
- {
- cout << countyNameVector[i] << " " << countyNCount[i] << " " << countyFCount[i] << " " << countyOCount[i] << endl;
- NTotal = NTotal + countyNCount[i];
- FTotal = FTotal + countyFCount[i];
- OTotal = OTotal + countyOCount[i];
- }
- cout << NTotal << " " << FTotal << " " << OTotal << endl;
- }
- void search_county(const std::vector<string> & countyNameVector, const std::vector<int> & countyNCount, const vector<int> & countyFCount, const std::vector<int> & countyOCount)
- {
- string searchname;
- cout << "Enter the county file to search for: ";
- cin >> searchname;
- for(int i = 0; i < countyNameVector.size(); i++)
- {
- if(searchname == countyNameVector[i])
- {
- cout << countyNameVector[i] << " " << countyNCount[i] << "" << countyFCount[i] << " " << countyOCount[i] << endl;
- }
- else
- {
- cout << "No county was found!" << endl;
- }
- }
- }
- 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)
- {
- char vote;
- string filename;
- string countyName;
- NCount = 0;
- FCount = 0;
- OCount = 0;
- cout << "Enter the county file to process: ";
- cin >> filename;
- std::ifstream input((filename).c_str());
- if(input.is_open())
- {
- input >> countyName;
- countyNameVector.push_back(countyName);
- while(input >> vote)
- {
- if(vote == 'N' || vote == 'n')
- {
- NCount = NCount + 1;
- }
- else if(vote == 'F' || vote == 'f')
- {
- FCount = FCount + 1;
- }
- else
- {
- OCount = OCount + 1;
- }
- }
- countyNCount.push_back(NCount);
- countyFCount.push_back(FCount);
- countyOCount.push_back(OCount);
- }
- cout << countyName << endl;
- }
- char get_menu_choice()
- {
- char selection;
- cin >> selection;
- return selection;
- }
- int main()
- {
- vector <string> countyNameVector;
- vector <int> countyNCount;
- vector <int> countyFCount;
- vector <int> countyOCount;
- int NCount = 0;
- int FCount = 0;
- int OCount = 0;
- int NTotal = 0;
- int FTotal = 0;
- int OTotal = 0;
- char selection;
- do
- {
- cout << "Add a county election file A" << endl;
- cout << "Show election totals on screen P" << endl;
- cout << "Search for county results S" << endl;
- cout << "Exit the program Q" << endl;
- cout << "Please enter your choice: ";
- selection = get_menu_choice();
- if(selection == 'a' || selection == 'A')
- {
- add_county_election_file(countyNameVector, countyNCount, countyFCount, countyOCount, NCount, FCount, OCount);
- }
- if(selection == 'p' || selection == 'P')
- {
- print_results(countyNameVector, countyNCount, countyFCount, countyOCount, NTotal, FTotal, OTotal);
- }
- if(selection == 'S' || selection == 's')
- {
- search_county(countyNameVector, countyNCount, countyFCount, countyOCount);
- }
- }while((selection != 'Q' && selection != 'q'));
- return 0;
- }a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement