Question
2) Write a C++ program that reads from a file the last name of an election candidate and the number of votes that they received,
2) Write a C++ program that reads from a file the last name of an election candidate and the number of votes that they received, you program would then determine what percentage of vote each candidate received and the winner of the election. Use the concept of parallel arrays. Your program should contain the following functions
a) A function to read in the data from the file into the appropriate data structure
b) A function to calculate each candidates percentage of vote earned
c) A function to print out each candidate's name, number of votes and percentage of total vote earned (Output should be formatted to look like the file, with a new header for vote percent)
d) A function that returns the name of the election winner.
Use appropriate function calls to test your program. Below is the content of the file. ignore the first line containing the headers if it makes it easier to write
Candidate Number of Votes
Lannister 350000
Stark 310000
Targaryen 397000
Baratheon 275000
Martell 280000
Greyjoy 205000
Mormont 415000
Tully 30000
(Feel free to adjust the numbers in the file)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started