Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Winner of the Election is Duffy. *******************************************

ID: 3708960 • Letter: T

Question

The Winner of the Election is Duffy.

************************************************

#include <iostream>

#include <iomanip>
#include <string>

using namespace std;

int sumVotes(int list[], int size);
int winnerIndex(int list[], int size);

int main()
{
// declare array varaibles
int totalVotes;
int i;

cout << fixed << showpoint;
cout << setprecision(2);
cout << "Enter candidate's name and the votes received by "
<<"the candidate." << endl;

// load data into arrays

// set totalVotes

cout << "Candidate Votes Received % of Total Votes" << endl;

// output data

cout << "Total " << totalVotes << endl;

// output winner
return 0;
}

int sumVotes(int list[], int size)
{
// function code
}

int winnerIndex(int list[], int size)
{
// function code
}

Candidate Votes Received % of Total Votes Johnson 5000 25.91 Miller 4000 20.73 Duffy 6000 31.09 Robinson 2500 12.95 Ashtony 1800 9.33 Total 19300

Explanation / Answer

#include <iostream>

#include <iomanip>
#include <string>

using namespace std;

int sumVotes(int list[], int size);
int winnerIndex(int list[], int size);

int main()
{
    // declare array varaibles
    int totalVotes;
    int i;

    cout << fixed << showpoint;
    cout << setprecision(2);
    cout << "Enter candidate's name and the votes received by "
         <<"the candidate." << endl;

    // load data into arrays
    string names[5];
    int votes[5];
    int size = 5;
    for(i = 0; i < size; ++i) {
       cout << "Name: ";
       cin >> names[i];
       cout << "Votes: ";
       cin >> votes[i];
   }
  
    // set totalVotes
   totalVotes = sumVotes(votes, size);
   int winner = winnerIndex(votes, size);
  
    cout << "Candidate    Votes Received   % of Total Votes" << endl;
   for(i = 0; i < size; ++i) {
       cout << names[i] << " " << votes[i] << " " << (votes[i]*100.0)/(totalVotes) << endl;
   }

    cout << "Total            " << totalVotes << endl;
   cout << "The Winner of the Election is " << names[winner] << "." << endl;
    // output winner
    return 0;
}

int sumVotes(int list[], int size)
{
    // function code
    int total = 0;
    for(int i = 0; i < size; ++i) {
       total += list[i];
   }
   return total;
}

int winnerIndex(int list[], int size)
{
    // function code
    int ind = 0;
    for(int i = 0; i < size; ++i) {
       if(list[i] > list[ind]) {
           ind = i;
       }
   }
   return ind;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote