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

C++ #include <iostream> #include <iomanip> #include <string> using namespace std

ID: 3729576 • Letter: C

Question

C++

#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
}

Mine Tap Luiy.y. L'amry . Mail. Fialux MINDTAP Gorman Jarratt Arrays and Strings in C (Example 7) +main.app Arrays and Strings #includ- #1nclude cinanip> Write a program narnes ol live carididales ina local election arid the murniber of votes received by each candidate. The program should then output each candidate's name, the number of votes rocelved, and the peroentage of the total votes reccived by the candidate. Your propram should alsao output the winner ol the election. A sarpleoulpul is: that allws the user ta enter the last 3 5 usung nanespace std; Int surWotes (int 1istL]. int stze) int u"1.ndez(int list[], int size); 18 tnt natn 12 declare array varatblos Candidate Votes Received % of Total Votes lohnson SO Miller Duffy Robinsa 2500 Ashtony 1800 Tatal 25.91 4000 20,73 14 nt 15 171 1H1 caut « setprecision(7); cout4 ·Lnter candtdate's nano and the votes receved by " 12.95 9.33 ec'the candidatend 28 19300 21load data into arrays 73 751 2 // set totalVotes The Winner of the Election is Duffy caut « .Candidat. VoteK Rmwived % of Total Votes. « endl; // output data 2 out Total 38 31utpot wine roturn Run Code TestGrade

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;

char voterNames[5][10];

float votePer;

int numbers[5];

int sum = 0;

cout << fixed << showpoint;

cout << setprecision(2);

cout << "Enter candidate's name and the votes received by "

<<"the candidate." << endl;

// load data into arrays

for(int i=0;i<5;i++){

  

cin >> voterNames[i];

  

}

for (int i = 0; i < 5; ++i)

{

cin >> numbers[i];

//sum += numbers[i];

}

// load data into arrays

// set totalVotes

totalVotes = sumVotes(numbers,5);

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

for (int i = 0; i < 5; ++i)

{

votePer= (numbers[i]/totalVotes)*100;

cout << voterNames[i] << " " << numbers[i] << " " << votePer << endl;

}

// output dat

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

// output winner

int winIndex = winnerIndex(numbers,5);

  

cout << "The winner of Election is " << voterNames[winIndex] << endl;

return 0;

}

int sumVotes(int list[], int size)

{

int sum=0;

for (int i = 0; i < size; ++i)

{

sum += list[i];

}

// function code

return sum;

}

int winnerIndex(int list[], int size)

{

// function code

int max=0, winIndex;

for (int i = 0; i < size; ++i)

{

if (list[i]>max){

max = list[i];

winIndex = i;

}

}

return winIndex;

}