#include #include #include using namespace std; int main(){ /////////////////// // Variables to hold the position, party, and name of each person running // string nullifierAuditorCandidate, fielditeAuditorCandidate, nullifierCoronerCandidate, fielditeCoronerCandidate, nullifierRecorderCandidate, fielditeRecorderCandidate; // variables to count votes int nullifierAuditor = 0, nullifierCoroner = 0, nullifierRecorder = 0, fielditeAuditor = 0, fielditeCoroner = 0, fielditeRecorder = 0, otherAuditor = 0, otherCoroner = 0, otherRecorder = 0; int totalAuditorVotes = 0, totalCoronerVotes = 0, totalRecorderVotes = 0, miscastVotes = 0; // string for the input file name we will be using string input_file_name; ifstream datafile; // variables to hold input as it is read // First, for the positions and names from the first six lines of the file string candidateParty, candidatePosition, candidateName; // Next, for the votes char officeVoted, partyVoted; // open the file or fail cout << "Please enter the name of the county results file to use: "; getline(cin,input_file_name); // open file if it is there datafile.open(input_file_name.c_str()); if (!datafile) { cerr << "Could not open file: "<< input_file_name << " for reading." << endl; exit(1); } // Read the six lines of candidate information and set up the candidate information for (int i = 0; i < 6; i++) { datafile >> candidateParty >> candidatePosition; getline(datafile, candidateName); if ("Nullifier" == candidateParty ){ if ("Recorder" == candidatePosition) { nullifierRecorderCandidate = candidateName; } else if ("Auditor" == candidatePosition) { nullifierAuditorCandidate = candidateName; } else { nullifierCoronerCandidate = candidateName; } } else { if ("Recorder" == candidatePosition) { fielditeRecorderCandidate = candidateName; } else if ("Auditor" == candidatePosition) { fielditeAuditorCandidate = candidateName; } else { fielditeCoronerCandidate = candidateName; } } } // Now that we have read the candidate information, we can count the votes while (datafile >> officeVoted >> partyVoted){ switch (officeVoted){ case 'R': case 'r': totalRecorderVotes++; switch (partyVoted) { case 'F': case 'f': fielditeRecorder++; break; case 'N': case 'n': nullifierRecorder++; break; default: otherRecorder++; } break; case 'A': case 'a': totalAuditorVotes++; switch (partyVoted) { case 'F': case 'f': fielditeAuditor++; break; case 'N': case 'n': nullifierAuditor++; break; default: otherAuditor++; } break; case 'C': case 'c': totalCoronerVotes++; switch (partyVoted) { case 'F': case 'f': fielditeCoroner++; break; case 'N': case 'n': nullifierCoroner++; break; default: otherCoroner++; } break; default: miscastVotes++; } } // Output the results neatly, put winner on top cout << endl << endl; cout << setw(25) << "Election results: " << endl; cout << setw(30) << "Office of Auditor" << endl; if (fielditeAuditor >= nullifierAuditor) { cout << setw(35) << fielditeAuditorCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeAuditor << endl; cout << setw(35) << nullifierAuditorCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierAuditor << endl; } else { cout << setw(35) << nullifierAuditorCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierAuditor << endl; cout << setw(35) << fielditeAuditorCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeAuditor << endl; } cout << setw(35) << "Other" << setw (15) << "(Other)" << setw(5) << otherAuditor << endl; cout << setw(50) << "Total Auditor Votes" << setw(5) << totalAuditorVotes << endl; cout << endl; cout << setw(30) << "Office of Coroner" << endl; if (fielditeCoroner >= nullifierCoroner) { cout << setw(35) << fielditeCoronerCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeCoroner << endl; cout << setw(35) << nullifierCoronerCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierCoroner << endl; } else { cout << setw(35) << nullifierCoronerCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierCoroner << endl; cout << setw(35) << fielditeCoronerCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeCoroner << endl; } cout << setw(35) << "Other" << setw (15) << "(Other)" << setw(5) << otherCoroner << endl; cout << setw(50) << "Total Coroner Votes" << setw(5) << totalCoronerVotes << endl; cout << endl; cout << setw(30) << "Office of Recorder" << endl; if (fielditeRecorder >= nullifierRecorder) { cout << setw(35) << fielditeRecorderCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeRecorder << endl; cout << setw(35) << nullifierRecorderCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierRecorder << endl; } else { cout << setw(35) << nullifierRecorderCandidate << setw(15) << "(Nullifier)" << setw(5) << nullifierRecorder << endl; cout << setw(35) << fielditeRecorderCandidate << setw(15) << "(Fieldite)" << setw(5) << fielditeRecorder << endl; } cout << setw(35) << "Other" << setw (15) << "(Other)" << setw(5) << otherRecorder << endl; cout << setw(50) << "Total Recorder Votes" << setw(5) << totalRecorderVotes << endl; cout << endl; cout << setw(50) << "Miscast Votes" << setw(5) << miscastVotes << endl; return 0; }