C Final
C Final
1.0 Introduction.........................................................................................................................................3
2.0 Assumption...........................................................................................................................................3
3.0 Explanation of program source code with sample input and output.............................................17
5.0 Conclusion..........................................................................................................................................31
1.0 Introduction
The voting system is a system designed for the APU university using the C programming
language. The C programming language is used in creating the program using the software
known as Dev C++. The voting system contains several users such as the admin who serves as a
manager, the candidate who elected the election, and voters who vote for the candidates.
The system allows the admin to add, delete, and update the candidate's details. Admin has a
username and password. The user entered the defined username and password to access the
admin function.
2.0 Assumption
There are several assumptions while designing the program. The voting system is programmed to
store the candidate’s details and voter details. The candidate’s details include the Candidate's ID,
Name, political party, and candidacy. The voter’s details include voter ID, name, address, and
password. In the admin function, user-defined the username and password. If the user wants to
edit the candidate, a user should enter the username and password after he or she accesses the
program.
2.0 Design of a program.
2.1 Pseudo code of a program
2.2 Flowchart of a program
Main program and Menu function flow chart.
3.0 Explanation of program source code with sample input and output
3.1 Header File Source code
In general, the header files contain function declarations, data types, and preprocessor
commands. This code also contains the structure where multiple data types are stored in the
suitable variable. After that code, declarations can be done. We all declare the necessary
functions that are needed to execute the program. The header file ’include<stdio.h>’ allows us to
use ‘printf()’ and ‘scanf()’ for input and output operations. Without these header files, the
compiler can’t compile the program. The other header file “#include<string.h>” is used to
manipulate the string function in the program. These functions include strcpy(), strlen(), strcmp()
etc. The structure ‘electionschedule’ is created to hold the information related to the election
schedule including the name of consistency (‘consistency’) and (‘DateOfElection’).
Similarly, the other structures are (‘Voter_Registratioin’) and (‘Candidate_Registration’) which
are designed the store multiple data related to their voter registration and candidate registration
respectively. We all declared so many functions such as admin(), candidate(), electionSchedule(),
VoterRegistration() and remaining functions are in the above program.
Fig 1 shows that the Switch case statement allows the user to select options 1 to 5 based on their
roles. If users want to exit the program, she/he can press button 5’ exit the program’. Fig 2
shows that if a user can’t select the options between 1 and 5, an invalid choice is displayed on the
screen. Similarly, when users press the button between 1 to 4, it goes to functions like
admin(),voterRegisteration(),candidate(), and displayVoteresult().
We go sequentially.
The admin username and password are defined at the first of the function. If the above username,
password, and the user's entered username, and password are not the same. It displayed admin
verification failed on the screen. If users want to create the election schedule, they entered right
username and password.
The above code in the figure uses the switch case statement to choose selections 1 to 3 whether
to create an election schedule, edit candidates, or exit the program. If the admin wants to create
the election schedule, he/she should press button 1 to enter the election schedule functions
The above code in this figure when users want to create the election schedule, they enter the
information related to the election schedule including consistency and date of election. After
entering the information related to the schedule, this information will be stored in schedule.txt.
if users want to store the information in the file, he/she creates the file, open its file in append
form, and close its file. After that, the information will be stored in that file.
In the above figure, the candidate entered their information based on the data types. After
entering, the candidate should be registered successfully. After the registration, all information is
stored in the candidatelist.txt file because the user creates a file candidate, opens it as append
mode, stores the information in that file, and then closes it file.
fig : candidatelist.txt
This is the candidatelist.txt where the candidate’s information are stored in this file.
According to the question, only the admin can add, update, and delete the candidates. After the
candidate registration, a user should go to the admin function to edit the candidates. It uses a
switch case statement where have to select edit candidates function whether to add, delete or
update the candidates.
In the above figure, this function operates to add the information of candidates such as ID, name,
political party, and candidacy. The function starts by declaring a file pointer candidate to FILE.
The file pointer is opened for appending mode and the writes user inputs information to store in
the candidatelist.txt.
In this output, the program asked the registered about the information of the new
candidate and added it to the file.
Fig: add candidate on candidatelist.txt.
After entering the information about the new candidate, this information will be
stored in a file. Only the admin can add the candidate information.