Voting System Using Classes and Methods
Voting System Using Classes and Methods
Date:
AIM:
To implement the polling mechanism using c++.
ALGORITHM:
PROGRAM:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class poll
{
int j,k,c1,c2,c3;
char name[20][20],vid[10],vot;
public:
poll()
{ j=0;c1=c2=c3=0; }
void welcome()
{
clrscr();
printf("========================================");
cout<<"\n\n ELECTION 2010"<<endl;
printf("========================================");
}
void voterdet()
{ clrscr();
cout<<"\n Welcome.."<<endl;
cout<<" Voter Name :"; cin>>name[j];
cout<<" Voter Id :"; cin>>vid[j];
j++;
}
void contestants()
{ clrscr();
printf("========================================");
cout<<"\n\t\t\t ELECTION 2010 CONTESTANTS"<<endl;
printf("========================================");
cout<<"\nNUMBER NAME REF.SIGN"<<endl;
cout<<"1055 Mr.Alfred Mann * "<<endl;
cout<<"1023 Mr.Stefen Peters $ "<<endl;
cout<<"1042 Ms.Ashely Hover # "<<endl;
}
void vote()
{ cout<<"\n Choose ur leader with the REF.SIGN:";
cin>>vot;
}
void calc()
{ if(vot=='*')
c1++;
else if(vot=='$')
c2++;
else if(vot=='#')
c3++;
else
{
cout<<"INVALID ENTRY"<<endl;
vote();
}
}
void display()
{ clrscr();
printf("========================================");
cout<<"\n\t\t\t ELECTION 2010 RESULTS"<<endl;
printf("========================================");
printf("\n\n\n\n");
cout<<"NUMBER NAME REF.SIGN VOTES"<<endl;
cout<<"1055 Mr.Alfred Mann * "<<c1<<endl;
cout<<"1023 Mr.Stefen Peters $ "<<c2<<endl;
cout<<"1042 Ms.Ashley Hover # "<<c3<<endl;
printf("\n\n\n\n\n\n\n");
if((c1>c2)&&(c1>c3))
cout<<"Mr.ALFRED MANN is the winner with "<<c1 << "votes"<<endl;
else if((c2>c1)&&(c2>c3))
cout<<"Mr.STEFEN PETERS is the winner with "<<c2<< "votes"<<endl;
else if((c3>c1)&&(c3>c2))
cout<<"Ms.ASHLEY HOVER is the winner with "<<c3<< "votes"<<endl;
}
~poll(){}
};
void main()
{
poll p1;
int n,i;
p1.welcome();
cout<< "\n No of voters:"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
p1.voterdet();
p1.contestants();
p1.vote();
p1.calc();
}
p1.display();
getch();
}
RESULT:
The polling mechanism was implemented using c++ and the output was verified.
OUTPUT:
========================================
ELECTION 2010
========================================
No of voters:
3
========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #
========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #
========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #