Question: please answer (b) by using c++ code and Condorcet system During an election, there were a given number n of candidates, each being named with

 please answer (b) by using c++ code and Condorcet system During

an election, there were a given number n of candidates, each being

named with precisely one number from {1, 2,..., n}. The results of

please answer (b) by using c++ code and Condorcet system

During an election, there were a given number n of candidates, each being named with precisely one number from {1, 2,..., n}. The results of the election are contained in the given file named profile.dat". Each row of "profile.dat" contains the preference list of a voter in the election with the candidates displayed from most preferred on the leftmost to least preferred on the rightmost. (a) In the Condorcet's method, a candidate r is said to beat another candidate Y if at least half of the voters rank over y on their preference lists. Write a C++ function with the following header bool beat(unsigned candidate_1, unsigned candidate_2, unsigned noofCandidates, string profile) to determine if a candidate beats another. Here the parameters candidate_1 and candidate_2 are the numbers naming the two candidates in the election, the parameter no0fCandidates is the number of candidates in the election, and the parameter profileName is the name of the file containing the results of the election. If the candidate represented by the number given by candidate_1 beats the one represented by the number given by candidate_2, the function evaluates to true; otherwise, the function evaluates to false. As an example, suppose that there are n= 6 candidates in an election and that the following is the content of the file "profile.dat": 4 6 5 2 3 1 6 1 3 5 2 4 6 4 3 1 5 2 2 6 3 1 4 5 6 1 5 4 3 2 4 6 3 5 1 2 5 1 2 4 3 6 5 6 2 3 1 4 Then the function call beat(1, 4, 6, "profile.dat") (b) In the Condorcet's method, a candidater is among the winners if x beats every other candidate y. Assuming that there are 6 candidates, write a C++ code to decide the winner(s). You may use the code from part (a). Note that there can be no winner, a unique winner, or more than one winner. Your code should be able to distinguish these cases and issue the corresponding output in each case as follows: There is no winner. There is a unique winner: candidate 5. There are 2 winners. They are candidates 34

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!