DSA Project
DSA Project
on
Submitted by
in a course
SY B. Tech
Under the Guidance of
(Mrs.Manisha Kowdiki)
1
Table of Contents
Acknowledgement 1
List of Figures 2
Online Voting System
Abbreviations 3
1 Introduction………………………………………………………….. 4
3 Problem statement 7
4 Methodology 7
5 Code 9
6 Results 14
7 Conclusion 17
8 Learning outcome 19
9 References 19
2
C Program to Implement Online Voting System
INTRODUCTION
Online voting systems represent a transformative approach to democratic
participation, harnessing the power of technology to modernize the electoral
process. By facilitating remote voting via the internet, these systems offer
unparalleled accessibility, convenience, and security to voters worldwide.
The code presented here lays the foundation for an online voting system,
demonstrating key functionalities essential to its operation. Let's delve into the
core components and principles underlying this innovative platform:
Security and Integrity: Central to the design of online voting systems is robust
security measures to safeguard the integrity of the electoral process. The code
implements encryption, authentication mechanisms, and ballot verification
procedures to protect against tampering, fraud, and unauthorized access, ensuring
that every vote is counted accurately and securely.
4
C Program to Implement Online Voting System
Aim and Objectives:
The online voting system offers the following functions:
Taking a Vote from the User
Storing Different Votes
Calculating Votes
Declaring Results
Components of Program
The Online Voting System program has the following components:
1. Header Files and Macro Definitions
This program makes use of only two standard header files <stdio.h>
and <string.h>.
We have also defined a macro to represent the maximum number of
candidates.
2. Structure with name “Candidate”
The structure with the name “Candidate” is defined to store the information of
the candidate. It has the following fields:
name Array: This array of characters is used to store the name of the
candidate.
5
C Program to Implement Online Voting System
symbol: This character variable stores the symbol allotted to the
candidate.
votes: This variable is used to store the number of votes that the given
candidate received.
3. Data Structures and Variables with Global Scope
Some of the data structures and variables are declared inside the global scope to
avoid scope problems and make them available to all the functions in the
program. These are:
allCandidate[]: This array stores all the candidates.
candidateCount: It is used to store the number of candidates.
symbol[]: This array is used to store all the symbols.
symbolTaken[]: Used to keep track of the symbols that are already
allotted to some candidate.
4. Functions to Perform Different Tasks
Various functions are used in the program to provide modularity to the code.
They are named based on the task they are performing:
fillCandidate(): This function is used to take user input about the
candidate details and store them in the allCandidate[] array.
displayAllCandidates(): This function is used to display all available
candidates while the voting is being performed.
getVotes(): This function is used to take the votes from the user and
store them in the structure for the given candidate.
getResults(): After the voting, the getResults() function is used to
calculate the votes and declare the results of the elections.
6
C Program to Implement Online Voting System
Methodology:
1. Requirements Gathering and Analysis:
Identify the primary objectives and functionality required for the online voting
system.
Define user roles, such as voters, candidates, and administrators, and their
respective responsibilities.
2. Design:
Design the data structures and algorithms needed to implement the core
functionalities of the online voting system, such as storing candidate
information, tallying votes, and displaying results.
Define the user interface layout and interaction flow for the web-based
application, considering usability and accessibility principles.
3. Implementation:
Write the code for the online voting system in C, following best practices for
code organization, readability, and modularity.
7
C Program to Implement Online Voting System
Implement functions for candidate registration, voter authentication, ballot
casting, vote tallying, and result determination according to the defined
requirements and design specifications.
4. Testing:
Develop test cases to verify the functionality, correctness, and reliability of the
online voting system.
5. Deployment:
Prepare the online voting system for deployment on a web server or hosting
platform.
8
C Program to Implement Online Voting System
Provide ongoing maintenance and support for the online voting system,
addressing any issues, bugs, or security vulnerabilities that arise.
Code:
#include <stdio.h>
#include <string.h>
#define MAX_C 11
char name[50];
int votes;
char symbol;
} Candidate;
Candidate allCandidates[MAX_C];
int candidateCount = 0;
char symbols[10] = { '!', '@', '#', '$', '%', '^', '&', '*', '~', '+' };
int symbolTaken[11];
void fillCandidate(int);
void displayAllCandidates();
void getVotes(int);
void getResults();
9
C Program to Implement Online Voting System
int main()
symbolTaken[i] = 0;
scanf("%d", &candidateCount);
return 0;
fillCandidate(i);
int numVoters;
scanf("%d", &numVoters);
getVotes(i);
getResults();
10
C Program to Implement Online Voting System
return 0;
if (symbolTaken[j] == 1)
continue;
int num = 0;
cNum + 1);
scanf("%d", &num);
num = 0;
fillCandidate(cNum);
else {
symbolTaken[num - 1] = 1;
cNum + 1);
11
C Program to Implement Online Voting System
scanf("%s", allCandidates[cNum].name);
allCandidates[cNum].votes = 0;
void displayAllCandidates()
if (candidateCount <= 0) {
return;
printf("%s\t\t", allCandidates[j].name);
printf("\n");
printf("%3c\t\t\t", allCandidates[j].symbol);
printf("\n");
displayAllCandidates();
voterCount + 1, candidateCount);
12
C Program to Implement Online Voting System
int choice;
scanf("%d", &choice);
allCandidates[choice - 1].votes++;
else {
getVotes(voterCount);
void getResults()
int maxVotes = 0;
int winnerFrequency = 0;
maxVotes = allCandidates[i].votes;
winnerIndex = i;
if (allCandidates[i].votes == maxVotes) {
winnerFrequency++;
13
C Program to Implement Online Voting System
}
printf("\n-----RESULT-----\n");
"%c\nwith %d votes!\n",
allCandidates[winnerIndex].name,
allCandidates[winnerIndex].symbol, maxVotes);
else {
printf("No winner\n");
}
}
Result:
Enter the number of candidates: 3
Available Symbols:
1!
2@
3#
4$
5%
6^
14
C Program to Implement Online Voting System
7&
8*
9~
10 +
Available Symbols:
2@
3#
4$
5%
6^
7&
8*
9~
10 +
Available Symbols:
3#
4$
5%
6^
15
C Program to Implement Online Voting System
7&
8*
9~
10 +
! @ #
! @ #
! @ #
! @ #
! @ #
! @ #
16
C Program to Implement Online Voting System
Voter 6, please enter your choice (1-3): 3
! @ #
! @ #
! @ #
! @ #
-----RESULT-----
Candidate Symbol: @
with 4 votes!
Conclusion:
17
C Program to Implement Online Voting System
Learning outcome:
1. Programming Concepts:
18
C Program to Implement Online Voting System
Algorithm Design: Designing algorithms for vote tallying and result
determination, essential skills for processing data and making decisions in
software development.
19
C Program to Implement Online Voting System
Legal and Regulatory Compliance: Learning about legal and regulatory
requirements governing online voting systems, including privacy laws,
electoral regulations, and cybersecurity standards.
Reference:
https://www.geeksforgeeks.org/online-voting-system-in-c/
https://github.com/Rajattheonlyhero/Online-Voting-System-Data-Structure-
Projec
20