Answered step by step
Verified Expert Solution
Link Copied!

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++ image text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions