In: Computer Science
Modify the following code to make the input and output look like this.
Input
5 Vader 1300 Kirk 1250 Adama 1000 Reynolds 1615 Oneill 1470
Output
Enter the number of candidates: 5 Enter candidate's name :Vader 1300 Enter votes received :Enter candidate's name :Kirk 1250 Enter votes received :Enter candidate's name :Adama 1000 Enter votes received :Enter candidate's name :Reynolds 1615 Enter votes received :Enter candidate's name :Oneill 1470 Enter votes received : Name Votes Percentage Vader 1300.00 19.59% Kirk 1250.00 18.84% Adama 1000.00 15.07% Reynolds 1615.00 24.34% Oneill 1470.00 22.16% Total 6635 The Winner of the Election is Reynolds
//Abduljabbr sale11/8/2019//
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int size;
cout<<"Enter the number of candidates: ";
cin>>size;
string *names= new string[size];
double *votes=new double[size];
double sum=0;
double winner=-1;
string winnerName="";
int total=0;
//reading votes
for(int i=0;i<size;i++){
cout<<"Enter candidate's name :";
cin>>names[i];
cout<<"Enter votes received :";
cin>>votes[i];
sum+=votes[i];
//finding the winner
if(winner<votes[i]){
winner=votes[i];
winnerName=names[i];
}
}
cout<<endl;
//printing the data
cout << setprecision(2)<<fixed;
cout<<setw(20) << left
<<"Name"<<setw(20) << left
<<"Votes"<<setw(20) << left
<<"Percentage"<<endl;
for(int i=0;i<5;i++){
cout<<setw(20) << left<<names[i]<<setw(20)
<< left
<<votes[i]<<votes[i]/sum*100<<"%"<<endl;
total+=votes[i];
}
cout<<setw(20) << left<<"Total"<<setw(20)
<< left <<total<<endl;
cout<<"The Winner of the Election is
"<<winnerName;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
string *names;
double *votes;
double sum=0;
double winner=-1;
string winnerName="";
int total=0;
int size;
cout<<"Enter the number of candiates: ";
cin>>size;
names=new string[size];
votes=new double[size];
//reading votes
for(int i=0;i<size;i++){
cout<<"Enter candidate's name :";
cin>>names[i];
cout<<"Enter votes received :";
cin>>votes[i];
sum+=votes[i];
//finding the winner
if(winner<votes[i]){
winner=votes[i];
winnerName=names[i];
}
}
cout<<endl;
//printing the data
cout << setprecision(2)<<fixed;
cout<<setw(20) << left
<<"Name"<<setw(20) << left
<<"Votes"<<setw(20) << left
<<"Percentage"<<endl;
for(int i=0;i<5;i++){
cout<<setw(20) << left<<names[i]<<setw(20)
<< left
<<votes[i]<<votes[i]/sum*100<<"%"<<endl;
total+=votes[i];
}
cout<<setw(20) << left<<"Total"<<setw(20)
<< left <<total<<endl;
cout<<"The Winner of the Election is
"<<winnerName;
return 0;
}