Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix the uploaded code. I get an error message when I compiler it. /// Header files section #include #include #include using namespace std; ///

Please fix the uploaded code. I get an error message when I compiler it.

image text in transcribed

/// Header files section #include #include #include using namespace std; /// function prototypes void readCandidatesDetails (string lastNames[],int numberOfVotes [], int size); int getIndexofWinner(int numberOfVotes[], int size); int getTotalVotes (int numberofVotes[], int size) ; void printElectionResults (string lastNames [],int numberOfVotes [], int size, int index, int totalVotes); /// start main function int main () {

/// declare constant for the maximum number of /// candidates in the election const int ARRAY_SIZE = 5 /// create parallel arrays for the last names and /// the number of votes received string lastNames[ARRAY_SIZE]; int numberOfVotes[ARRAY_SIZE]; int winnerIndex; int totalVotes; /// ca1l the readCandidates Details function readCandidatesDetails (lastNames, numberOfVotes, ARRAY_SIZE); /// call the getIndexOfWinner function winnerIndex = getIndexofWinner(numberOfVotes, ARRAY_SIZE) ; /// call the getTotalVotes function totalvotes = getTotalVotes(numberOfVotes, ARRAY_SIZE); /// call the printElectionResults function printElectionResults (lastNames, numberOfVotes, ARRAY_SIZE, winnerIndex, totalVotes) ; return 0; } /// end of main function

/// readCandidatesDetails function prompts and reads /// the last name and the number of votes received for /// each candidate void readCandidatesDetails (string lastNames [], int numberOfVotes [ ], int size) {

/// repeat the loop to read the last name and /// the number of votes received of each candidate for (int i = 0; i

cout > lastNames [i]; cout > numberOfVotes [i]; } /// end of readCandidates Details method } /// get IndexOfWinner function finds and returns the index ///of the highest number of votes in the given array int get IndexofWinner(int numberOfVotes[], int size) {

/// local variables int index = 0; int maximum = numberofVotes [0]; /// find the index of the highest number of votes for (int i = 1; i

if (numberOfVotes [i] > maximum) {

maximum = numberOfVotes [il; index = i; }

} /// return the index of the highest number of votes return index; } /// end of getIndexOfWinner function /// getTotalVotes function computes and returns the total /// number of votes in the given array int getTotalvotes (int numberOfVotes [], int size) {

/// compute the total number of votes int totalNumberofVotes = 0; for (int i = 0; i

/// return the total number of votes return totalNumberofVotes; } /// end of getTotalVotes function ///printElectionResults function prints the election /// results in a table format void printElectionResults (string lastNames [], int numberOfVotes [], int size, int index,int totalVotes) {

cout

cout

cout Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the win- ner of the election. A sample output is: Candidate 7. Votes Received % of Total Votes Johnson Miller Duffy Robinson Ashtony Total 5000 4000 6000 2500 1800 19300 25.91 20.73 31.09 12.95 9.33 The Winner of the Election is Duffy

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

denigration of emotional outbursts; being reserved;

Answered: 1 week ago

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago