// election.cpp #include #include #include using namespace std; int main() { string cand_names[5]; // names of cand_names 1..4 int vote_counts[5]; // tally vote_counts for cand_names 1..4 // Read candidate names from file into name[1]..name[4] get_names (cand_names); // Intialize count[1]..count[4] to zeros initialize(vote_counts); // Read votes from votes.dat and tally them using array of vote_counts tally(vote_counts); // Output names and vote counts for each candidate print_summary(cand_names, vote_counts); return 0; } /* candnams.dat Grey Mastrekova Quirot Rodal */ /* votes.dat 1 4 3 2 1 2 4 4 2 4 2 4 12 2 3 3 4 2 2 5 2 3 4 2 1 4 2 3 1 2 2 4 4 2 2 1 4 4 3 1 2 4 2 1 4 2 4 3 4 2 1 3 2 2 3 4 2 2 4 1 4 3 4 3 2 2 1 2 3 3 2 3 2 3 4 1 2 4 2 4 1 2 4 2 1 3 3 4 2 1 3 4 2 4 24 1 2 1 4 2 4 3 3 4 1 2 3 2 3 3 3 2 4 4 */ /* Invalid vote: 12 Invalid vote: 5 Invalid vote: 24 CANDIDATE NO. OF VOTES Grey 17 Mastrekova 38 Quirot 24 Rodal 32 */