0% found this document useful (0 votes)
223 views

Voting System Using Classes and Methods

1) The document describes an algorithm to implement a polling mechanism using C++ classes and methods. 2) It reads the number of voters, displays candidate names and symbols, calculates votes for each candidate, and declares the winner with the most votes. 3) The output shows the program tracking 3 voters, tallying 3 votes for Ms. Ashley Hover, and correctly declaring her as the winner.

Uploaded by

nandinambi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
223 views

Voting System Using Classes and Methods

1) The document describes an algorithm to implement a polling mechanism using C++ classes and methods. 2) It reads the number of voters, displays candidate names and symbols, calculates votes for each candidate, and declares the winner with the most votes. 3) The output shows the program tracking 3 voters, tallying 3 votes for Ms. Ashley Hover, and correctly declaring her as the winner.

Uploaded by

nandinambi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Ex No: VOTING SYSTEM USING CLASSES AND METHODS

Date:

AIM:
To implement the polling mechanism using c++.

ALGORITHM:

Step 1: Read the number of voters.


Step 2: Display the contestant’s names and their referencing symbol.
Step 3: calc () function is used to calculate the number of votes for each contestant.
Step 4: The contestant with maximum number of votes count is declared as winner.
Step 5: Display the result
Step 6: Stop the process.

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

Voter Name: Nithya


Voter Id :1

========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #

Choose ur leader with the corresponding REF.SIGN: #

Voter Name: Janani


Voter Id :2

========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #

Choose ur leader with the corresponding REF.SIGN: #

Voter Name: Dhivya


Voter Id :3

========================================
ELECTION 2010 CONTESTANTS
========================================
NUMBER NAME REF.SIGN
1055 Mr.Alfred Mann *
1023 Mr.Stefen Peters $
1042 Ms.Ashely Hover #

Choose ur leader with the corresponding REF.SIGN: #


========================================
ELECTION 2010 RESULTS
========================================
NUMBER NAME REF.SIGN VOTES
1055 Mr.Alfred Mann * 0
1023 Mr.Stefen Peters $ 0
1042 Ms.Ashely Hover # 3

Ms. Ashley Hover is the winner with 3 votes.

You might also like