Вы находитесь на странице: 1из 15

BEGIN ALGORITM

DECLARE TYPE
partyinfo= Record
candidate of datatype string
party of datatype string
candidatevotes of datatype integer
End
constitinfo= Record
WNA, DAP, UPM, PDR of datatype partyinfo
countedlvotes of datatype integer
spltvotes of datatype integer
castvotes of datatype integer
specvotes of datatype integer
genvotes of datatype integer
electors of datatype integer
spltpercent of datatype real
castvotespercent of datatype real
End
elecinfo= Record
castvotes of datatype integer
spltvotes of datatype integer
countedvotes of datatype integer
specvotes of datatype integer
genvotes of datatype integer
elecinfo1= Record
WNA, DAP, UPM, PDR of datatype elecinfo
End

VAR
overview: ARRAY [1..11] of constitinfo
results: ARRAY [1..11] of partyinfo
elec: ARRAY [1..11] of elecinfo1
x, yesno, pollno, pollnocount, countedvotes0, spltvotes0, specvotes0,
genvotes0, castvotes0, min, max, elector0, wcandidatevotes,
WNAallvotes, DAPallvotes, UPMallvotes, PNRallvotes, highestvotes of
datatype integer
wcandidate, wparty, highestparty of datatype string

Begin

PRINT (Welcome to the Trinbarjam Elections Exercise! There are 11


constituencies and 4 parties contesting: Democratic Action Party DAP,
Workers National Alliance WNA, United Progressive Movement UPM,
Peoples Democratic Revolution PDR. All of the parties field candidates
in every constituency except PDR which fields candidates in only the
first 6 constituencies )
{Initializing variables, prior to processing}
FOR x= 1 to 11
BEGIN
overview[x].WNA.candidate= NO CANDIDATE
overview[x].WNA.party= WNA
overview[x].WNA.candidatevotes= 0
overview[x].DAP.candidate= NO CANDIDATE
overview[x].DAP.party= DAP
overview[x].DAP.candidatevotes= 0
overview[x].UPM.candidate= NO CANDIDATE
overview[x].UPM.party= UPM
overview[x].UPM.candidatevotes= 0
overview[x].PDR.candidate= NO CANDIDATE
overview[x].PDR.party= PDR
overview[x].PDR.candidatevotes= 0
overview[x].countedvotes= 0
overview[x].spltvotes= 0
overview[x].castvotes= 0
overview[x].specvotes= 0
overview[x].genvotes= 0
overview[x].electors= 0
overview[x].spltvotespercent= 00.0
overview[x].castvotespercent= 00.0
results[x].candidate= NO CANDIDATE

results[x].party= NO PARTY
results[x].candidatevotes= 0
elec[x].WNA.castvotes= 0
elec[x].WNA.spltvotes= 0
elec[x].WNA.countedvotes= 0
elec[x].WNA.specvotes= 0
elec[x].WNA.genvotes= 0
elec[x].DAP.castvotes= 0
elec[x].DAP.spltvotes= 0
elec[x].DAP.countedvotes= 0
elec[x].DAP.specvotes= 0
elec[x].DAP.genvotes= 0
elec[x].UPM.castvotes= 0
elec[x].UPM.spltvotes= 0
elec[x].UPM.countedvotes= 0
elec[x].UPM.specvotes= 0
elec[x].UPM.genvotes= 0
elec[x].PDR.castvotes= 0
elec[x].PDR.spltvotes= 0
elec[x].PDR.countedvotes= 0
elec[x].PDR.specvotes= 0
elec[x].PDR.genvotes= 0
END
pollno= 0
pollnocount= 0
castvotes0= 0
countedvotes0= 0
spltvotes0= 0

specvotes0= 0
genvotes0= 0
spltvotespercent= 00.0
castvotespercent= 00.0
remaindervotes= 0
wcandidate= NO CANDIDATE
wparty= NO PARTY
wcandidatevotes= 0
highestvotes= 0
highestparty= NO PARTY
WNAallvotes= 0
DAPallvotes= 0
UPMallvotes= 0
PNRallvotes= 0
min= 0
max= 0

x=1 {this loop will loop 11 times and data for each
constituency will be entered}
WHILE (x<= 11) DO
BEGIN
PRINT (YOU ARE FILLING IN VOTE DATA FOR CONSTITUENCY,
x,. )
{to input names for the candidate in constituency x, so
candidate names for a constituency will not change}
PRINT (Does this constituency have all 4 parties contesting?
Type 1 for yes or 2 for no)
READ (yesno)
IF (yesno= 1) DO {all 4 parties}

