Question: Declare the following prototypes : int sumVotes(int list[], int size); int winnerIndex(int list[], int size); In the mainline : Declare an int variable to store

Declare the following prototypes :

int sumVotes(int list[], int size); int winnerIndex(int list[], int size);

In the mainline :

Declare an int variable to store the number of candidates.

Declare an int variable to store the total number of votes cast.

Declare a string pointer to be used to point to the array of candidate names. Declare an int pointer to be used to point to the array of candidate votes.

Set manipulators so the vote percentages are outputted with 2 dec. positions

Prompt the user for number of candidates and store the answer.

Set the pointers to contain the addresses of dynamic arrays(one array for the candidate names and the other to contain the votes for each candidate)

Prompt the use to enter candidate's name and the votes received by the candidate

Create a loop to accept(input) the users responses and store them in the arrays

Call the sumVotes functions and store returned value

Output the heading line of the report

Output the detail lines of the report by creating a loop that loops through the two arrays

Output the total line

Output the winner line (see output below)

End program.

After the mainline :

Define the functions called within the mainline.

sumVotes function :

Loop through the array containing the votes and add them up.

winnerIndex function :

Loop through the array containing the votes and determine the index of the element with the largest value.

Sample execution :

Enter number of candidates: 5

Enter candidate's name and the votes received by the candidate.

Miller 34 Novak 12 Zubich 56 Jackson 45 Fenski 38

Candidate Votes Received % of Total Votes Miller 34 18.38 Novak 12 6.49 Zubich 56 30.27 Jackson 45 24.32 Fenski 38 20.54 Total 185

The Winner of the Election is: Zubich

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!