Sie sind auf Seite 1von 114

Electronic Voting Management [EVM]

Project report
Title of the Project

Electronic
Electronic Voting Management
[EVM]
Introduction

Election process is very cumbersome process which in modern age seems to

be very difficult job without use of computer. In past, during election time,

the District election officer used to depute all typists from various

departments to his office for carrying out the work of typing the

appointment orders, polling station lists and other election related

documents. Imagine if some correction is to be made in the appointment

order or in some polling list, the updation was almost impossible under

these conditions.

Thanks to the modern technology with the invention of computers, all this

work can be managed by a single person far efficiently than a hundreds of

typists could not do with satisfaction. These days, the polling station list

required to be fed only once and numerous reports can be generated

without any efforts. Again, deploying staff for polling duty or counting duty

is achieved with press of one key.

Page 1 of 114
Electronic Voting Management [EVM]

With the evolution of internet, the transmission of data has become very fast

and efficient. We have observed for last few years the election analysis

programs. During the counting process, one can know the overall party-wise

position in a state or throughout the country within no time.

Keeping in view these difficulties, we have developed this software namely

“COMPUTERIZED VOTING SYSTEM”.

EIS is a project designed in Turboc C++ Compiler using data files.

Project Category

This project comes under Object Oriented Programming (OOPs) category.

The fundamental idea behind using Object Oriented Language (i.e. C++) is to

combine into a single unit both data and the methods that operate on that

data. Moreover, the concept of data hiding and stacks in C++ makes it more

suitable for this project work. As in this project, in order for the existence of

Bank Management System there is need to implement it using the concept

of Procedural or Object Oriented Languages. Above all the only way to make

the data accessible by their respective functions or modules is by

implementing the concept of classes and objects making the data hidden, so

that it is safe from accidental alteration and provides the security features.

Page 2 of 114
Electronic Voting Management [EVM]

Function used in this Project

Function Name Description


Lineh To Draw A Horizontal Line(x1,x2,y)
Linev To Draw A Vertical Line(y1,y2,x)
Box to draw a box(x1,y1,x2,y2)
vertical_menu To Make Vertical Menu
horizontal_menu To Make Horizontal Menu.
Help To printf the help screen for various important
operations
PRINT To read the characters on the screen & save it to a
temp variable and then send it to the printer
Statusbar To make the status bar at prefixed coordinates at
the bottom of the screen.
Getlinedelchar To delete a character for getline
Getline To add online editing for inputing a line
Mscreen To paint the screen with the THE OPENING
SCREEN.
Main Draw main menu & call related functions
Fcode To return 0 if the given code is not found
display_voter To display a record from "voter.dat"
add_voter To get data about new voter
modify_voter To provide with necessary data required for
modification of a given record
del_voter To Delete A Record in "voter.dat"
displaycode_voter To Obtain Code For Displaying a Record
showlist_voter To Display The List of the voter
Display To display a record from "candidate.dat"

Page 3 of 114
Electronic Voting Management [EVM]

Function Name Description


Add To get data about new candidate
Modify To provide with necessary data required for
modification of a given record
del To Delete A Record in "candidate.dat"
displaycode1 To Obtain Code For Displaying a Record
showlist1 To Display The List of the voter
Vote To Check Whether or not the voter casted the vote
and increment the total votes for the casted
candidate
Showlistf To Display The List of Voters Together with the total
voters
Final To Display The Winner in the election

System Analysis

The System Analysis Phase is considered as one of the most important


phases in the system development life cycle (SDLC). It is extremely
important that the developer should undergo system study of the existing
system thoroughly because otherwise it is impossible to build the system
that will satisfy the needs of the user. This study enables the developer to
light so that he may know exactly what not to do while building the
candidate system.

Requirement Analysis must be done to understand the problem that the


software system is to solve e.g. the problem could be automating an existing
manual system or developing a completely new automated system or a

Page 4 of 114
Electronic Voting Management [EVM]

combination of the two. For a large system, having a large number of


features as there has the need to perform many different tasks. The
emphasis in requirement analysis is to identify what are the needs of the
system and not how the system achieves or gets its goal.

The developer usually does not understand the issues involved in software
systems, this causes a communication gap that needs bridging adequately
during this analysis.

Feasibility Study

All projects are feasible if given unlimited resources and infinite time!
Unfortunately, the development of a computer based system or project is
likely to be plagued by scarcity of resources and difficult delivery dates. It is
both necessary and prudent to evaluate the feasibility of a project at the
earliest. Months or years of efforts, thousands or millions of dollars, and
untold professional embarrassment can be averted if defective system is
recognized early in the definition phase.

Feasibility and risk analysis are related in many ways. If project risk is
much the feasibility of producing quality software is reduced. During
product engineering, however, we concentrate our attention on four primary
areas of interest.

Economic Feasibility
An evaluation development cost weighed against the ultimate income or
benefit derived from the developed system or product. Overheads regarding
routine activities (i.e. Paper Work, various types of diaries/Organizers etc)
are reduced by maintaining all contact details on the computer.

Page 5 of 114
Electronic Voting Management [EVM]

Technical Feasibility

A study of function, performance and constraints that can affect the ability to achieve an
acceptable system. The system developed provides fast, accurate, reliable and interactive
mode of executing a transaction.

Operational Feasibility
It tells about the handling of the software by the user of the system for the
routine activities

Legal Feasibility
A determination of infringement, violation or liability that can result from
development of the system. A project designed does not violate any rule as
specified for this activity.

Tools, Platform and Languages

Software Requirement
Operating System Windows 95,98 or higher versions of Windows

Application used Turbo C++

Hardware Requirement
Hard Disk 10 GB or Higher

Compact Disk 700 MB

Mouse Serial or USB

RAM 64 MB or higher

Page 6 of 114
Electronic Voting Management [EVM]

Processor Pentium-I or higher

Monitor 14 inch Colored or VGA

Others Speakers, CD-ROM etc

Quality Assurance and Testing

Software quality assurance is a check to prove that the program works as

expected. Testing should locate any previously undetected errors that might

hamper the smooth functioning of the system. In this phase we try to make

the system fail and then continue testing till we cannot deliberately make

the system fail anymore.

Debugging

If defects are there in the system, they must be located and removed. This

process is called Debugging. Defects in the code must be located and the

program modified to meet its requirement. Testing must be repeated to

ensure that the change has been made correctly.

Page 7 of 114
Electronic Voting Management [EVM]

The following diagram makes understand the process of


debugging:

Locate Design Repair Re-test


error error error error

The Debugging process

Model of Debugging Process

Testing Process

• System should be build of sub-systems that are build out of modules,

which are composed of procedures and functions. The testing

proceeds in stages where it is carried out incrementally in conjunction

with the system implementation.

• The most widely used testing process consists of five stages illustrated

in the figure below:

Page 8 of 114
Electronic Voting Management [EVM]

Unit
Testing

Module
Testing

Subsystem
Testing

System
Testing

Acceptance
Testing

MODEL OF TESTING PROCESS

Testing and Safe Aspects

In order to assure quality of the project in accordance with the plan,

following Software Quality measures are to be taken:

• Formal Technical Reviews

• Individual Reports

• Regular Brainstorming Sessions

Page 9 of 114
Electronic Voting Management [EVM]

• Peer Reviews

• Coding Standard

• Structural multilevel testing

Testing

No program or system design is perfect. Communication between the user

and the designer is not always complete or clear. Time is usually short. The

result is errors and more errors. The number and native of errors in a new

design depends on several factors:

 Communication between the user and designer.

 The programmer’s ability to generate a code that reflects exactly the


system specifications.

 The time frame of the design.

Theoretically, a newly designed system should have all the pieces in working
order. But in reality, each piece works independently. The purpose of
system testing is to consider all the likely variations to which it will be
subjected and then push the system to its limits. It is very tedious but
necessary in system development.

Types of Testing Process

• Unit testing is testing changes made in an existing or new program.

• Sequential or series testing is checking the logic of one or more


programs in the candidate system, where the output of one will affect
the processing done by another program.

Page 10 of 114
Electronic Voting Management [EVM]

• System testing is executing a program to check logic changes made


in it and with the intention of finding errors (making the program
fail). Effective testing does not guarantee reliability. Reliability is a
design consideration.

• Positive testing is making sure that the new program, in fact,


processes certain transactions according to specifications

• Acceptance testing is running the system with live data.

Testing is a process of executing program with the intention of uncovering


errors in it. Though testing cannot show absence of errors but by showing
their presence, it is considered that these are not present or at least have
been minimized a lot.

The following considerations that were taken for testing the modules:

• Preplanning of testing and test case design.

• Conformance of requirements.

• Gradual and incremental representations of test cases for the whole


domain.

Implementation

An important aspect of system analyst’s job is to make sure that the new

design implementation meets the standard. The term implementation has

different meanings, ranging from conversion of basic applications to

complete replacement of computer systems. The procedure however is

Page 11 of 114
Electronic Voting Management [EVM]

virtually the same. Implementation here means the process of converting a

new or a revised system design into an operational one. Conversion is one

aspect of implementation. The other aspects are post implementation and

software maintenance.

Types of Implementation

• Implementation of computer system to replace manual system. The

problem encountered is converting files, training users, creating

accurate files and verifying printouts for integrity.

• Implementation of a computer system to replace an existing one. This


is usually a difficult one. If not properly planned, there can be many
problems. Some large computer systems have taken as long as a year
to convert.

• Implementation of modified application to replace an existing one.

Using the same computer, this type of conversion is relatively easy to

handle, provided there are no major changes in the files.

Software Maintenance

Maintenance is enigma of system development. It holds the software

industry captive, typing up the programming resources. Analyst’s and

programmers spend far more time in maintaining the program than they do

writing them. Maintenance accounts for 50-80 % of total system

development. The federal government alone spends more than $1.3 billion a

Page 12 of 114
Electronic Voting Management [EVM]

year on software maintenance. Whereas the cost of hardware has steadily

