Votes

This is a software development task and an implementation task.

One of the ways in which votes may be counted in an election is by a transferable vote system. There are a number of such systems in use in different parts of the world. One of them is called the Alternative Vote (AV) system. For this task the AV system is implemented in the way described below and this is the only method to be used in this task.

In the AV system, a candidate has to obtain an absolute majority, that is, more than half the valid votes cast in the election. This remains true no matter how many candidates contest the election. The ballot paper, an example of which is shown below, consists of the names of the candidates, which are also numbered. Each voter fills in a grid to identify the number of the candidate who is their 1st choice, their 2nd choice, and so on, until all candidates have been included once in the grid.

votes1.jpg - 12/2015

The first time the votes are counted, only each voter’s first choice is taken into account. If a candidate polls more than half of the votes cast, he or she is declared to be elected. If there is no absolute majority, the candidate with the lowest number of votes is eliminated and the votes are counted again. Only one candidate may be eliminated after any count. In any count, voters, whose preferred candidate has been eliminated, have their next choice counted instead. Candidates are eliminated and further counts are carried out until one candidate has an absolute majority, or all the remaining candidates are tied on the same number of votes.

The image below shows the ballot paper choices for 12 voters.

votes2.jpg - 12/2015

After the first count, candidate 1 has four votes, candidate 3 has three votes, candidates 2 and 5 have two votes each and candidate 4 has one vote. No candidate has an absolute majority, so candidate 4 is eliminated and a recount is made.

After this recount, candidate 1 has four votes, candidates 3 and 5 have three votes each and candidate 2 has two votes. Again no candidate has an absolute majority, so candidate 2 is eliminated. Following a further recount, candidate 1 has five votes, candidate 5 has four votes and candidate 3 has three votes.

The elimination of candidate 3 leads to a final recount which gives seven votes to candidate 5 and five votes to candidate 1. Candidate 5 (Olivia Pembury) is therefore elected.

You are to write a program that will decide the winner (if any) of an Alternative Vote election.

To do this, you must use a high level language. State the language and the version you use.

You are expected to provide full annotation of your program code and to use meaningful names throughout.

You must complete the following tasks, each of which must be presented separately in your final submission.

For the following tasks you are to assume that there are at least 2 and no more than 6 candidates and at least 10 and no more than 20 ballot papers.

(a) Write program code that will input the number of candidates in an election, followed by the preferences shown for the candidates on each ballot paper. For this task, you are to assume that all the ballot papers are completed correctly. The preferences shown on the ballot papers are to be stored in a two dimensional array, similar in form to Fig. 3.2 on page 10.
The code should also count the number of ballot papers entered.

Provide evidence of your code, which should be fully annotated. [6 Marks]

(b) Write program code that will read each ballot stored in the array created in (a) and count the total number of first choice votes for each candidate.
The code should then report which of three possibilities has occurred: an absolute majority, a tie between all candidates, or the need for a recount.

Provide evidence of your code, which should be fully annotated. [6 Marks]

(c) Develop a test plan to test the code you have written in (a) and (b). The plan must identify exactly what is being tested and what outcome is expected. The test plan should include three sets of data, each of which should consist of 10 valid ballot papers for 5 candidates.
Write a short program to test your code with these sets of test data and, in each case, output the result after the first count.

Provide evidence of the testing and the output. [5 Marks]

One problem that arises during elections is that not all ballot papers are completed correctly. For the purposes of this task, a valid ballot paper is one that shows a level of preference for every candidate, in
the form required, and where no preference is repeated.

(d) Develop the section of program code that you wrote in (a), so that any invalid ballot papers are rejected and not entered into the array.

The number of invalid ballot papers should be counted as well as the number of valid ones.

Provide evidence of the whole of this section of rewritten code, which should be fully annotated. All new or amended code, together with its annotations, should be clearly identified. [8 Marks]

A further problem in Alternative Vote elections occurs when a recount is required and more than one candidate has the lowest number of votes. For the purposes of this task, if this happens, the user should be asked to input the number of the candidate who should be eliminated.

(e) Develop the program code that you wrote in (b) so that, whenever a recount is required, the candidate with the fewest number of votes is eliminated before the new count takes place. Remember that only one candidate can be eliminated at each stage.

The code should then recount the number of votes for each remaining candidate. This will mean establishing the leading choice on each ballot paper represented in the original array, after excluding eliminated candidates.

The code should provide for recounts to continue until one candidate has an absolute majority or all remaining candidates are tied.

The code should report the result of the election, either by naming the winner, together with the percentage of the total valid votes obtained, or by declaring a tie between named candidates. The total numbers of valid and invalid votes cast should also be reported.

Provide hard copy evidence of the whole of this section of rewritten code, which should be fully annotated. All new or amended code, together with its annotations, should be clearly identified. [11 Marks]

(f) Extend the test plan you created in (c) so that it takes account of the problems of handling invalid ballot papers and recounts, as well as elections involving different numbers of candidates. The plan must identify exactly what is being tested and what outcome is expected. The new test plan should include sufficient sets of data for testing your whole program as developed in (d) and (e).

Provide evidence of the testing and the outputs that result. [8 Marks]

 

This task was worth 44 Marks.  It was a software development task and an implementation task that orginally appeared in OCR 2507 Task 3 Jun 2007.  All rights and copyright to OCR.  Please refer to the OCR Copyright Statement for further information.

About CDB 361 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.