Question: please answer question a and b using c++. a and b is two different question and each question should have 1 code . Question 1

 please answer question a and b using c++. a and b

please answer question a and b using c++. a and b is two different question and each question should have 1 code .

Question 1 During an election, there were a given number of candidates, each being named with precisely one number from {1,2,...). The results of the election are contained in the given file named "profile.dar 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 candidater is said to beat another candidate if at least half of the voters rank rovery on their preference lists. Write a C++ function with the . a 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 noofCandidates 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 6 candidates in an election and that the following is the content of the file "profile.dat": 4 65 2 3 1 613524 6 4 3 1 5 2 2 6 3 1 4 5 61 5 4 3 2 463512 5 1 2 4 3 6 5 6 2314 Then the function call beat(1, 4, 6, "profile.dat") , 4, 6, 3 evaluates to true because 5 out of the 8 voters, ie, voters #2, #4, 45, and #7, and #8 rank candidate 1 over candidate 4. while the function call 1 beat(3, 4, 6, "profile.dat") evaluates to false because only 3 out of the 8 voters, t.e. voters #2, #4, and #8 rank candidate 3 over candidate 4. 4. (10 marks) (b) In the Condorcet's method, a candidater is among the winners in beats every other candidate ). 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!