declined, the cost of producing programs has skyrocketed, e.g., Ten years

ago the development cost of a department of defense (DOD) project averaged

$ 75 per line of programming instructions, whereas maintenance cost ran

as high as $ 4,000 per line.

This problem occurs across industry largely because software is a

handmade product designed in an ad hoc fashion with few standards; it

comes out late, is purely documented, and therefore is difficult to maintain.

Problems in Maintenance

• Maintenance is not as rewarding and exciting as developing systems.


It is perceived as requiring neither skill nor experience.
• Users are not fully cognizant of the maintenance problem or its high
cost.
• Few tools and techniques are available for maintenance.
• A good test plan is lacking.
• Standards, procedures and guidelines are purely defined and
enforced.
• Maintenance is viewed as a necessary evil, often delegated to junior
programmers. There is practically no maintenance manager’s job
classification in MTS field.
• Programs are often maintained without care, for structure and
documentation.
• There are minimal standards for maintenance.

Page 13 of 114
Electronic Voting Management [EVM]

• Programmers anticipate that they will not be in their current


commitment by the time their program goes into the maintenance
cycle.

Most programmers view maintenance as low-level drudgery. After they


develop an application, they spent years locked in maintaining it.
Eventually, boredom sets in, with subsequent turn over and loss of
expertise necessary to maintain the system. It is obvious that the more
carefully the system is thought out and developed, with attention paid to
external influence over a reasonable lifetime, the less maintenance will be
required.

Page 14 of 114
Electronic Voting Management [EVM]

Primary Activities of

Maintenance Procedure

Request 1
for
System

Request System Results for Submit test for


System and Program User User Approval
Program Documentation
Documentation

Specify Return Modified


Required Modifications Documentation
Modification Requirements To library

Acquire Source Source Notify User of


Program Statement Program Project
Printout from Library Statement Completion
Printout

Make Required Project


Changes to Program Completion
And Systems Notice

Test changes 1

Page 15 of 114
Electronic Voting Management [EVM]

Output Design

Outputs

Login Screen

Main Screen

1. Press 1 For Voters

2. Press 2 For Candidates

3. Press 3 For Start Voting

4. Exit

Enter Your Choice:

Page 16 of 114
Electronic Voting Management [EVM]

Main Screen for Voters

file edit print help exit

────────────┐
│newvoter │ ─────────────┐ ┌─────────┐
│displayinfo │ │modifyvoter │ │to main │
│displaylist │ │deletevoter │ │quit │
│return │ │return │ │return │
└─────────────┘ └─────────┘
└────────────┘

Main Screen for Candidates

file edit print help exit

────────────┐
│newcanidate│ ─────────────┐ ┌─────────┐
│displayinfo │ │modifycandidate │ │to main │
│displaylist │ │deletecandidate │ │quit │
│return │ │return │ │return │
└─────────────┘ └─────────┘
└────────────┘

Page 17 of 114
Electronic Voting Management [EVM]

ADDITION OF NEW VOTER

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
VOTER CODE # 4
~~~~~~~~~~~~~~~~~~~~~~

NAME : ...AMIT ....... SEX(m/f) m

ADDRESS : ...JAMMU.......... CITY : JAMMU

PIN CODE : ...180002 ....... PHONE NO. : 255468

AGE : ...19

───────────────────────────────────────────────────
DO YOU WISH TO SAVE [Y/N]

Page 18 of 114
Electronic Voting Management [EVM]

MODIFICATION OF VOTER RECORD <0>=EXIT


VOTER CODE #4

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
≡≡≡≡≡≡≡≡

name :Mr AMIT

address :Jammu -180002

contact no. :468

age :19

vote done :Y

ADDITION OF NEW CANDIDATE


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
CANDIDATE CODE # 4
~~~~~~~~~~~~~~~~~~~~~~

NAME : ...ARUN....... SEX(m/f) m

ADDRESS : ...JAMMU.......... CITY : JAMMU

PIN CODE : ...180002 ....... PHONE NO. : 255468

AGE : ...19

────────────────────────────────────────────────────
DO YOU WISH TO SAVE [Y/N]

Page 19 of 114
Electronic Voting Management [EVM]

MODIFICATION OF CANDIDATE RECORD <0>=EXIT


CANDIDATE R CODE #4

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

name :Mr ARUN

address :Jammu -180002

contact no. :468

age :19

vote done :Y

START VOTING SCREEN

LIST VOTE PRINT HELP EXIT

┌───────────────┐
│List of candidate │ ┌──────────────┐
│Winner │ │modify voter │
│return │ │return │
└──────────────┘ └──────────────┘

Page 20 of 114
Electronic Voting Management [EVM]

WINNER SCREEN:
3

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

WINNER IS...

CODE :1

NAME :RISHI

WIN BY :3votes
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

LIST OF CANDIDATES SCREEN AS ON 12.11.2008


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
║ CODE# ║ NAME TOTAL
║══════║════════════ ║════════║
║1 ║ RISHI ║3 ║
║2 ║ amit ║1 ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
press any key to continue....

Page 21 of 114
Electronic Voting Management [EVM]

Help Screen

About Electronic Voting System

This is a menu driven voting system for candidates and voters

1. Important instructions are displayed at the status bar at the


bottom of the screen.

2. Press escape key to exit the immediate screen at any time


during the program

file edit print help exit

────────────┐
│newvoter │ ─────────────┐ ┌─────────┐
│displayinfo │ │modifyvoter │ │to main │
│displaylist │ │deletevoter │ │quit │
│return │ │return │ │return │
└─────────────┘ └─────────┘
└────────────┘

Page 22 of 114
Electronic Voting Management [EVM]

Coding

#include<conio.h>
#include<string.h>
#include<stdio.h>
# include<dos.h>
#include<dir.h>
#include<stdlib.h>
#include<graphics.h>
#include<ctype.h>
void getlinedelchar(char*,int,int,int*);//delete char
void getline(char*,int);
void vmain(void); //voter menu
void cmain(void); //condiate menu
void fmain(void); //voting menu

//**************************************************************
********
//THE DRAWING FUNCTION & THE MAIN SCREEN.

//**************************************************************
********
void lineh(int,int,int,char);
void linev(int,int,int,char);
void graphics();
void statusbar(char[]);

//**************************************************************
********
//FUNCTION:lineh
//DESCRIPTION:To Draw A Horizontal Line(x1,x2,y)

Page 23 of 114
Electronic Voting Management [EVM]

//**************************************************************
********
void lineh(int row1,int row2,int column,char c)
{
for (row1;row1<=row2;row1++)
{
gotoxy(row1,column);
printf("%c",c);
}
}

//**************************************************************
********
//FUNCTION:linev
//DESCRIPTION:To Draw A Vertical Line(y1,y2,x)

//**************************************************************
********
void linev(int column1,int column2,int row,char c)
{
for(column1;column1<=column2;column1++)
{
gotoxy(row,column1);
printf("%c",c);
}
}

//**************************************************************
********
//FUNCTION:box
//DESCRIPTION:to draw a box(x1,y1,x2,y2)

Page 24 of 114
Electronic Voting Management [EVM]

//**************************************************************
********
void box(int row1,int column1,int row2,int column2,char c)
{
char ch=218;
char c1,c2,c3,c4;
char l1=196,l2=179;
if(c==ch)
{
c1=218;
c2=191;
c3=192;
c4=217;
l1=196;
l2=179;
}
else
{
c1=c;
c2=c;
c3=c;
c4=c;
l1=c;
l2=c;
}
gotoxy(row1,column1);
printf("%c",c1);
gotoxy(row2,column1);
printf("%c",c2);
gotoxy(row1,column2);
printf("%c",c3);

Page 25 of 114
Electronic Voting Management [EVM]

gotoxy(row2,column2);
printf("%c",c4);
row1++;
row2--;
lineh(row1,row2,column1,l1);
lineh(row1,row2,column2,l1);
row1--;
row2++;
column1++;
column2--;
linev(column1,column2,row1,l2);
linev(column1,column2,row2,l2);
}

//**************************************************************
********
//FUNCTION:vertical_menu
//DESCRIPTION:To Make Vertical Menu.

//**************************************************************
********
int vertical_menu(char menu[][20],int present,int end,int x,int y)
{
int ex=0;
int i;
char ch;
box(x+9,y,x+strlen(menu[0])+12,y+end,218);
for(i=0;i<end-1;i++)
{
gotoxy(x+10,y+i+1);
printf("%s",menu[i]);
}

Page 26 of 114
Electronic Voting Management [EVM]

do
{
int tpresent=present;
textcolor(BLACK);
textbackground(WHITE);
gotoxy(x+10,y+present);
cprintf(menu[present-1]);
textcolor(WHITE);
textbackground(BLACK);
ch=getch();
switch(ch)
{
case 75:if(present==1)
present=end-1;
else
present--;
break;
case 77:if(present==end-1)
present=1;
else
present++;
break;
case 71:present=1;
break;
case 79:present=end;
break;
case 72:if(present==1)
present=end-1;
else
present--;
break;
case 80:if(present==end-1)

Page 27 of 114
Electronic Voting Management [EVM]

present=1;
else
present++;
break;
case 13:ex=1;
break;
case 27:present=end;
ex=1;
}
gotoxy(x+10,y+tpresent);
cprintf(menu[tpresent-1]);
}while(!ex);
return(present);
}

//**************************************************************
********
//CLASS:menu
//FUNCTION:horizontal_menu
//DESCRIPTION:To Make Horizontal Menu.

