1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
irina [24]
2 years ago
15

write a c++program that allows the user to enter the last names of fivecandidates in a local election and the number of votes re

ceived byeach candidate. The program should then output each candidate'sname, the number of votes recieved, and the percentage of the totalvotes received by the candidate. Your program should also outputthe winner of the election.
Computers and Technology
1 answer:
madreJ [45]2 years ago
5 0

Answer:

#include<iostream>

#include<stdlib.h>

using namespace std;

int main(){

   //initialization

   string str1[5];

   int arr_Vote[5];

   int Total_Vote=0,max1_Index;

   int max1=INT_MIN;

   //loop for storing input enter by user

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

       cout<<"Enter the last name of candidate: "<<endl;

       cin>>str1[i];

       cout<<"Enter the number of vote receive by the candidate: "<<endl;

       cin>>arr_Vote[i];

       //calculate the sum

       Total_Vote = Total_Vote + arr_Vote[i];

       //find the index of maximum vote

       if(arr_Vote[i]>max1){

           max1=arr_Vote[i];

           max1_Index=i;

       }

   }

   //display

   cout<<"\nThe output is......"<<endl;

   //loop for display data of each candidate

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

       cout<<str1[i]<<"\t"<<arr_Vote[i]<<"\t"     <<float(arr_Vote[i]*100)/Total_Vote<<"%"<<endl;

   }

   //display winner

   cout<<"The winner candidate is"<<endl;

   cout<<str1[max1_Index]<<"\t"<<arr_Vote[max1_Index]<<"\t"<<float(arr_Vote[max1_Index]*100)/Total_Vote<<" %"<<endl;

}

Explanation:

Create the main function and declare the two arrays and variables.

the first array for storing the names, so it must be a string type. second array stores the votes, so it must be int type.

after that, take a for loop and it runs for 5 times and storing the values entered by the user in the arrays.

we also calculate the sum by adding the array data one by one.

In the same loop, we also find the index of the maximum vote. take an if statement and it checks the element in the array is greater than the max1 variable. Max1 variable contains the very small value INT_MIN.

If condition true, update the max1 value and update the max1_Index value.

The above process continues for each candidate for 5 times.

After that, take a for loop and display the data along with percentage by using the formula:

Vote\,percent=\frac{Vote\,receive*100}{Total\,vote}

the, finally display the winner by using the max1_Index value.  

You might be interested in
Which statement accurately compares the restart at 1 and continue numbering featured of word
Andrews [41]

Answer: the continue numbering feature can be used to maintain the numbering order in a list and the restart at 1 feature can be used to make a new list

Explanation:

7 0
3 years ago
Read 2 more answers
Taking these steps will help to improve the delivery of your presentation.
NNADVOKAT [17]

Taking any/all of these steps will help to improve the delivery of your presentation:

<em>==> Be familiar with the place the presentation will be given.</em>

<em>==> Practice your presentation.</em>

<em>==> Move away from your computer frequently while speaking, and return to it to advance slides.</em>

<em>==> Use your conversation words and voice.  Don't read it from a paper (unless you can write in conversational words and phrases, but this is really hard to do).</em>

<em>==> Look around the audience while you're talking.  Make eye-contact with people. </em>

<em>==> Let your hands move normally while you talk.  Smile.</em>

-- Read from your slides so you don't forget your content.   ==> No. This is considered one of the signs of a poor presentation, and an inadequately prepared presenter.  

You're not there to read the slides to your audience.  They can read the slides just as well as you can.  You're there to explain, embellish, enhance, and enlarge the material on the slides.  If you don't have any more to tell them except what's on the slides, then you don't even need to drag yourself or the audience through the agony of the presentation. Just print the slides onto a handout, hand it out, dismiss the audience, and take the rest of the day off.  

Also, you're expected to know your subject well enough so that you don't need to read your slides to know what you're talking about, and to be well enough prepared to remember what comes next.

5 0
2 years ago
Read 2 more answers
A(n) _________________________ conveys a visual representation of data.
Komok [63]
I believe that the answer to fit this sentence is chart. Hope that this answer helped! ☺
3 0
3 years ago
A Google Doc automatically moves text to the next line when it reaches the right edge of the screen, is called:
DanielleElmas [232]
Word Wrap

As the name allows, the word wraps around the document once it reaches the border, thus making it the answer.

Hope this helps!
4 0
3 years ago
Read 2 more answers
A technician wants to configure the inbound port of a router to prevent FTP traffic from leaving the LAN.
Archy [21]

Answer:

The technician will want to add ACL for ports 20 and 21

Explanation:

The FTP protocol by default will attempt to use 21 for TCP access and 20 for data access.  By enabling an Access Control List (ACL) on ports 20 and 21, the technician can prevent FTP traffic from leaving the network on the default ports.

Cheers.

8 0
3 years ago
Other questions:
  • A data structure used to bind an authenticated individual to a public key is the definition of ________.
    14·1 answer
  • SecOps focuses on integrating the need for the development team to provide iterative and rapid improvements to system functional
    11·1 answer
  • How many fonts are there in a theme?<br> A. 1<br> B. 2<br> C. 4<br> D. 5
    10·1 answer
  • Google Glass uses a projector that bounces a beam of light off a prism and projects the image directly on your ________. field o
    14·1 answer
  • Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 3 4 void sho
    9·1 answer
  • Most significant effect the rotary press had on printing
    9·1 answer
  • MULTI SELECTION
    9·1 answer
  • Mattias's friend asked him to critique his presentation about gorillas. Mattias noticed that there weren't any images of gorilla
    6·1 answer
  • Which of these is a type of social engineering attack?
    10·1 answer
  • De acuerdo con las generaciones de la computación, ¿Creen que estamos en la 5ta generación o aun no? y ¿por qué?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!