Question
C++ needed You must use dynamic arrays covered in chapter 12 for this exercise. Do not use static arrays covered in chapter 8 of the
C++ needed
You must use dynamic arrays covered in chapter 12 for this exercise. Do not use static arrays covered in chapter 8 of the textbook. Write a program for the following problem that processes voting information. DO NOT use global variables.
a) Write a void function to ask for the last names of a series of candidates and the number of votes received by each candidate. Use a sentinel value to stop reading data. The function must be able to pass the needed arrays. Note the function will have input statements. b) Write a string function to return the name of the winner (through the return value of the function) along with the number of votes received (through the parameter list) by the winner. c) Write a string function to return the name of the loser (through the return value of the function) along with the number of votes received (through the parameter list) by the loser. d) Write a int function to return the total number of votes casted. e) Write a int function to return the average of the number of votes casted. This function must use the function defined in step (e). f) Write a void function to sort the name and the corresponding votes. The function must return (through the parameter list, of course) the sorted data. You can use an existing sort algorithm. Dont reinvent the wheel! g) Write a void function to display each candidates name, the number of votes received, and the percentage of the total votes received by the candidate in a sorted order (call your sort function). Also, display the total and average number of votes along with the winner and loser information. The display must be in a tabular format as shown at the end of this document. The percent of votes must be displayed with 2 digits after the decimal point.
h) Write a int function that accepts as parameter the name of a candidate and return the number of votes received by the candidate. So, if the user enters Duck, the output will be 6000. Of course, if the given name does not exist, display an appropriate message.
A sample output is as follows. Note that this is just a sample test case. Your code should work for any set of data. Candidate Votes Received % of Total Votes Duck 6000 40.00 Fish 5000 33.33 Shark 4000 26.66 Total 15000 Average 5000 The winner of the election is Duck with 6000 votes The looser of the election is Shark with 4000 votes
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