BEGIN
PRINT (Enter the WNA candidate name for this
constituency :)
READ (overview[x].WNA.candidate)
PRINT (Enter the DAP candidate name for this
constituency :)
READ (overview[x].DAP.candidate)
PRINT (Enter the UPM candidate name for this
constituency :)
READ (overview[x].UPM.candidate)
PRINT (Enter the PDR candidate name for this
constituency :)
READ (overview[x].PDR.candidate)
END
ELSE BEGIN {only 3 of the 4 candidates}
PRINT (Enter the WNA candidate name for this
constituency :)
READ (overview[x].WNA.candidate)
PRINT (Enter the DAP candidate name for this
constituency :)
READ (overview[x].DAP.candidate)
PRINT (Enter the UPM candidate name for this
constituency :)
READ (overview[x].UPM.candidate)
END
{calculating general info in the overview array}
REPEAT
PRINT (This value must be in the range 6250 to 10795, if
you are asked to renter a value this means that you had
entered a value out of range before.)
PRINT (Enter the no. of registered electors: )

READ (electors0)
UNTIL (electors0 > 6250) AND (electors0 < 10795) {the value
must be in this range}
overview[x].electors= elector0
REPEAT
PRINT(This value must be in the range 3 to 5, inclusive, if
you are asked to renter a value this means that you had
entered a value out of range before.)
PRINT (Enter the no. of polling stations in this
constituency :)
READ (pollno)
UNTIL (pollno > 2) AND (pollno < 6) {this keeps the range for
polling stations}
FOR pollnocount= 1 to pollno DO {will loop around until all p
stations data is complete}
BEGIN
IF (yesno= 1) DO {all 4 parties}
BEGIN
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].WNA.candidate, of WNA:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].WNA.candidate, of WNA:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].WNA.candidate, of WNA:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0

elec[x].WNA.castvotes= castvotes0 +
elec[x].WNA.castvotes
elec[x].WNA.spltvotes= spltvotes0 +
elec[x].WNA.spltvotes
elec[x].WNA.countedvotes= countedvotes0 +
elec[x].WNA.countedvotes
elec[x].WNA.specvotes= specvotes0 +
elec[x].WNA.specvotes
elec[x].WNA.genvotes= genvotes0 +
elec[x].WNA.genvotes
{stop updating elec array for this party}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].DAP.candidate, of DAP:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].DAP.candidate, of DAP:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].DAP.candidate, of DAP:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0
elec[x].DAP.castvotes= castvotes0 +
elec[x].DAP.castvotes
elec[x].DAP.spltvotes= spltvotes0 +
elec[x].DAP.spltvotes
elec[x].DAP.countedvotes= countedvotes0 +
elec[x].DAP.countedvotes
elec[x].DAP.specvotes= specvotes0 +
elec[x].DAP.specvotes

elec[x].DAP.genvotes= genvotes0 +
elec[x].DAP.genvotes
{stop updating elec array for this party}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].UPM.candidate, of UPM:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].UPM.candidate, of UPM:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].UPM.candidate, of UPM:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0
elec[x].UPM.castvotes= castvotes0 +
elec[x].UPM.castvotes
elec[x].UPM.spltvotes= spltvotes0 +
elec[x].UPM.spltvotes
elec[x].UPM.countedvotes= countedvotes0 +
elec[x].UPM.countedvotes
elec[x].UPM.specvotes= specvotes0 +
elec[x].UPM.specvotes
elec[x].UPM.genvotes= genvotes0 +
elec[x].UPM.genvotes
{stop updating elec array for this party}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].PDR.candidate, of PDR:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].PDR.candidate, of PDR:)

READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].PDR.candidate, of PDR:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0
elec[x].PDR.castvotes= castvotes0 +
elec[x].PDR.castvotes
elec[x].PDR.spltvotes= spltvotes0 +
elec[x].PDR.spltvotes
elec[x].PDR.countedvotes= countedvotes0 +
elec[x].PDR.countedvotes
elec[x].PDR.specvotes= specvotes0 +
elec[x].PDR.specvotes
elec[x].PDR.genvotes= genvotes0 +
elec[x].PDR.genvotes
{stop updating elec array for this party}
END
ELSE BEGIN {only 3 of the 4 candidates}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].WNA.candidate, of WNA:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].WNA.candidate, of WNA:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].WNA.candidate, of WNA:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0

elec[x].WNA.castvotes= castvotes0 +
elec[x].WNA.castvotes
elec[x].WNA.spltvotes= spltvotes0 +
elec[x].WNA.spltvotes
elec[x].WNA.countedvotes= countedvotes0 +
elec[x].WNA.countedvotes
elec[x].WNA.specvotes= specvotes0 +
elec[x].WNA.specvotes
elec[x].WNA.genvotes= genvotes0 +
elec[x].WNA.genvotes
{stop updating elec array for this party}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].DAP.candidate, of DAP:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].DAP.candidate, of DAP:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].DAP.candidate, of DAP:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0
elec[x].DAP.castvotes= castvotes0 +
elec[x].DAP.castvotes
elec[x].DAP.spltvotes= spltvotes0 +
elec[x].DAP.spltvotes
elec[x].DAP.countedvotes= countedvotes0 +
elec[x].DAP.countedvotes
elec[x].DAP.specvotes= specvotes0 +
elec[x].DAP.specvotes

