Concept

How does a Borda-count program process ranked election ballots?

ComputerScienceOne / Exercises

"Exercise 9.10. Ranked voting elections are elections where each voter ranks each candidate rather than just voting for a single candidate. If there are n candidates, then each voter will rank them 1 (best) through n (worst). Usually, the winner of such an election is determined by a Condorcet method (the candidate that would win in by a majority in all head-to-head contests). However, we’ll use an alternative method, a Borda count . In a Borda count, points are awarded to each candidate for each ballot. For every number 1 ranking, a candidate receives n points, for every 2 ranking, a candidate gets n − 1 points, and so on. For a rank of n , the candidate only receives 1 point. The candidates are then ordered by their total points and the one with the highest point count wins the election. Such a system usually leads to a “consensus” candidate rather than one preferred by a majority. Implement a Borda-count based ranked voting program. Your program will read in a file in the following format. The first line will contain an ordered list of candidates delimited by commas. Each line after that will represent a single ballot’s ranking of the candidates and will contain comma delimited integers 1 through n . The order of the rankings will correspond to the order of the candidates on the first line. Your program will take an input file name as a command line argument, open the file and process it. It will then report the results including the point total for each candidate (in order) as well as the overall winner. It will also report the total number of ballots. You may assume each ballot is valid and all rankings are provided. An example input: Alice,Bob,Charlie,Deb 2,1,4,3 3,4,2,1 4,2,3,1 3,2,1,4 3,1,4,2 An example output: Election Results Number of ballots: 5 Candidate Points Bob 15 Deb 14 Charlie 11 Alice 10\n\nWinner is Bob"

Related Ideas

How does a Borda-count program process ranked election ballots? | ComputerScienceOne | Bifalgorithm | Bifalgorithm