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
What is the main function of an operating system​
alina1380 [7]

Here are the main functions of an operating system:

1) Manage the resources of the device

The operating system controls how much of each resource is distributed, and it controls things like the processing unit and memory.

2) Establish a interface for the user of the device

The operating system must classify what the classes of the script/code have to do and what they implement.

3) Service application software

The operating system must service each application that is downloaded onto the device. It must balance it's use of storage between apps.

4 0
3 years ago
Everyone interacts with various information systems every day: at the grocery store, at work, at school, even in our cars. Make
Alex73 [517]

Answer:

- RFID tags in shopping mall.

- Browsing the internet.

- Mobile phone calls

Explanation:

Radio frequency identification tag (RFID) in a device that holds personal information of a user electromagnetically. it is used in shopping mall, installed in the shopper's phone or a card, in which all payments are done automatically.

The internet is a global network of devices. With a subscription to a internet service provider, a user can surf the internet at any time of the day.

Mobile phones are portable devices, procured by a user for on-the-go calls. This cell phones have databases with information of cell tower connections, for easy switching for flexible but quality call adaptation.

5 0
3 years ago
What are the purpose of Keyframes,
Kobotan [32]

Answer:

In media production, a key frame or keyframe is a location on a timeline which marks the beginning or end of a transition. It holds special information that defines where a transition should start or stop. The intermediate frames are interpolated over time between those definitions to create the illusion of motion.

Explanation:

7 0
3 years ago
Where is Peru located?
Illusion [34]
B. South America

[ignore:20 CHARACTERS]
4 0
3 years ago
AUPs ensure that an organization’s network and internet are not abused. Select 3 options that describe AUPs.
tigry1 [53]

AUPs often involves not going onto unauthorized sites or downloading certain content, not using the service to violate any law, and not connecting to unauthorized devices through the network.

<h3>What is AUP?</h3>

AUP stands for Acceptable Use Policy, which refers to a policy that regulates users when they access a corporate newtork.

<h3>How does an AUP regulates users?</h3>

Most AUPs imply:

  • Users can only access certain sites and dowloading specific content is forbidden.
  • The access to the internet or network cannot be used for criminal purposes.
  • Only authorized users can connect to the corporate network.

Learn more about AUP in: brainly.com/question/9509517

#SPJ1

8 0
2 years ago
Other questions:
  • Jail and prison officials may generally limit inmate rights when the limitations serve
    13·2 answers
  • What’s the answer?............................
    13·1 answer
  • How should a cover letter begin?
    13·2 answers
  • You are responsible for performing all routine maintenance on your company's laser printers. Which of the following maintenance
    15·1 answer
  • What operating system is an open source program
    15·1 answer
  • Amy uses digital devices to listen to music and to watch movies. Which one of these is Mbps a measure of?
    12·1 answer
  • To have a reason or purpose to do something
    8·2 answers
  • The Internet was first used by which of the following institutions?
    7·1 answer
  • What can you say about the different website that you used? do they have in common?​
    8·1 answer
  • Which is an example of a demand account
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!