Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » BeginnersRSS Feeds

Program for election contest among five candidates

Posted By: Easy Tutor     Category: C++ Programming     Views: 14222

An election is contested by five candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and counts
the votes cast for each candidates using an array variable count. In case, a number read is outside the range 1 to 5, the ballot should be considered as a 'spoilt ballot' and the program should also count
the number of spoilt ballots.

Code for Program for election contest among five candidates in C++ Programming

/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*//*An election is contested by five candidates.  The candidates arenumbered 1 to 5 and the voting is done by marking the candidate numberon the ballot paper.  Write a program to read the ballots and countsthe votes cast for each candidates using an array variable count.In case, a number read is outside the range 1 to 5, the ballot shouldbe considered as a 'spoilt ballot' and the program should also countthe number of spoilt ballots.*/

#include <iostream.h>
#include <conio.h>

intconst size=50;

class ballot
{
int    candidate;        //candidate you want to create for votingint vote[size];
int    ballot[5];
staticint spballot;            //spoil ballotpublic :
void getdisplay(void);
};

int ballot :: spballot;

void ballot :: getdisplay(void)
{
cout<<"\n\n\nEnter how many candidate you want to make:-";
cin>>candidate;

staticint a,b,c,d,e;
a=0;
a=b=c=d=e;

cout<<"\nEnter 1-5 Integers\n";
for(int i=0;i< candidate;i++)
{
    cin>>vote[i];
   switch(vote[i])
   {
    case 1:ballot[a];
            a++;
           break;
      case 2:ballot[b];
            b++;
           break;
      case 3:ballot[c];
            c++;
           break;
      case 4:ballot[d];
            d++;
           break;
      case 5:ballot[e];
            e++;
           break;
   default    : ++spballot;
   }
}

//for displayingint choice;
   do
   {
    cout<<"\n\n\n\nChoices Available\n";
      cout<<"\n1)  Scored By Ballot A\n";
      cout<<"2)  Scored By Ballot B\n";
      cout<<"3)  Scored By Ballot C\n";
      cout<<"4)  Scored By Ballot D\n";
      cout<<"5)  Scored By Ballot E\n";
      cout<<"6)  Spoilt Ballot\n";
      cout<<"7)  EXIT\n";
      cout<<"Enter Your Choice :- ";
      cin>>choice;
      switch(choice)
      {
      case 1:    cout<<"Scored By Ballot A is "<<a;
                  break;
      case 2:    cout<<"Scored By Ballot B is "<<b;
                  break;
      case 3:    cout<<"Scored By Ballot C is "<<c;
                  break;
      case 4:    cout<<"Scored By Ballot D is "<<d;
            break;
      case 5:    cout<<"Scored By Ballot E is "<<e;
                  break;
      case 6:    cout<<"Spoil Ballot were "<<spballot;
                  break;
      case 7:    goto end;
      }
   }while(1);
end:
}



void main()
{
clrscr();
ballot o1;
o1.getdisplay();
}
  
Share: 


Didn't find what you were looking for? Find more on Program for election contest among five candidates Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program for election contest among five candidates is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!