Assignment 3
Assignment 3
Assignment # 3
Total Marks: 10 Deadline: June 6, 2024 in class till 08:10 AM
Instructions:
1) Please provide a complete solution in HARD FORM (Hand Written).
2) Typed/Printed Assignment will NOT be marked.
3) Plagiarism in the work is Professional dishonesty which leads to strict disciplinary action
and zero in grading of Assignment.
4) NOT following the given instructions for the assignment will result in ZERO marks.
5) Make your own functions and every function should perform one functionality only.
6) Use pointer notation rather than array notation.
7) Don’t use of any built-in function related to char array otherwise your task will be
cancelled.
8) Don’t use Global variables and string data type.
Learning Objectives: Demonstrate knowledge of Pointers, dynamic memory allocation, function,
file handling in C++ in programming (C++).
Write a C++ program that allows read the local election data from the file to get the candidate’s ID
and Vote received by the candidate. The program should then store into the file and display each
candidate’s ID, the number of votes received, and the percentage of the total votes received by the
candidate. Your program should also output total number of votes and the winner of the election.
Note: Follows the function declarations and you can add more helper functions apart from provided
the declaration with function names as helper1, helper 2 and so on.
Sample Output
Candidate Votes Received % of Total Votes
10005 5000 25.91%
20006 4000 20.73 %
30007 6000 31.09 %
40008 2500 12.95 %
80009 1800 9.33 %
Total 19300
The Winner of the Election is 30007
1
Function Declarations:
• void Sizeofarrayfromfile(char* filename,int& numCandidates)
• void ReadCandidateData(char *filename, int* candidateIds, int* votesReceived, int
numCandidates);
• int calculateTotalVotes(int* votesReceived, int numCandidates);
• void calculateVotePercentages(double* votePercentages, int* votesReceived, int
totalVotes, int numCandidates);
• int findWinnerIndex(int* votesReceived, int numCandidates);
• void displayCandidateInfo(int* candidateIds, int* votesReceived, double*
votePercentages, int numCandidates);
• void writeToFile(int* candidateIds, int* votesReceived, double* votePercentages, int
numCandidates);
• int* dynamic(int numCandidates);