//**************************************************************
********
int horizontal_menu(char menu[][20],int present,int end,int x,int y)
{
int ex=0,i;
char ch;
for(i=0;i<end-1;i++)
{
gotoxy(x+(i+2)*10-5,y);
printf("%s",menu[i]);
}

Page 28 of 114
Electronic Voting Management [EVM]

lineh(1,80,2,205);
do
{
int tpresent=present;
textcolor(BLACK);
textbackground(WHITE);
gotoxy(x+(present+1)*10-5,y);
cprintf(menu[present-1]);
textcolor(WHITE);
textbackground(BLACK);
ch=getch();
switch(ch)
{
case 71:present=1;
break;
case 79:present=end;
break;
case 75:
if(present==1)
present=end-1;
else
present--;
break;
case 77:if(present==end-1)
present=1;
else
present++;
break;
case 72:if(present==1)
present=end-1;
else
present--;

Page 29 of 114
Electronic Voting Management [EVM]

break;
case 80:if(present==end-1)
present=1;
else
present++;
break;
case 13:ex=1;
break;
case 27:present=end;
ex=1;
}
gotoxy(x+(tpresent+1)*10-5,y);
cprintf(menu[tpresent-1]);
}while(!ex);
return(present);
}

//**************************************************************
********
//FUNCTION : help
//DESCRIPTION : to printf the help screen for various important operations
//**************************************************************
********

void help()
{
clrscr();
printf("\n\n\n\t\t\tAbout Electronic Voting System");
printf("\n\nThis is a menu driven voting system for candidates and voters");

Page 30 of 114
Electronic Voting Management [EVM]

printf("\n\n\n1)Important instructions are displayed at the status bar at");


printf(" the \n bottom of the screen.");
printf("\n\n2)Press escape key to exit the immediate screen at any time");
printf("\n during the program");
getch();
clrscr();
return;
}

//**************************************************************
********
//FUNCTION : PRINT
//DESCRIPTION :TO READ THE CHARACTERS ON THE SCREEN & SAVE IT
//TO A TEMP VARIABLE AND THEN SEND IT TO THE PRINTER
//**************************************************************
********

void print(int x1,int y1,int x2,int y2)


