Components of Online Voting System
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.
- 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.
Online Voting System in C
Voting in elections is one of the most fundamental organs of any Democracy and in the modern world, voting is done through digital machines. In this article, we will try to write a simple Online Voting System using C programming language.