Sie sind auf Seite 1von 15

ELECTION

PROGRAM
REPORT
REPORT
INDEX
HEADERFILE
ALOGARITHM
CODING
REFRENCE
CONCLUSION
INTORDUCTION

 PROGRM AND REPORT ABOUT THE CLASIC ELECTION FOR


DIGITALISED ERA

ELECTION

 DONE BY USING MODERN METHOD C++


HEADER FILES

 #<iostream.h>
 #<conio.h>
 #<stdio.h>
 #<bits/stdc++.h>
ALGORITHM
1:Create an array of 5 element of type candidate.
2:Input all the entry & assign them to the candidate array.
Like for s be the input name & v be the no of
received vote for ith candidate, we assign it by-
Array[i].name=s; //members are assigned their values
Array[i].vote=v;
3:To count the total number of votes, sum all the votes received.
For i=0:4
total_vote+= array[i].vote
End for loop
4:To calculate percentage vote received for each of the candidates,
divide no of votes received by total_vote& make percentage. (Take care
of integer division, result may reflect 0, if you change the order, first multiply
with 100 or use floating calculation).
5:For figure out the winner
Set max= INT_MIN, count=0;
for i=0:4
Find the max vote received by any candidate in the election
End for loop

For i=0:4
if no of received vote for i th candidate==max
Store i
Increase count // no of winner candidate

Print the name(s) of winner(s) using the stored indexes.


 #include <bits/stdc++.h>
 using namespace std;

 class candidate{
CODING
 public:
 string name;
 int vote;
 };

 void outputElection(candidate* arr){


 int total_vote=0;
 for(int i=0;i<5;i++){
 //finding total no of votes
 total_vote=total_vote+arr[i].vote;
 }
cout<<"result of the election............."<<endl;
cout<<"name of candidate"<<"\t"<<"vote
received"<<"\t"<<"percentage"<<endl;
for(int i=0;i<5;i++){
cout<<arr[i].name<<"\t\t\t";
cout<<arr[i].vote<<"\t\t";
cout<<(arr[i].vote*100)/total_vote<<"%"<<endl;
}

int max=INT_MIN,count=0;
int index[5]={0};

for(int i=0;i<5;i++){
if(arr[i].vote>max){
max=arr[i].vote;
}
}
 for(int i=0;i<5;i++){
 if(arr[i].vote==max){
 index[count]=i;
 count++;
 }
 }

 if(count==1)
 cout<<"The winner is "<<arr[index[count-1]].name<<endl;
 else{
 cout<<"There is tie between:"<<endl;
 for(int i=0;i<count-1;i++)
 cout<<arr[index[i]].name<<", ";
 cout<<arr[index[count-1]].name<<endl;
 cout<<"all are winner\n";
 }
 return ;
 }
 int main(){
 string s;
 int v;
 candidate arr[5];
 cout<<"enter candidates last name, there are five candidates\n";
 for(int i=0;i<5;i++){
 cout<<"enter candidate "<<i<<" last name\n";
 cin>>s;
 arr[i].name=s;
 cout<<"enter no of votes received by candidate "<<i<<endl;
 cin>>v;
 arr[i].vote=v;
 }
 outputElection(arr);
 return 0;
 }
CONCLUSION

THEPROGRAM IS RUNNING
SUCCESFULLY
OUTPUT
 enter candidates last name, there are five candidates
 enter candidate 0 last name
 ASHWIN
 enter no of votes received by candidate 0
 30
 enter candidate 1 last name
 AKASH
 enter no of votes received by candidate 1
 20
 enter candidate 2 last name
 SHARAN
 enter no of votes received by candidate 2
 40
 enter candidate 3 last name
HARISSH
enter no of votes received by candidate 3
60
enter candidate 4 last name
RAM
enter no of votes received by candidate 4
10
result of the election.............
name of candidate vote received percentage
ASHWIN 30 18%
AKASH 20 12%
SHARAN 40 25%
HARISSH 60 37%
RAM 10 6%
The winner is HARISSH
REFERNCE

 WWW.includehelp.com
 CLASS TEXTBOOK(COMPUTER SCIENCE WITH SUMITA ARORA)
THANK YOU

DONE BY
 HARISSH
 SHARAN
 AKASH
 ASHWIN

Das könnte Ihnen auch gefallen