Answered step by step
Verified Expert Solution
Question
1 Approved Answer
With C++ 2. [20 points] Write a program that allows to read from a file the last names of the candidates in an election and
With C++ 2. [20 points] Write a program that allows to read from a file the last names of the candidates in an election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate in descending order. Your program should also output the winner of the election. A sample output is: Candidate Johnson Brown Miller Duffy Robinson Votes Received 6000 5000 4000 2500 1800 % of Total Votes 31.09 25.91 20.73 12.95 9.33 Total 19300 The Winner of the Election is Johnson Your program should have the following functions: (a) Write a function openFile that prompts a user to enter a file name and opens it. (b) Write a function getData that reads from the file the candidate names and their number of votes received and returns them in 2 separate arrays. number of votes and returns an array of percentages of votes array of names, the arrays of the number of votes, and the array of percentages), and (c) Write a function computePercentages that takes as its parameter an array of (d) Write a function sortVotes that takes as its parameters the three arrays (i.e, the sort them in descending order of the number of votes or percentages. (e) Write a function display that displays the candidate names, their number of votes received, their percentages in descending order, and the total number of votes, as formatted above. (f) Write a function displayWinner that displays the winner of the election
With C++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started