Question: write this code using dynamic arrays instead of static arrays #include #include #include using namespace std; const int NUM _ CANDIDATES = 5 ; void
write this code using dynamic arrays instead of static arrays #include
#include
#include
using namespace std;
const int NUMCANDIDATES ;
void readCandidateDatastringint;
int sumVotesint;
int determineWinnerstringint;
void printResultsstringintdouble;
int main
string lastNamesNUMCANDIDATES;
int votesNUMCANDIDATES;
double percentagesNUMCANDIDATES;
readCandidateData lastNames votes;
int totalVotes sumVotesvotes;
for int i ; i NUMCANDIDATES; i
percentagesistaticcast votesi totalVotes;
printResults lastNames votes percentages;
int winnerIndex determineWinner lastNames votes;
cout "The winner of the election is lastNameswinnerIndex endl;
return ;
void readCandidateDatastring lastNames int votes
for int i ; i NUMCANDIDATES; i
cout "Candidate i last name: ;
cin lastNamesi ;
cout "Votes recieved: lastNamesi: ;
cin votesi ;
int sumVotes int votes
int total ;
for int i ; i NUMCANDIDATES ; i
total votesi ;
return total ;
int determineWinner string lastNames int votes
int maxIndex ;
for int i ; i NUMCANDIDATES ; i
if votesi votesmaxIndex
maxIndex i ;
return maxIndex ;
void printResults string lastNames int votes double percentages
cout setw left "Candidate" setw right "Votes" setw "Percentage" endl;
cout setfill setw setfill endl;
cout fixed setprecision;
for int i ; i NUMCANDIDATES ; i
cout setw left lastNamesi setw right votesi setw percentagesi endl;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
