Write a C++ program that allows the user to declare the inside main () a two-dim
ID: 3647630 • Letter: W
Question
Write a C++ program that allows the user to declare the inside main () a two-dimensional character array to store lastnames of 5 candidates in a local election and a long array to store the number of votes received by each candidate in the election. Inside main (), pass both the arrays to a function Input () to input lastnames and votes received of the candidate. You must use looping control structures. Use the data shown below. Write the input data to a file "Election.Dat" (don't write column headings in this data file). Inside main (), pass both the arrays to a function Output () that will read data file "Election.Dat" into arrays and display lastnames and votes received of the candidate in a table form. You must use looping control structures. Inside main (), pass both the arrays to a function PercVotes () that will output each candidate's name, the number of votes received, and the calculated percentage of the total votes received by the candidate. The function should also output the winner of the election. The sample output for this function is shown below. Then write the output of the program in data file "ElectionRep.Dat" in format below with appropriate column headings. This file will not be read later on. The winner of the election is DuffyExplanation / Answer
#include using std::cerr; using std::endl; #include #include using namespace std; double PercVotes(long sum, long votes) { Return votes*100/sum; } int Winner(int[] vote) { int i = 0; long large=0; int index=0; for(i = 0; ilarge) { large = vote[i]; index = i; } } } void output(long total, int winner) { string name[5]; long votes[5]; double per[5]; int i = 0; ifstream in("test.dat"); in.open("election.dat"); while(!in.eof()) { in >>name[i]; in >> votes[i]; in >> per[i]; i= i+1; } in >> temp; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.