{
const SEGMENT=0xB800;
unsigned norow=y2-y1+1,nocol=x2-x1+1;
unsigned i=0,noele=norow*nocol,*ptr;
unsigned row ,col,offset;
unsigned char ch;
int count=0;
FILE *prn;
prn=fopen("PRN","w");
ptr=((unsigned*)malloc(noele));
statusbar("PRINTING PRINTING PRINTING PRINTING PRINTING PRINTING
PRINTING PRINTING PRINTING");
for(row=y1;row<=y2;row++)
{

Page 31 of 114
Electronic Voting Management [EVM]

for(col=x1;col<=x2;col++)
{
offset=2*col+160*row-162;
ptr[i++]=peek(SEGMENT,offset);
}
}
for(i=0;i<noele;i++,count++)
{
ch=ptr[i]%256;
putc(ch,prn);
if(count==80)
{
fputs("\n",prn);
count=0;
}
}
fclose(prn);
}

//**************************************************************
********
//FUNCTION : statusbar
//DESCRIPTION : To make the status bar at prefixed coordinates
// at the bottom of the screen.
//**************************************************************
********

void statusbar(char m[])


{
_setcursortype(_NOCURSOR);
window(1,24,80,25);
textcolor(BLACK);

Page 32 of 114
Electronic Voting Management [EVM]

textbackground(WHITE);
cprintf(m);
clreol();
window(1,1,80,24);
textcolor(WHITE);
textbackground(BLACK);
}

//**************************************************************
********
//FUNCTION : getlinedelchar
//DESCRIPTION : To delete a character for getline
//**************************************************************
********

void getlinedelchar(char *s,int col,int p,int *len)


{
int i;
for(i=p;i<*len;i++)
s[i-1]=s[i];
gotoxy(col+p-1,wherey());
len--;
for(i=p;i<*len;i++)
printf("%s",s[i]);
printf(".");
}

//**************************************************************
********
//FUNCTION : getline
//DESCRIPTION : To add online editing for inputing a line

Page 33 of 114
Electronic Voting Management [EVM]

//**************************************************************
********

void getline(char *s,int limit)


{
int i,curx,done,col;
col=wherex();
for(i=0;i<limit;i++)
printf(".");
gotoxy(col,wherey());
done=0;
curx=0;
i=0;
do
{
char ch=getch();
ch=tolower(ch);
switch(ch)
{
case 0:
ch =getch();
switch(ch);
{
case 75:if(curx>0)
{
curx--;
gotoxy(wherex()-1,wherey());
}
break;
case 77:if(curx<i)
{
curx++;

Page 34 of 114
Electronic Voting Management [EVM]

gotoxy(wherex()+1,wherey());
}
break;
case 83:if(i>0)
{
if(curx<i)
{
getlinedelchar(s,col,curx+1,&i);
gotoxy(col+curx,wherey());
if(i==0)
s[i]=0;
}
}
}
break;
case 8:if(curx>0)
{
getlinedelchar(s,col,curx,&i);
gotoxy(col+curx-1,wherey());
curx--;
if(i==0)
s[i]=0;
}
break;
case 13:done=1;
s[i]=0;
break;
case 27:done=1;
s[0]='0';
break;
default:if(i<limit)
{

Page 35 of 114
Electronic Voting Management [EVM]

if(curx<i)
{
s[curx]=ch;
printf("%c",ch);
curx++;
}
else
{
s[i]=ch;
printf("%c",ch);
i++;
curx=i;
}
}
else
s[i]=0;
}
}while(!done);
printf("\n");
}

//**************************************************************
********
//FUNCTION : mscreen
//DESCRIPTION : To paint the screen with the THE OPENING SCREEN.
//**************************************************************
********

void mscreen()
{
int i=1;
int c;

Page 36 of 114
Electronic Voting Management [EVM]

char ch2;
/*request auto declaration*/
int gdriver=DETECT,gmode,errorcode;

/*initialize graphs and local variables*/


initgraph(&gdriver,&gmode,"\\tc\\bgi");

clrscr();
/*read result of initialization*/
errorcode=graphresult();

if(errorcode!=grOk) /*an error occured*/


{
printf("Graphics error :%s\n",grapherrormsg(errorcode));
printf("enter any key to halt");
getch();
exit(1); /*terminate with an error code*/
}
_setcursortype(_NOCURSOR);
clrscr();
cleardevice();

// while((!kbhit()) && (i<17))


while(i<2)
{
setbkcolor(BLACK);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
moveto(0,0);
setcolor(i);
settextstyle(GOTHIC_FONT,HORIZ_DIR,9);
moveto(5,5);
outtext("C");

Page 37 of 114
Electronic Voting Management [EVM]

delay(80);
outtext("o");
delay(80);
outtext("m");
delay(80);
outtext("p");
delay(80);
outtext("u");
delay(80);
outtext("t");
delay(80);
outtext("e");
delay(80);
outtext("r");
delay(80);
outtext("i");
delay(80);
outtext("z");
delay(80);
outtext("e");
delay(80);
outtext("d");
delay(80);

moveto(125,125);
outtext("V");
delay(80);
outtext("o");
delay(80);
outtext("t");
delay(80);

Page 38 of 114
Electronic Voting Management [EVM]

outtext("l");
delay(80);
outtext("n");
delay(80);
outtext("g");
delay(80);
moveto(245,245);
outtext("S");
delay(80);
outtext("y");
delay(80);
outtext("s");
delay(80);
outtext("t");
delay(80);
outtext("e");
delay(80);
outtext("m");
delay(80);
settextstyle(3,HORIZ_DIR,1);
i++;
}
closegraph();
_setcursortype(_SOLIDCURSOR);
}

//**************************************************************
********
//CLASS : menu
//FUNCTION : main
//DESCRIPTION : To Draw Main Menu & Call Related Functions

Page 39 of 114
Electronic Voting Management [EVM]

//**************************************************************
********

void menu()
{
int ch1;
char ch='y';
int gdriver=DETECT,gmode,errorcode;
int userpat=1;
// mscreen();

initgraph(&gdriver,&gmode,"\\tc\\bgi");
setbkcolor(BLACK);
do
{
do{
initgraph(&gdriver,&gmode,"\\tc\\bgi");
setbkcolor(BLACK);

setbkcolor(BLACK);
setcolor(15);
setlinestyle(0,userpat,3);
rectangle(0,0,getmaxx(),getmaxy());
line(0,0,25,25);
line(638,0,613,25);
line(0,475,25,450);
line(638,475,613,450);
rectangle(25,25,613,450);
settextstyle(5,HORIZ_DIR,4);
setlinestyle(0,userpat,1);
outtextxy(105,50,"Computerized Voting System");
setcolor(5);

Page 40 of 114
Electronic Voting Management [EVM]

line(105,100,510,100);
setcolor(8);
settextstyle(2,HORIZ_DIR,7);
outtextxy(250,135,"MAIN MENU");
setcolor(14);
line(250,160,355,160);
setcolor(14);
outtextxy(40,170,"1)Press 1 for voters");
outtextxy(40,205,"2)Press 2 for candidates");
outtextxy(40,240,"3)Press 3 for start voting");
outtextxy(40,275,"4)Press 4 to exit");
outtextxy(60,305,"Enter Your Choice:-");
gotoxy(39,21);

ch1=getch()-48;
printf("%d",&ch1);
closegraph();
}while(ch1>4||ch1<1);
switch(ch1)
{
case 1:
clrscr();

vmain();
break;
case 2:
clrscr();
cmain();
break;
case 3:
fmain();

Page 41 of 114
Electronic Voting Management [EVM]

break;
case 4:
exit(0);

}
gotoxy(30,25);
textcolor(BLINK+LIGHTGREEN);
cprintf("Do You Want To Continue.....");
textcolor(15);
scanf("%c",&ch);
}while((ch=='y') || (ch=='Y'));
}

void main()
{
closegraph();
mscreen();
menu();
closegraph();
}

//**************************************************************
********
//ALL THE FIELDS RELATED TO VOTERS
//**************************************************************
********

struct voter

Page 42 of 114
Electronic Voting Management [EVM]

{
int v_code;
char v_name[30],v_add[30],v_city[20],v_pin[7];
char v_phone[10];
char v_sex,v_done;
int v_age;
};
int fcode(int); //finding the voter code
void display_voter(int); //displaying a voter's information

//**************************************************************
********
//ALL FUNCTION RELATED TO VOTER
//**************************************************************
********

void add_voter(); //adding new voter in the database


void modify_voter(); //modifying the voter's information
void del_voter(); //deleting voter from the list
void displaycode_voter(); //checking the voter is exits or not
void showlist_voter(); //showing voter's list

//voter menu to handle voter's information


void main_menu()
{
int end=6, present=1, upperlim1=5, currentpos1=1, upperlim2=4,
currentpos2
=1,upperlim3=4, currentpos3=1,currentpos4=1, upperlim4=4;
char main[][20]={"file","edit","print","help","exit"};
char sub1[][20]={"newvoter ","displayinfo","displaylist","return"};
char sub2[][20]={"modifyvoter","deletevoter","return"};
char sub3[][20]={"voterinfo","voterlist","return"};

Page 43 of 114
Electronic Voting Management [EVM]

char sub4[][20]={"to main","quit","return"};


do
{
_setcursortype(_NOCURSOR);
present=horizontal_menu(main,present,end,3,1);

switch(present)
{
case 1:
currentpos1=vertical_menu(sub1,1,upperlim1,3,3);
switch(currentpos1)
{
case 1:
_setcursortype(_SOLIDCURSOR);
add_voter();
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_SOLIDCURSOR);
displaycode_voter();
break;
case 3:
showlist_voter();
break;
case 4:
_setcursortype(_SOLIDCURSOR);
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;

Page 44 of 114
Electronic Voting Management [EVM]

case 2:
currentpos2=vertical_menu(sub2,1,upperlim2,13,3);
switch(currentpos2)
{
case 1:
_setcursortype(_SOLIDCURSOR);
modify_voter();
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_NORMALCURSOR);
del_voter();
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;
case 3:
currentpos3=vertical_menu(sub3,1,upperlim3,27,3);
switch(currentpos3)
{
case 1:
_setcursortype(_SOLIDCURSOR);
displaycode_voter();
print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
case 2:
showlist_voter();
print(1,1,80,23);

Page 45 of 114
Electronic Voting Management [EVM]

_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;
case 4:
help();
clrscr();

break;

case 5:
currentpos4=vertical_menu(sub4,1,upperlim4,48,3);

switch(currentpos4)
{
case 1:
_setcursortype(_SOLIDCURSOR);
menu();
// print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
case 2:
present =end;
break;
case 3:
present = 5;
}
clrscr();
}
}while(present!=end);
}

Page 46 of 114
Electronic Voting Management [EVM]

//**************************************************************
********
//FUNCTION : fcode
//DESCRIPTIO : TO RETURN 0 IF THE GIVEN CODE IS NOT FOUND
//**************************************************************
********

int fcode(int code)


{
FILE *file;
int found=0;
struct voter temp;
file=fopen("voter.dat","rb+");
while(fread(&temp,sizeof(struct voter),1,file))
{
if(temp.v_code==code)
{
found=1;
break;
}
}
fclose(file);
return(found);
}

//**************************************************************
********
//FUNCTION : display_voter
//DESCRIPTION : to display a record from "voter.dat"
//**************************************************************
********

Page 47 of 114
Electronic Voting Management [EVM]

void display_voter(int code)


{
FILE *file;
struct voter t;
char *initial;
file=fopen("voter.dat","rb+");
while(fread(&t,sizeof(struct voter),1,file))
{
if(t.v_code==code)
{
gotoxy(28,2);
printf("VOTER INFORMATION");
if(t.v_sex=='f')
initial="Ms";
else
initial="Mr";
gotoxy(30,3);
printf("VOTER CODE #%d",t.v_code);
lineh(2,79,4,240);
gotoxy(20,6);
printf("name :%s %s",initial,t.v_name);
gotoxy(20,8);
printf("address :%s",t.v_add);
gotoxy(40,10);
printf("%s-%s",t.v_city,t.v_pin);
gotoxy(20,12);
printf("contact no. :%s",t.v_phone);
gotoxy(20,14);
printf("age :%d",t.v_age);
gotoxy(20,16);
printf("vote done :%c",t.v_done);

Page 48 of 114
Electronic Voting Management [EVM]

}
}
fclose(file);
}
//**************************************************************
********
//FUNCTION : add_voter
//DESCRIPTION : to get data about new voter
//**************************************************************
********

void add_voter()
{
struct voter t,te;
FILE *file;
char ch,choice='y';
char d[3],m[3],y[5],pf[6],da[6],ca[6],hra[6],basic[10];
int code=0,valid;
t.v_done='n';
do
{
clrscr();
_setcursortype(_SOLIDCURSOR);
gotoxy(28,2);
printf("ADDITION OF NEW VOTER");
lineh(20,59,3,240);
gotoxy(31,4);
printf("VOTER CODE #");
gotoxy(29,5);
printf("~~~~~~~~~~~~~~~~~~~~~~");
gotoxy(5,8);
printf("NAME : ..................");

Page 49 of 114
Electronic Voting Management [EVM]

gotoxy(50,8);
printf("SEX(m/f)");
gotoxy(5,10);
printf("ADDRESS : ..................");
gotoxy(50,10);
printf("CITY : ..................");
gotoxy(5,12);
printf("PIN CODE : ...................");
gotoxy(50,12);
printf("PHONE NO. : ...................");
lineh(3,78,16,196);
gotoxy(5,14);
printf("AGE : .....................");

file=fopen("voter.dat","rb+");
while(fread(&te,sizeof(struct voter),1,file)==1)
code=te.v_code;

fclose(file);
code++;
t.v_code=code;
gotoxy(47,4);
printf("%d",t.v_code);

do
{
valid=1;
statusbar("\aENTER THE NAME OF THE voter");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,8);
printf(" ");
gotoxy(20,8);

Page 50 of 114
Electronic Voting Management [EVM]

gets(t.v_name);

if(t.v_name[0]=='0')
return;
if(strlen(t.v_name)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY(LENGTH 1..30)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
statusbar("ENTER IF voter IS MALE(m) OR FEMALE(f)");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,8);
clreol();
t.v_sex=getch();

if((t.v_sex==27)||(t.v_sex=='0'))
return;
t.v_sex=tolower(t.v_sex);
}while((t.v_sex!='m')&&(t.v_sex!='f'));
printf("%c",t.v_sex);

do
{
valid=1;
statusbar("ENTER ADDRESS OF THE voter");
_setcursortype(_SOLIDCURSOR);

Page 51 of 114
Electronic Voting Management [EVM]

gotoxy(20,10);
printf(" ");
gotoxy(20,10);
gets(t.v_add);

if(t.v_add[0]=='0')
return;
if(strlen(t.v_add)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH 1..30)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER CITY OF THE voter");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,10);
clreol();
gets(t.v_city);

if(t.v_city[0]=='0')
return;
if(strlen(t.v_city)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH : 1..20)");
getch();

Page 52 of 114
Electronic Voting Management [EVM]

_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER PINCODE OF THE voter");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,12);
printf(" ");
gotoxy(20,12);
gets(t.v_pin);

if(t.v_pin[0]=='0')
return;
if(strlen(t.v_pin)!=6)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH :6)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER PHONE NO. OF THE voter OR PRESS <enter> FOR
NONE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,12);

Page 53 of 114
Electronic Voting Management [EVM]

clreol();
gets(t.v_phone);
if(t.v_phone[0]=='0')
return;
if((strlen(t.v_phone)<6) && (strlen(t.v_phone)>0) ||
(strlen(t.v_phone)>7))
{
valid=0;
statusbar("\aENTER CORRECTLY");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);
if(strlen(t.v_phone)==0)
strcpy(t.v_phone,"-");

do
{
valid=1;
statusbar("ENTER AGE OF THE voter");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,14);
clreol();
scanf("%d",&t.v_age);

if(t.v_age==0)
return;
if(t.v_age<18)
{
valid=0;
statusbar("\aENTER CORRECTLY (AGE SHOULD BE GREATER THAN
18)");

Page 54 of 114
Electronic Voting Management [EVM]

getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
statusbar("\aDO YOU WISH TO SAVE [Y/N]");
ch=getch();
ch=tolower(ch);
if((ch=='0') || (ch==27))
return;
}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;
file=fopen("voter.dat","ab+");
fwrite(&t,sizeof(struct voter),1,file);
fclose(file);
statusbar("\aADD ANY MORE [Y/N]");
do
{
choice=getch();
choice=tolower(choice);
if(choice==13)
choice='y';
if(choice==27)
choice='n';
}while((choice!='y') && (choice!='n'));
}while(choice=='y');
}

Page 55 of 114
Electronic Voting Management [EVM]

//**************************************************************
********
//FUNCTION : modify_voter
//DESCRIPTION : To Provide With Necessary Data Required For Modification
// Of a Given Record
//**************************************************************
********

