You are on page 1of 6

Result display module: Functions: Display overall result 3. Coding: a. Coding for candidate: #include<stdio.h> #include<conio.h> #include<string.

h> char cadname[80][10]; int cadcount[10]; int nocad; void getcandidatedetails() { int i; printf("\t\tEnter the number of the candidates(1-10):"); scanf("%d",&nocad); if(nocad>10) { printf("\n\t\tNumber of candidate should not exceed 10"); exit(0); } for(i=0;i<nocad;i++) { printf("\n\t\tEnter the %d name:",i+1); scanf("%s",cadname[i]); cadcount[i]=0; } } void displaycandidatedetails() { int i; int winner=0; int listOfwinners[10]; int noOfWinners=0; printf("\n\t\tCandidate details:\n"); for(i=0;i<nocad;i++) { printf("\t\n%s\t%d",cadname[i],cadcount[i]); if(cadcount[i]>winner) { winner=cadcount[i];

} } for(i=0;i<nocad;i++) { if(cadcount[i]==winner) { listOfwinners[noOfWinners]=i; noOfWinners++; } } if(noOfWinners==1) printf("\n\n\t\tTHE WINNER IS %s",cadname[listOfwinners[0]]); else { printf("\n\nThe poll is a draw.List of winners\n"); for(i=0;i<noOfWinners;i++) { printf("%s-",cadname[listOfwinners[i]]); } } } void displaycandidatelist() { int i; printf("\nCandidate list:\n"); for(i=0;i<nocad;i++) { printf("\t\n%s",cadname[i]); } } void updatecandidatecount(int j) { cadcount[j]=cadcount[j]+1; } b. Coding for election module: #include<stdio.h> #include<conio.h> #include<string.h> #define LINE printf("\n--------------------------------------"); char elcname[100][100]; void getelectiondetails()

{ printf("\nEnter the election detail(name witout space):"); scanf("%s",elcname); } void displayelectiondetails() { printf("\n\nElection Details:%s election",elcname); } c. Coding for voters: #include<stdio.h> #include<conio.h> #include<string.h> int alreadyvoted[100]; char votername[80][100]; int novoter; int getnovoters() { return novoter; } void getvoterdetails() { int i; printf("\n\t\tEnter the number of voters(1-100):"); scanf("%d",&novoter); if(novoter>100) { printf("\n\t\tNumber of voters should not exceed 100:"); exit(0); } for(i=0;i<novoter;i++) { printf("\n\t\tEnter %d voter name:",i+1); scanf("%s",votername[i]); alreadyvoted[i]=0; } } int validatevoter(char tmpname[80]) { int i; for(i=0;i<novoter;i++) { if(strcmp(votername[i],tmpname)==0) { if(alreadyvoted[i]==1)

{ printf("\t\tYou have already voted"); return 0; } else { alreadyvoted[i]=1; return 1; } } } printf("\t\t\nYour name is not in the list"); return 0; } void displayvoterdetails() { int i; printf("\n\t\tVoter list:\n"); for(i=0;i<novoter;i++) { printf("\t\n\n%s",votername[i]); } } d. Coding for voting engine: #include<stdio.h> #include<conio.h> #include"election.c" #include"candidat.c" #include"voter.c" #include<string.h> #define LINE printf("\n---------------------------------------"); char password[80]; int votersdone=0; void getuservote() { char tempname[80]; int tempint; printf("\nLogin Voter(Enter your name in lower case):"); scanf("%s",tempname); if(validatevoter(tempname)==0) {

return; } else { votersdone++; displaycandidatelist(); printf("\n\nSelect your candidate(Enter 1,2,...):"); scanf("%d",&tempint); updatecandidatecount(tempint-1); } } void main() { int j,a=0; clrscr(); LINE printf("\nVoting Administrator Login"); LINE for(j=0;j<3;j++) { printf("\n\nEnter your password:"); scanf("%s",password); if(strcmp(password,"administrator")!=0) { printf("\n\n****Wrong Password****"); } else { a=1; break; } } if(a==0) { return; } getelectiondetails(); getcandidatedetails(); getvoterdetails(); clrscr(); while(votersdone<getnovoters()) { getuservote(); } printf("\t\tPolling complete"); LINE

printf("\n\t\t\aELECTION RESULT"); displayelectiondetails(); LINE displaycandidatedetails(); LINE getch(); }

You might also like