Question
#include #include #include #include #include #include #include #include using namespace std;const string filename = votes.txt;const int maxCandidates = 8;struct Candidate{ string name = ; size_t
#include
cout << left << setw(namefieldwidth) << "Candidate" << ' ' << right << setw(votesfieldwidth) << "Votes Received" << ' ' << right << setw(percentfieldwidth) << setfill(' ') << "% of Total Votes " << endl << endl; for (size_t idx = 0; idx < nCandidates; ++idx) cout << left << setw(namefieldwidth) << candidates[idx].name << ' ' << right << setw(votesfieldwidth) << candidates[idx].votes << ' ' << right << setw(percentfieldwidth) << setfill(' ') << candidates[idx].percent << endl; size_t totalvotesfieldwidth = namefieldwidth + votesfieldwidth + 1; cout << setw(totalvotesfieldwidth) << totalvotes << endl << endl; cout << "The winner of the Election is " << candidates[maxidx].name << endl; } return 0;}
Modify the attached file to detect and display multiple candidates with the same number of votes: multiple winners, multiple candidates with the second highest number of votes, multiple candidates with the third highest number of votes, and so on.
example:
Suppose the candidates are A,B,C,D,E,F and G and their votes are:
A 100
B 200
C 200
D 400
E 100
F 400
G 300
Then your program should display,
A Fourth Place
B Third Place
C Third Place
D First Place
F First Place
G Second Place
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