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]
3 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]3 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
Danielle is analyzing logs and baselines of the systems and services that she is responsible for in her organization. She wants
GalinKa [24]

Answer:

b. Machine learning

Explanation:

The technique that is being described in this situation is known as Machine Learning. This is a fairly new technology that has become popular over the last decade. Machine learning uses artificial intelligence to analyze data and learn from it. Every time the system analyzes the data it learns something new, saves it, and implements it to its processes. Therefore, the more times it repeats the more it learns. These systems are continuously getting better and learning more, which makes them incredibly efficient.

5 0
3 years ago
What can you search on Microsoft Word or Powerpoint Clipart or Google (Clip art) to find more pictures like the ones below but w
elena-14-01-66 [18.8K]
Well if you put sad/mad/scared/tired/ect it should pop up with the same person.
3 0
3 years ago
Who can pick up GPS signals
bazaltina [42]

Devices such as TomTom GPS and Garmin GPS pick up a GPS signal


I hope that's help !

5 0
3 years ago
On the Audio Tools contextual tab, which tab will control how the audio file appears, if it appears, on the slide itself?
dexar [7]

Answer:

B.

Explanation:

3 0
3 years ago
Read 2 more answers
(tco 5) how many 4-bit parallel adders are required to add the numbers 5,345 and 3,892? explain how you got your answer.
Igoryamba
The sum is 9237. To express this as binary requires log(9237)/log(2) bits ≈ 13.2 bits, rounded up at least 14 bits. (You can check: 2^13 is not enough, 2^14 is enough)

So you need four 4-bit adders, giving you 16 bits resolution.
7 0
3 years ago
Other questions:
  • What is transmission control protocol?
    7·1 answer
  • Write a program that assigns two integer values from standard input to the variables int1 and int2, then prints "true" if they a
    10·1 answer
  • Which sentences in the passage correctly describe a function?
    11·1 answer
  • Why is Apple using social media ?
    15·1 answer
  • The length property of the String object returns
    15·1 answer
  • Sorry but, what are brainliest for?
    7·2 answers
  • Gabriel's sister called him about a message that suddenly appeared on her screen that says her software license has expired and
    11·1 answer
  • Lab 6B: printing a binary number
    13·1 answer
  • What does getfenv() do?
    11·2 answers
  • Why does my messenger say this person is unavailable on messenger.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!