elec[x].DAP.genvotes= genvotes0 +
elec[x].DAP.genvotes
{stop updating elec array for this party}
{begin updating elec array for this party}
PRINT (Enter the number of votes cast for,
overview[x].UPM.candidate, of UPM:)
READ (castvotes0)
PRINT (Enter the number of spoilt votes for,
overview[x].UPM.candidate, of UPM:)
READ (spltvotes0)
countedvotes0= castvotes0 spltvotes0
PRINT (Enter the number of special votes for,
overview[x].UPM.candidate, of UPM:)
READ (specvotes0)
genvotes0= countedvotes0 specvotes0
elec[x].UPM.castvotes= castvotes0 +
elec[x].UPM.castvotes
elec[x].UPM.spltvotes= spltvotes0 +
elec[x].UPM.spltvotes
elec[x].UPM.countedvotes= countedvotes0 +
elec[x].UPM.countedvotes
elec[x].UPM.specvotes= specvotes0 +
elec[x].UPM.specvotes
elec[x].UPM.genvotes= genvotes0 +
elec[x].UPM.genvotes
{stop updating elec array for this party}
END
END
{start updating overview array}
overview[x].WNA.candiatevotes= elec[x].WNA.countedvotes
overview[x].DAP.candiatevotes= elec[x].DAP.countedvotes

overview[x].UPM.candiatevotes= elec[x].UPM.countedvotes
overview[x].PDR.candiatevotes= elec[x].PDR.countedvotes
overview[x].countedvotes= elec[x].WNA.countedvotes +
elec[x].DAP.countedvotes + elec[x].UPM.countedvotes +
elec[x].PDR.countedvotes
overview[x].spltvotes= elec[x].WNA.spltvotes +
elec[x].DAP.spltvotes + elec[x].UPM.spltvotes +
elec[x].PDR.spltvotes
overview[x].castvotes= elec[x].WNA.castvotes +
elec[x].DAP.castvotes + elec[x].UPM.castvotes +
elec[x].PDR.castvotes
overview[x].specvotes= elec[x].WNA.specvotes +
elec[x].DAP.specvotes + elec[x].UPM.specvotes +
elec[x].PDR.specvotes
overview[x].genvotes= elec[x].WNA.genvotes +
elec[x].DAP.genvotes + elec[x].UPM.genvotes +
elec[x].PDR.genvotes
overview[x].spltpercent=
(overview[x].spltvotes/overview[x].castvotes) *100
overview[x].castvotespercent=
(overview[x].castvotes/overview[x].electors) *100
{stop updating overview array}
{trying to find the winning candidate for constituency x}
wcandidate= overview[x].WNA.candidate
wparty= overview[x].WNA.party
wcandidatevotes= overview[x].WNA.candidatevotes
IF (overview[x].DAP.candidatevotes > wcandidatevotes)
BEGIN
wcandidate= overview[x].DAP.candidate
wparty= overview[x].DAP.party
wcandidatevotes= overview[x].DAP.candidatevotes
DAPallvotes= DAPallvotes + 1

END
ELSE
IF (overview[x].UPM.candidatevotes > wcandidatevotes)
BEGIN
wcandidate= overview[x].UPM.candidate
wparty= overview[x].UPM.party
wcandidatevotes= overview[x].UPM.candidatevotes
UPMallvotes= UPMallvotes + 1
END
ELSE
IF (overview[x].PNR.candidatevotes > wcandidatevotes)
BEGIN
wcandidate= overview[x].PNR.candidate
wparty= overview[x].PNR.party
wcandidatevotes= overview[x].PNR.candidatevotes
PDRallvotes= PDRallvotes + 1
END
ELSE
IF (overview[x].WNA.candidatevotes = wcandidatevotes)
BEGIN
WNAallvotes= WNAallvotes + 1
END
results[x].candidate= wcandidate
results[x].party= wparty
results[x].candidatevotes= wcandidatevotes
x= x + 1
END
PRINT(This is our list of the winning candidates)

x= 1
WHILE (x<= 11) DO
BEGIN
PRINT (THIS IS THE WINNER FOR CONSTSITUENCY, x, :)
PRINT (Winning candidate: ,results[x].candidate)
PRINT (Representing: ,results[x].party)
PRINT (Votes received: ,results[x].candidatevotes)
END
End.
END ALGORITHM

Вам также может понравиться