English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

(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 hard copy evidence of your code, which should be fully annotated.

[6]
(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 hard copy evidence of your code, which should be fully annotated.

2007-03-10 11:28:35 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

My impression of your homework question is that you are going to count votes for a particular office. The program would have to be able to deal with a varying number of candidates as some elections have more than two parties running. (Republicans, Democrates, Green Party, Libertarian, Rainbow ect) You would have two or more candidates.

I do not think you would have to consider multiple offices in each election so you could just count votes for a single office like president. If you have to do multiple offices then you are still going to use similar techniques but add the abaility to track multiple offices.


Pseudo Code:

Enter the number of candidates running.
Dimension an array for the number of candidates plus one for none of the above or blank

enter a conditional loop which will let you indicate which candidate has a vote. Enter button to tally the vote and a Compute button to exit the loop and compute the stats

In your loop each candidate is represented by a particular index value. For each vote entered increment the value referenced by a particular index by one


When you exit the tally loop and compute your array will hold individual counts entered for each candidate Add each element in the array to get a total number of cast votes

Using the total cast votes compute each canddates percentage. Create another array which will hold the percentage results

Now sort through the array for the highest percentage and determine if they are the winner based upon the margin (difference ) between the other candidates. If the margin is large enough on all candidates then declare a winner else RECOUNT. (And watch out for chads :-) )

2007-03-10 13:17:57 · answer #1 · answered by MarkG 7 · 1 0

fedest.com, questions and answers