void modify_voter()
{
FILE *file,*file1;
struct voter t,et;
int code,valid;
char ch,choice='y';
char address[31],city[21],pin[7],phone[10],desig[21];
char tbasic[10],tpf[6],tda[6],tca[6],thra[6];
// float basic=0,pf=0,da=0,ca=0,hra=0;
int age;
clrscr();
do
{
gotoxy(72,2);
printf("Esc=EXIT");
gotoxy(5,5);
printf("enter code of the voter :");
scanf("%d",&code);
if(code==0)
return;
clrscr();

if(!fcode(code))
{

Page 56 of 114
Electronic Voting Management [EVM]

gotoxy(30,24);
printf("\a record not found");
getch();
return;
}
display_voter(code);
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(24,2);
printf("MODIFICATION OF VOTER RECORD");
do
{
statusbar("\aDo you wish to modify this record");
ch=getch();
ch=tolower(ch);
if(ch=='0')
return;

if(ch==13)
ch='y';

if(ch==27)
ch='n';
}while((ch!='y')&&(ch!='n'));

if(ch=='n')
return;
clrscr();
file=fopen("voter.dat","rb+");
while(fread(&t,sizeof(struct voter),1,file)==1)
if(t.v_code==code)
break;

Page 57 of 114
Electronic Voting Management [EVM]

gotoxy(72,2);
printf("Esc=EXIT");
gotoxy(26,2);
printf("MODIFICATION OF NEW VOTER");
lineh(20,59,3,240);
gotoxy(31,4);
printf("voter code #%d",code);
gotoxy(29,5);
printf("~~~~~~~~~~~~~~");
lineh(3,78,7,196);
gotoxy(5,9);
printf("Name :");
gotoxy(50,9);
printf("Sex (M/F)");
gotoxy(5,11);
printf("Address :");
gotoxy(50,11);
printf("City :");
gotoxy(5,13);
printf("pincode :");
gotoxy(50,13);
printf("phone :");
gotoxy(5,15);
printf("age :");
lineh(3,78,17,196);
gotoxy(20,9);
printf("%s",t.v_name);

gotoxy(62,9);
printf("%c",t.v_sex);
fflush(stdin);

Page 58 of 114
Electronic Voting Management [EVM]

do
{
valid=1;
statusbar("ENTER ADDRES OF THE voter OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,11);
printf(" ");
gotoxy(20,11);
gets(address);

if(address[0]=='0')
return;
if(strlen(address)>30)
{
valid=0;
statusbar("\aenter correctly (length 1..30)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(address)==0)
{
strcpy(address,t.v_add);
gotoxy(20,11);
printf("%s",address);
}

do
{

Page 59 of 114
Electronic Voting Management [EVM]

valid=1;
statusbar("\aENTER CITY OF THE voter OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,11);
clreol();
gets(city);

if(city[0]=='0')
return;
if(strlen(city)>18)
{
valid=0;
statusbar("\aenter correctly (length 1..18)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(city)==0)
{
strcpy(city,t.v_city);
gotoxy(62,11);
printf("%s",city);
}

do
{
valid=1;
statusbar("\aENTER PINCODE OF THE voter OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);

Page 60 of 114
Electronic Voting Management [EVM]

gotoxy(20,13);
printf(" ");
gotoxy(20,13);
gets(pin);

if(pin[0]=='0')
return;
if((strlen(pin)!=6) && (strlen(pin)>1))
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH 6)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(pin)==0)
{
strcpy(pin,t.v_pin);
gotoxy(20,13);
printf("%s",pin);
}

do
{
valid=1;
statusbar("\aENTER PHONE OF THE voter OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,13);
clreol();
gets(phone);

Page 61 of 114
Electronic Voting Management [EVM]

if(phone[0]=='0')
return;
if(((strlen(phone)<6)&&(strlen(phone)>0))||(strlen(phone)>7))
{
valid=0;
statusbar("\aENTER CORRECTLY");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(phone)==0)
{
strcpy(phone,t.v_phone);
gotoxy(62,13);
printf("%s",phone);
}

do
{
valid=1;
statusbar("\aENTER AGE OF THE voter OR PRESS <enter> FOR NO
CHANGE"); _setcursortype(_SOLIDCURSOR);
_setcursortype(_SOLIDCURSOR);
gotoxy(20,15);
clreol();
scanf("%d",&age);
if(age==0)
return;
if(age<18)
{

Page 62 of 114
Electronic Voting Management [EVM]

valid=0;
statusbar("\aENTER CORRECTLY (range >=18)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

strcpy(t.v_add,address);
strcpy(t.v_city,city);
strcpy(t.v_pin,pin);
strcpy(t.v_phone,phone);
t.v_code=code;
t.v_age=age;

file=fopen("voter.dat","rb+");
file1=fopen("Tempmod.dat","wb+");

while(fread(&et,sizeof(struct voter),1,file)==1)
{
if(t.v_code!=et.v_code)
fwrite(&et,sizeof(struct voter),1,file1);
else
break;
}
fwrite(&t,sizeof(struct voter),1,file1);

while(fread(&et,sizeof(struct voter),1,file)==1)
fwrite(&et,sizeof(struct voter),1,file1);

/* file=fopen("voter.dat","wb+");
file1=fopen("Tempmod.dat","rb+");

Page 63 of 114
Electronic Voting Management [EVM]

while(fread(&t,sizeof(struct voter),1,file1)==1)
fwrite(&t,sizeof(struct voter),1,file);
*/
fclose(file);
fclose(file1);
gotoxy(5,25);
clreol();
do
{
statusbar("\aDo u wish to save");
ch=getch();
ch=tolower(ch);
if(ch=='0')
return;
}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;
remove("voter.dat");
rename("Tempmod.dat","voter.dat");
statusbar("\aRecord Modified");
getch();

statusbar("\aModify any more [Y/N]");


do
{
choice=getch();
choice=tolower(choice);
if(choice==13)
choice='y';

if(choice==27)

Page 64 of 114
Electronic Voting Management [EVM]

choice='n';
}while((choice!='y') && (choice!='n'));
}while(choice=='y');
}

//**************************************************************
********
//FUNCTION : del_voter
//DESCRIPTION : To Delete A Record in "voter.dat"
//**************************************************************
********

void del_voter()
{
struct voter t;
FILE *file,*file1;
char ch;
int code;
clrscr();
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(5,5);
printf("enter code of the voter");
scanf("%d",&code);
if(code==0)
return;
clrscr();
if(!fcode(code))
{
gotoxy(30,24);
printf("\arecord not found");
getch();

Page 65 of 114
Electronic Voting Management [EVM]

return;
}
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(23,1);
printf("DELETION OF THE VOTER RECORD");
display_voter(code);
do
{
statusbar("\aDo u wish to remove this record[y/n]");
ch=getch();
if(ch==27)
return;

if(ch==13)
ch='y';

ch=tolower(ch);

if(ch=='0')
return;

}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;

file=fopen("voter.dat","rb+");
file1=fopen("Tempdel.dat","wb+");

while(fread(&t,sizeof(struct voter),1,file)==1)
{

Page 66 of 114
Electronic Voting Management [EVM]

if(t.v_code!=code)
fwrite(&t,sizeof(struct voter),1,file1);
}
fclose(file);
fclose(file1);

file=fopen("voter.dat","wb+");
file1=fopen("Tempdel.dat","rb+");

while(fread(&t,sizeof(struct voter),1,file1)==1)
fwrite(&t,sizeof(struct voter),1,file);

fclose(file);
fclose(file1);

clrscr();
statusbar("\aRECORD DELETED");
getch();
statusbar(" Press Any Key to Continue");
getch();
}

//**************************************************************
********
//FUNCTION : displaycode_voter
//DESCRIPTION : To Obtain Code For Displaying a Record
//**************************************************************
********

void displaycode_voter()
{
int code;

Page 67 of 114
Electronic Voting Management [EVM]

clrscr();
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(5,5);
_setcursortype(_SOLIDCURSOR);
printf("Enter code of the voter");
scanf("%d",&code);
if(code==0)
return;
clrscr();
if(!fcode(code))
{
_setcursortype(_NOCURSOR);
gotoxy(30,25);
printf("\arecord not found");
getch();
return;
}
display_voter(code);
statusbar(" Press any key to continue....");
getch();
}

//**************************************************************
********
//FUNCTION : showlist_voter
//DESCRIPTION : To Display The List of the voter
//**************************************************************
********

void showlist_voter()
{

Page 68 of 114
Electronic Voting Management [EVM]

struct voter t;
FILE *file;
int row=6,flag=0,found=0;
int d1,m1,y1;
char ch;
struct date d;
getdate(&d);
d1=d.da_day;
m1=d.da_mon;
y1=d.da_year;
clrscr();
gotoxy(23,2);
printf("LIST OF voters AS ON %d.%d.%d",d1,m1,y1);
lineh(1,80,3,240);
gotoxy(12,4);
printf("CODE# NAME AGE");
gotoxy(1,5);
lineh(11,72,5,205);
linev(4,22,10,186);
linev(4,22,19,186);
linev(4,22,51,186);
linev(4,22,72,186);
lineh(1,80,23,240);

file=fopen("voter.dat","rb+");

while(fread(&t,sizeof(struct voter),1,file)==1)
{
flag=0;
found=1;
gotoxy(12,row);
printf("%d",t.v_code);

Page 69 of 114
Electronic Voting Management [EVM]

gotoxy(21,row);
printf("%s",t.v_name);
gotoxy(53,row);
printf("%d",t.v_age);

if(row==18)
{
flag=1;
row=6;
statusbar("Press any key to continue or pres <Esc> to exit");
ch=getch();

if(ch==27)
break;

clrscr();
gotoxy(31,2);
printf("list of voters");
lineh(1,90,3,240);
gotoxy(2,4);
printf("CODE# NAME AGE");
gotoxy(1,5);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
row++;
}
if(!found)
{
gotoxy(26,14);
printf("\aRecords not found");
}

Page 70 of 114
Electronic Voting Management [EVM]

if(!flag)
{
statusbar(" press any key to continue");
getch();
}
fclose(file);
}

//**************************************************************
********
//MAIN FUNCTION
//**************************************************************
*********

void vmain()
{
main_menu();
}

//PROGRAM 3

//**************************************************************
********
//All The Files Related To Candidate
//**************************************************************
********

struct candidate
{
int c_code,c_age,total;

Page 71 of 114
Electronic Voting Management [EVM]

char c_name[30],c_add[30],c_city[21],c_pin[7];
char c_phone[10],c_sex;
};

int fcode(int); //finding a candidate code


void display(int); //display the candidate information
void add1(); //adding new candidate
void modify1(); //modifying candidate information
void del1(); //deleting candidate from list
void displaycode1(); //displaying candidate information
void showlist1(); //showing the candidates list
void print(int,int,int,int); //activate the printer

//**************************************************************
********
//FUNCTION : main
//DESCRIPTION : To Draw The Main Menu & Call Related Functions
//**************************************************************
********

void main_menu1()
{
int end=6,present=1,upperlim1=5,upperlim2=4,upperlim3=4,currentpos1=1,
currentpos2=1,currentpos3=1, currentpos4=5,upperlim4=4;
char main[][20]={"FILE","EDIT","PRINT","HELP","EXIT"};
char sub1[][20]={"newcandidate ","displayinfo","displaylist","return"};
char sub2[][20]={"modifycandidate","deletecandidate","return"};
char sub3[][20]={"candidateinfo","candidatelist","return"};
char sub4[][20]={"to main","quit","return"};
do
{
_setcursortype(_NOCURSOR);

Page 72 of 114
Electronic Voting Management [EVM]

present=horizontal_menu(main,present,end,3,1);
switch(present)
{
case 1:
currentpos1=vertical_menu(sub1,1,upperlim1,3,3);
switch(currentpos1)
{
case 1:
_setcursortype(_SOLIDCURSOR);
add1();
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_SOLIDCURSOR);
displaycode1();
break;
case 3:
showlist1();
break;
case 4:
_setcursortype(_SOLIDCURSOR);
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;

case 2:
currentpos2=vertical_menu(sub2,1,upperlim2,13,3);
switch(currentpos2)
{
case 1:

Page 73 of 114
Electronic Voting Management [EVM]

_setcursortype(_SOLIDCURSOR);
modify1();
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_NORMALCURSOR);
del1();
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;
case 3:
currentpos3=vertical_menu(sub3,1,upperlim3,27,3);
switch(currentpos3)
{
case 1:
_setcursortype(_SOLIDCURSOR);
displaycode1();
print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
case 2:
showlist1();
print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;
case 4:
help();

Page 74 of 114
Electronic Voting Management [EVM]

clrscr();
break;

case 5:
currentpos4=vertical_menu(sub4,1,upperlim4,48,3);
switch(currentpos4)
{
case 1:
_setcursortype(_SOLIDCURSOR);
menu();
_setcursortype(_NOCURSOR);
break;
case 2:
present=end;
}
clrscr();
}
}while(present!=end);
}

//**************************************************************
********
//FUNCTION : fcode
//DESCRIPTIO : TO RETURN 0 IF THE GIVEN CODE IS NOT FOUND
//**************************************************************
********

int fcode1(int code)


{
FILE *file;
int found=0;
struct candidate temp;

Page 75 of 114
Electronic Voting Management [EVM]

file=fopen("candidate.dat","rb+");
while(fread(&temp,sizeof(struct candidate),1,file))
{
if(temp.c_code==code)
{
found=1;
break;
}
}
fclose(file);
return(found);
}

//**************************************************************
********
//FUNCTION : display
//DESCRIPTION : to display a record from "candidate.dat"
//**************************************************************
********

void display1(int code)


{
FILE *file;
struct candidate t;
char *initial;
file=fopen("candidate.dat","rb+");
while(fread(&t,sizeof(struct candidate),1,file))
{
if(t.c_code==code)
{
gotoxy(28,2);
printf("CANDIDATE INFORMATION");

Page 76 of 114
Electronic Voting Management [EVM]

if(t.c_sex=='f')
initial="Ms";
else
initial="Mr";
gotoxy(30,3);
printf("CANDIDATE CODE #%d",t.c_code);
lineh(2,79,4,240);
gotoxy(20,6);
printf("name :%s %s",initial,t.c_name);
gotoxy(20,8);
printf("address :%s",t.c_add);
gotoxy(40,10);
printf("%s-%s",t.c_city,t.c_pin);
gotoxy(20,12);
printf("contact no. :%s",t.c_phone);
gotoxy(20,14);
printf("age :%d",t.c_age);
gotoxy(20,16);
printf("Total Vote Gain : %d",t.total);
}
}
fclose(file);
}

//**************************************************************
********
//FUNCTION : add
//DESCRIPTION : to get data about new candidate
//**************************************************************
********

void add1()

Page 77 of 114
Electronic Voting Management [EVM]

{
struct candidate t,te;
FILE *file;
char ch,choice='y';
char d[3],m[3],y[5],pf[6],da[6],ca[6],hra[6],basic[10];
int code=0,valid;
t.total=0;
do
{
clrscr();
_setcursortype(_SOLIDCURSOR);
gotoxy(28,2);
printf("ADDITION OF NEW CANDIDATE");
lineh(20,59,3,240);
gotoxy(31,4);
printf("CANDIDATE CODE #");
gotoxy(29,5);
printf("~~~~~~~~~~~~~~~~~~~~");
gotoxy(5,8);
printf("NAME : ..................");
gotoxy(50,8);
printf("SEX(m/f)");
gotoxy(5,10);
printf("ADDRESS : ..................");
gotoxy(50,10);
printf("CITY : ..................");
gotoxy(5,12);
printf("PIN CODE : ...................");
gotoxy(50,12);
printf("PHONE NO. : ...................");
lineh(3,78,16,196);
gotoxy(5,14);

Page 78 of 114
Electronic Voting Management [EVM]

printf("AGE : .....................");

file=fopen("candidate.dat","rb+");
while(fread(&te,sizeof(struct candidate),1,file)==1)
code=te.c_code;

fclose(file);
code++;
t.c_code=code;
gotoxy(47,4);
printf("%d",t.c_code);

do
{
valid=1;
statusbar("\aENTER THE NAME OF THE candidate");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,8);
printf(" ");
gotoxy(20,8);
gets(t.c_name);

if(t.c_name[0]=='0')
return;
if(strlen(t.c_name)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY(LENGTH 1..30)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

Page 79 of 114
Electronic Voting Management [EVM]

do
{
statusbar("ENTER IF voter IS MALE(m) OR FEMALE(f)");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,8);
clreol();
t.c_sex=getch();
t.c_sex=tolower(t.c_sex);

if((t.c_sex==27)||(t.c_sex=='0'))
return;
t.c_sex=tolower(t.c_sex);
}while((t.c_sex!='m')&&(t.c_sex!='f'));
printf("%c",t.c_sex);

do
{
valid=1;
statusbar("ENTER ADDRESS OF THE candidate");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,10);
printf(" ");
gotoxy(20,10);
gets(t.c_add);

if(t.c_add[0]=='0')
return;
if(strlen(t.c_add)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH 1..30)");

Page 80 of 114
Electronic Voting Management [EVM]

getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER CITY OF THE candidate");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,10);
clreol();
gets(t.c_city);

if(t.c_city[0]=='0')
return;
if(strlen(t.c_city)<1)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH : 1..20)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER PINCODE OF THE candidate");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,12);
printf(" ");

Page 81 of 114
Electronic Voting Management [EVM]

gotoxy(20,12);
gets(t.c_pin);

if(t.c_pin[0]=='0')
return;
if(strlen(t.c_pin)!=6)
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH :6)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
valid=1;
statusbar("ENTER PHONE NO. OF THE candidate OR PRESS <enter> FOR
NONE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,12);
clreol();
gets(t.c_phone);
if(t.c_phone[0]=='0')
return;
if((strlen(t.c_phone)<6) && (strlen(t.c_phone)>0) ||
(strlen(t.c_phone)>7))
{
valid=0;
statusbar("\aENTER CORRECTLY");
getch();
_setcursortype(_SOLIDCURSOR);

Page 82 of 114
Electronic Voting Management [EVM]

}
}while(!valid);
if(strlen(t.c_phone)==0)
strcpy(t.c_phone,"-");

do
{
valid=1;
statusbar("ENTER AGE OF THE voter");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,14);
clreol();
scanf("%d",&t.c_age);

if(t.c_age==0)
return;
if(t.c_age<18)
{
valid=0;
statusbar("\aENTER CORRECTLY (AGE SHOULD BE GREATER THAN
18)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

do
{
statusbar("\aDO YOU WISH TO SAVE [Y/N]");
ch=getch();
ch=tolower(ch);
if((ch=='0') || (ch==27))

Page 83 of 114
Electronic Voting Management [EVM]

return;
}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;
file=fopen("candidate.dat","ab+");
fwrite(&t,sizeof(struct candidate),1,file);
fclose(file);
statusbar("\aADD ANY MORE [Y/N]");
do
{
choice=getch();
choice=tolower(choice);
if(choice==13)
choice='y';
if(choice==27)
choice='n';
}while((choice!='y') && (choice!='n'));
}while(choice=='y');
}

//**************************************************************
********
//FUNCTION : modify
//DESCRIPTION : To Provide With Necessary Data Required For Modification
// Of a Given Record
//**************************************************************
********

void modify1()
{
FILE *file,*file1;

Page 84 of 114
Electronic Voting Management [EVM]

struct candidate t,et;


int code,valid;
char ch,choice='y';
char address[31],city[21],pin[7],phone[10],desig[21];
char tbasic[10],tpf[6],tda[6],tca[6],thra[6];
// float basic=0,pf=0,da=0,ca=0,hra=0;
int age;
clrscr();
do
{
gotoxy(72,2);
printf("Esc=EXIT");
gotoxy(5,5);
printf("enter code of the candidate :");
scanf("%d",&code);
if(code==0)
return;
clrscr();

if(!fcode1(code))
{
gotoxy(30,24);
printf("\a record not found");
getch();
return;
}
display1(code);
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(24,2);
printf("MODIFICATION OF CANDIDATE RECORD");
do

Page 85 of 114
Electronic Voting Management [EVM]

{
statusbar("\aDo you wish to modify this record");
ch=getch();
ch=tolower(ch);
if(ch=='0')
return;

if(ch==13)
ch='y';

if(ch==27)
ch='n';
}while((ch!='y')&&(ch!='n'));

if(ch=='n')
return;
clrscr();
file=fopen("candidate.dat","rb+");
while(fread(&t,sizeof(struct candidate),1,file)==1)
if(t.c_code==code)
break;

gotoxy(72,2);
printf("Esc=EXIT");
gotoxy(26,2);
printf("MODIFICATION OF NEW CANDIDATE");
lineh(20,59,3,240);
gotoxy(31,4);
printf("candidate code #%d",code);
gotoxy(29,5);
printf("~~~~~~~~~~~~~~");
lineh(3,78,7,196);

Page 86 of 114
Electronic Voting Management [EVM]

gotoxy(5,9);
printf("Name :");
gotoxy(50,9);
printf("Sex (M/F)");
gotoxy(5,11);
printf("Address :");
gotoxy(50,11);
printf("City :");
gotoxy(5,13);
printf("pincode :");
gotoxy(50,13);
printf("phone :");
gotoxy(5,15);
printf("age :");
lineh(3,78,17,196);
gotoxy(20,9);
printf("%s",t.c_name);

gotoxy(62,9);
printf("%c",t.c_sex);
fflush(stdin);

do
{
valid=1;
statusbar("ENTER ADDRES OF THE candidate OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,11);
printf(" ");
gotoxy(20,11);
gets(address);

Page 87 of 114
Electronic Voting Management [EVM]

if(address[0]=='0')
return;
if(strlen(address)>30)
{
valid=0;
statusbar("\aenter correctly (length 1..30)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(address)==0)
{
strcpy(address,t.c_add);
gotoxy(20,11);
printf("%s",address);
}

do
{
valid=1;
statusbar("\aENTER CITY OF THE candidate OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,11);
clreol();
gets(city);

if(city[0]=='0')
return;
if(strlen(city)>18)

Page 88 of 114
Electronic Voting Management [EVM]

{
valid=0;
statusbar("\aenter correctly (length 1..18)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(city)==0)
{
strcpy(city,t.c_city);
gotoxy(62,11);
printf("%s",city);
}

do
{
valid=1;
statusbar("\aENTER PINCODE OF THE candidate OR PRESS <enter>
FOR NO CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(20,13);
printf(" ");
gotoxy(20,13);
gets(pin);

if(pin[0]=='0')
return;
if((strlen(pin)!=6) && (strlen(pin)>1))
{
valid=0;
statusbar("\aENTER CORRECTLY (LENGTH 6)");

Page 89 of 114
Electronic Voting Management [EVM]

getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

if(strlen(pin)==0)
{
strcpy(pin,t.c_pin);
gotoxy(20,13);
printf("%s",pin);
}

do
{
valid=1;
statusbar("\aENTER PHONE OF THE candidate OR PRESS <enter> FOR NO
CHANGE");
_setcursortype(_SOLIDCURSOR);
gotoxy(62,13);
clreol();
gets(phone);

if(phone[0]=='0')
return;
if(((strlen(phone)<6)&&(strlen(phone)>0))||(strlen(phone)>7))
{
valid=0;
statusbar("\aENTER CORRECTLY");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

Page 90 of 114
Electronic Voting Management [EVM]

if(strlen(phone)==0)
{
strcpy(phone,t.c_phone);
gotoxy(62,13);
printf("%s",phone);
}

do
{
valid=1;
statusbar("\aENTER AGE OF THE candidate OR PRESS <enter> FOR NO
CHANGE"); _setcursortype(_SOLIDCURSOR);
_setcursortype(_SOLIDCURSOR);
gotoxy(20,15);
clreol();
scanf("%d",&age);
if(age==0)
return;
if(age<18)
{
valid=0;
statusbar("\aENTER CORRECTLY (range >=18)");
getch();
_setcursortype(_SOLIDCURSOR);
}
}while(!valid);

strcpy(t.c_add,address);
strcpy(t.c_city,city);
strcpy(t.c_pin,pin);
strcpy(t.c_phone,phone);

Page 91 of 114
Electronic Voting Management [EVM]

t.c_code=code;
t.c_age=age;

file=fopen("candidate.dat","rb+");
file1=fopen("Tempmod.dat","wb+");

while(fread(&et,sizeof(struct candidate),1,file)==1)
{
if(t.c_code!=et.c_code)
fwrite(&et,sizeof(struct candidate),1,file1);
else
break;
}
fwrite(&t,sizeof(struct candidate),1,file1);

while(fread(&et,sizeof(struct candidate),1,file)==1)
fwrite(&et,sizeof(struct candidate),1,file1);

fclose(file);
fclose(file1);

gotoxy(5,25);
clreol();
do
{
statusbar("\aDo u wish to save");
ch=getch();
ch=tolower(ch);
if(ch=='0')
return;
}while((ch!='y') && (ch!='n'));

Page 92 of 114
Electronic Voting Management [EVM]

if(ch=='n')
return;

remove("candidate.dat");
rename("Tempmod.dat","candidate.dat");
statusbar("\a Record Modified ");
getch();

statusbar("\aModify any more [Y/N]");


do
{
choice=getch();
choice=tolower(choice);
if(choice==13)
choice='y';

if(choice==27)
choice='n';
}while((choice!='y') && (choice!='n'));
}while(choice=='y');
}

//**************************************************************
********
//FUNCTION : del
//DESCRIPTION : To Delete A Record in "candidate.dat"
//**************************************************************
********

void del1()
{

Page 93 of 114
Electronic Voting Management [EVM]

struct candidate t;
FILE *file,*file1;
char ch;
int code;
clrscr();
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(5,5);
printf("enter code of the candidate");
scanf("%d",&code);
if(code==0)
return;
clrscr();
if(!fcode1(code))
{
gotoxy(30,24);
printf("\arecord not found");
getch();
return;
}
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(23,1);
printf("DELETION OF THE CANDIDATE RECORD");
display1(code);
do
{
statusbar("\aDo u wish to remove this record[y/n]");
ch=getch();
if(ch==27)
return;

Page 94 of 114
Electronic Voting Management [EVM]

if(ch==13)
ch='y';

ch=tolower(ch);

if(ch=='0')
return;

}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;

file=fopen("candidate.dat","rb+");
file1=fopen("Tempdel.dat","wb+");

while(fread(&t,sizeof(struct candidate),1,file)==1)
{
if(t.c_code!=code)
fwrite(&t,sizeof(struct candidate),1,file1);
}
fclose(file);
fclose(file1);

file=fopen("candidate.dat","wb+");
file1=fopen("Tempdel.dat","rb+");

while(fread(&t,sizeof(struct candidate),1,file1)==1)
fwrite(&t,sizeof(struct candidate),1,file);

fclose(file);
fclose(file1);

Page 95 of 114
Electronic Voting Management [EVM]

clrscr();
statusbar("\aRECORD DELETED");
getch();
statusbar(" Press Any Key to Continue");
getch();
}

//**************************************************************
********
//FUNCTION : displaycode1
//DESCRIPTION : To Obtain Code For Displaying a Record
//**************************************************************
********

void displaycode1()
{
int code;
clrscr();
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(5,5);
_setcursortype(_SOLIDCURSOR);
printf("Enter code of the candidate");
scanf("%d",&code);
if(code==0)
return;
clrscr();
if(!fcode1(code))
{
_setcursortype(_NOCURSOR);
gotoxy(30,25);

Page 96 of 114
Electronic Voting Management [EVM]

printf("\arecord not found");


getch();
return;
}
display1(code);
statusbar(" Press any key to continue....");
getch();
}

//**************************************************************
********
//FUNCTION : showlist1
//DESCRIPTION : To Display The List of the voter
//**************************************************************
********

void showlist1()
{
struct candidate t;
FILE *file;
int row=6,flag=0,found=0;
int d1,m1,y1;
char ch;
struct date d;
getdate(&d);
d1=d.da_day;
m1=d.da_mon;
y1=d.da_year;
clrscr();
gotoxy(23,2);
printf("LIST OF candidates AS ON %d.%d.%d",d1,m1,y1);
lineh(1,80,3,240);

Page 97 of 114
Electronic Voting Management [EVM]

gotoxy(12,4);
printf("CODE# NAME AGE");
gotoxy(1,4);
lineh(11,72,5,205);
linev(4,22,10,186);
linev(4,22,19,186);
linev(4,22,51,186);
linev(4,22,72,186);
lineh(1,80,23,240);

file=fopen("candidate.dat","rb+");

while(fread(&t,sizeof(struct candidate),1,file)==1)
{
flag=0;
found=1;
gotoxy(12,row);
printf("%d",t.c_code);
gotoxy(21,row);
printf("%s",t.c_name);
gotoxy(53,row);
printf("%d",t.c_age);

if(row==18)
{
flag=1;
row=6;
statusbar("Press any key to continue or pres <Esc> to exit");
ch=getch();

if(ch==27)
break;

Page 98 of 114
Electronic Voting Management [EVM]

clrscr();
gotoxy(31,2);
printf("list of candidates");
lineh(1,90,3,240);
gotoxy(2,4);
printf("CODE# NAME AGE");
gotoxy(1,5);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
row++;
}
if(!found)
{
gotoxy(26,14);
printf("\aRecords not found");
}

if(!flag)
{
statusbar(" press any key to continue");
getch();
}
fclose(file);
}

//**************************************************************
********
//MAIN FUNCTION
//**************************************************************
*********

Page 99 of 114
Electronic Voting Management [EVM]

void cmain()
{
main_menu1();
}

// PROGRAM 4

//**************************************************************
********
//ALL THE FIELDS RELATED TO VOTERS
//**************************************************************
********

int fcode(int);

//**************************************************************
********
//ALL THE FUNCTIONS RELATED TO VOTERS
//**************************************************************
********

void showlistf(); //displaying list of voters and candidates


void final(); //preparing final list for winner
void vote(); //casting vote or checking for vote
void showlist();
void showlist1();
void fmain(void); //to start voting main menu

//displaying voting main menu

Page 100 of 114


Electronic Voting Management [EVM]

void vote_menu()
{
int end=6,present=1,upperlim1=4,upperlim2=3,upperlim3=4,currentpos1=1,
currentpos2=1,currentpos3=1,upperlim4=4,currentpos4=5;
char main[][20]={"LIST","VOTE","PRINT","HELP","EXIT"};
char sub1[][20]={"List of candidate ","Winner","return"};
char sub2[][20]={"modify voter","return"};
char sub3[][20]={"after vote","winner","return"};
char sub4[][20]={"to main","quit","return"};
do
{
_setcursortype(_NOCURSOR);
present=horizontal_menu(main,present,end,3,1);
switch(present)
{
case 1:
currentpos1=vertical_menu(sub1,1,upperlim1,3,3);
switch(currentpos1)
{
case 1:
_setcursortype(_SOLIDCURSOR);
showlistf();
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_SOLIDCURSOR);
final();
break;
}
clrscr();
break;

Page 101 of 114


Electronic Voting Management [EVM]

case 2:
currentpos2=vertical_menu(sub2,1,upperlim2,13,3);
switch(currentpos2)
{
case 1:
_setcursortype(_SOLIDCURSOR);
vote();
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;
case 3:
currentpos3=vertical_menu(sub3,1,upperlim3,27,3);
switch(currentpos3)
{
case 1:
_setcursortype(_SOLIDCURSOR);
showlistf();
print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
case 2:
_setcursortype(_NORMALCURSOR);
final();
print(1,1,80,23);
_setcursortype(_NOCURSOR);
break;
}
clrscr();
break;

Page 102 of 114


Electronic Voting Management [EVM]

case 4:
help();
clrscr();
break;

case 5:
currentpos4=vertical_menu(sub4,1,upperlim4,48,3);
switch(currentpos4)
{
case 1:
_setcursortype(_SOLIDCURSOR);
menu();
_setcursortype(_NOCURSOR);
break;
case 2:
present=end;
}
clrscr();
}

}while(present!=end);
}

//**************************************************************
********
//FUNCTION : vote
//DESCRIPTION : To Check Whether or not the voter casted the vote
// and increment the total votes for the casted candidate
//**************************************************************
********

void vote()

Page 103 of 114


Electronic Voting Management [EVM]

{
FILE *file;
FILE *file2;
FILE *file3;
struct voter t,te;
struct candidate c,ce;
FILE *file1;
int code,code1,valid;
char ch;
char add[30],city[21],pin[7],phone[10],desig[21];
int age;

clrscr();

gotoxy(72,2);
printf("Esc=EXIT");
gotoxy(5,5);
printf("enter code of the voter:");
scanf("%d",&code);

if(code==0)
return;
clrscr();

if(!fcode(code))
{
gotoxy(30,24);
printf("\a Record not found");
getch();
return;
}
file=fopen("voter.dat","rb+");

Page 104 of 114


Electronic Voting Management [EVM]

while(fread(&t,sizeof(struct voter),1,file)==1)
{
if(t.v_code==code)
{
if(t.v_done=='Y')
{
printf("Already casted the vote");
getch();
return;
}
}
}
fclose(file);
gotoxy(72,2);
printf("<0>=EXIT");
gotoxy(24,2);
printf("VOTING IS GOING ON");
gotoxy(5,4);
printf("candidate no :....");
scanf("%d",&code1);

if(!fcode1(code1))
{
gotoxy(30,24);
printf("\a record not found");
getch();
return;
}
file=fopen("voter.dat","rb+");
while(fread(&t,sizeof(struct voter),1,file)==1)
{
if(t.v_code==code)

Page 105 of 114


Electronic Voting Management [EVM]

{
t.v_done='Y';
break;
}
}

file2=fopen("candidate.dat","rb+");
while(fread(&c,sizeof(struct candidate),1,file2)==1)
{
if(c.c_code==code1)
{
c.total++;
break;
}
}
// lineh(3,78,17,196);

file=fopen("voter.dat","rb+");
file1=fopen("tempmod.dat","wb+");

while(fread(&te,sizeof(struct voter),1,file)==1)
{
if(t.v_code!=te.v_code)
fwrite(&te,sizeof(struct voter),1,file1);
else
break;
}

fwrite(&t,sizeof(struct voter),1,file1);
while(fread(&te,sizeof(struct voter),1,file)==1)
fwrite(&te,sizeof(struct voter),1,file1);

Page 106 of 114


Electronic Voting Management [EVM]

fclose(file);
fclose(file1);
remove("voter.dat");
rename("Tempmod.dat","voter.dat");

file=fopen("candidate.dat","rb+");
file1=fopen("Tempmod1.dat","wb+");
while(fread(&ce,sizeof(struct candidate),1,file)==1)
{
if(c.c_code!=ce.c_code)
fwrite(&ce,sizeof(struct candidate),1,file1);
else
break;
}

fwrite(&c,sizeof(struct candidate),1,file1);
while(fread(&ce,sizeof(struct candidate),1,file)==1)
fwrite(&ce,sizeof(struct candidate),1,file1);

fclose(file);
fclose(file1);
remove("candidate.dat");
rename("Tempmod1.dat","candidate.dat");
gotoxy(5,25);
clreol();

do
{
statusbar("\aDo u wish to save (y/n)");
ch=getch();
ch=tolower(ch);
if(ch=='0')

Page 107 of 114


Electronic Voting Management [EVM]

return;
}while((ch!='y') && (ch!='n'));

if(ch=='n')
return;
statusbar("Record Modified.");
getch();
}

//**************************************************************
********
//FUNCTION : showlistf
//DESCRIPTION : To Display The List of Voters Together with the total voters
//**************************************************************
********

void showlistf()
{
struct candidate t;
FILE *file;
int row=6,found=0,flag=0;
int d1,m1,y1;
char ch;
struct date d;
getdate(&d);
d1=d.da_day;
m1=d.da_mon;
y1=d.da_year;

clrscr();

Page 108 of 114


Electronic Voting Management [EVM]

gotoxy(23,2);
printf("LIST OF candidates AS ON %d.%d.%d",d1,m1,y1);
lineh(1,80,3,240);
gotoxy(12,4);
printf("CODE# NAME TOTAL");
gotoxy(1,5);
lineh(11,72,5,205);
linev(4,22,10,186);
linev(4,22,19,186);
linev(4,22,51,186);
linev(4,22,72,186);
lineh(1,80,23,240);

file=fopen("candidate.dat","rb+");

while(fread(&t,sizeof(struct candidate),1,file)==1)
{
flag=0;
found=1;
gotoxy(12,row);
printf("%d",t.c_code);
gotoxy(21,row);
printf("%s",t.c_name);
gotoxy(53,row);
printf("%d",t.total);

if(row==18)
{
flag=1;
row=6;
statusbar("Press any key to continue or pres <Esc> to exit");
ch=getch();

Page 109 of 114


Electronic Voting Management [EVM]

if(ch==27)
break;

clrscr();
gotoxy(31,2);
printf("list of voters");
lineh(1,90,3,240);
gotoxy(2,4);
printf("CODE# NAME TOTAL");
gotoxy(1,5);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
row++;
}
if(!found)
{
gotoxy(26,14);
printf("\aRecords not found");
}

if(!flag)
{
statusbar(" press any key to continue....");
getch();
}
fclose(file);
}

//**************************************************************
********

Page 110 of 114


Electronic Voting Management [EVM]

//FUNCTION : final
//DESCRIPTION : To Display The Winner in the election
//**************************************************************
********

void final()
{
FILE *file;
struct candidate t;
int code,max=0;
char name[31];

clrscr();

file=fopen("candidate.dat","rb+");
fread(&t,sizeof(struct candidate),1,file);
max=t.total;
code=t.c_code;
strcpy(name,t.c_name);
printf("%d",max);
getch();

while(fread(&t,sizeof(struct candidate),1,file)==1)
{
if(t.total>max)
{
max=t.total;
code=t.c_code;
strcpy(name,t.c_name);
}
}

Page 111 of 114


Electronic Voting Management [EVM]

lineh(1,80,3,240);
gotoxy(22,5);
printf("WINNER IS...");
gotoxy(22,7);
printf("CODE :%d",code);
gotoxy(22,9);
printf("NAME :%s",name);
gotoxy(22,11);
printf("WIN BY :%d" ,max);
printf("votes");
lineh(1,80,12,240);
getch();
fclose(file);
}

//**************************************************************
********
//MAIN FUNCTION
//y*************************************************************
**********

void fmain(void)
{
vote_menu();
}

Page 112 of 114


Electronic Voting Management [EVM]

Data types used in C++

Name Description Size* Range*


signed: -128 to 127
Char Character or small integer. 1byte
unsigned: 0 to 255
signed: -32768 to
short int
Short Integer. 2bytes 32767
(short)
unsigned: 0 to 65535
signed: -2147483648
to 2147483647
int Integer. 4bytes
unsigned: 0 to
4294967295
signed: -2147483648
long int to 2147483647
Long integer. 4bytes
(long) unsigned: 0 to
4294967295
Boolean value. It can take one of
bool 1byte true or false
two values: true or false.
+/- 3.4e +/- 38 (~7
float Floating point number. 4bytes
digits)
Double precision floating point +/- 1.7e +/- 308 (~15
double 8bytes
number. digits)
long Long double precision floating +/- 1.7e +/- 308 (~15
8bytes
double point number. digits)
2 or 4
wchar_t Wide character. 1 wide character
bytes

Declaration of variables

In order to use a variable in C++, we must first declare it specifying which


data type we want it to be. The syntax to declare a new : :
int a;
float mynumber;

Page 113 of 114


Electronic Voting Management [EVM]

Scope of Variables

Function: A function is a group of statements that is executed when it is


called from some point of the program. The following is its format:

type name ( parameter1, parameter2, ...) { statements }

where:

• type is the data type specifier of the data returned by the function.
• name is the identifier by which it will be possible to call the function.
• parameters (as many as needed): Each parameter consists of a data
type specifier followed by an identifier, like any regular variable
declaration (for example: int x) and which acts within the function as
a regular local variable. They allow to pass arguments to the function
when it is called. The different parameters are separated by commas.
• statements is the function's body. It is a block of statements
surrounded by braces { }.

Page 114 of 114

Das könnte Ihnen auch gefallen