Question
This is a C++ assignment using pointers and dynamic arrays. I have some of it written, need help! A. Declare the following prototypes : int
This is a C++ assignment using pointers and dynamic arrays. I have some of it written, need help!
A. Declare the following prototypes :
int sumVotes(int list[], int size);
int winnerIndex(int list[], int size);
B. 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.
C. After the mainline :
Define the functions called within the mainline.
1. sumVotes function :
Loop through the array containing the votes and add them up (See Example 8-6 in the textbook)
2. winnerIndex function :
Loop through the array containing the votes and determine the index of the element with the largest value (See Example 8-6 in the textbook)
D. 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
--------------------------------
Process exited with return value 0
Press any key to continue . . .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started