Question
language-C++ NO ARRAYS ALLOWED The Hogwarts Potions Club recently held elections for President, Vice-President, Secretary, and Treasurer. All of the students , teachers, ghosts and
language-C++
NO ARRAYS ALLOWED
The Hogwarts Potions Club recently held elections for President, Vice-President, Secretary,
and Treasurer. All of the students, teachers, ghosts and paintings votes were stored in a text file. You have been tasked with writing a program that reads from that file and figures out who the winners of each election were.
The file is formatted with one persons (or former persons) ballot on each line. Each line of the file contains four integers (each separated by a space).
For each election, there are only two candidates. The first number represents a vote for a candidate in the Presidential Election, the second number represents a vote for a candidate in the Vice-Presidential Election, the third number is for the Secretary Election, and the fourth integer is a vote for the Treasurer Election.
The first number on each line will either be a 1 or a 2, the second number on that line a 3 or a 4, the third a 5 or a 6, the fourth a 7 or a 8. Each number encountered represents one vote for the corresponding candidate. The key, for tallying votes is as follows:
Presidential Race
1 Cedric Diggory
2 Harry Potter
Vice-Presidential Race
3 Hermione Granger
4 Vincent Crabbe
Secretary Race
5 Luna Lovegood
6 Susan Bones
Treasurer Race
7 Draco Malfoy
8 Neville Longbottom
Your program needs to tally the votes for each candidate, then print out each election, along with each candidates name, the total votes they received, and the percentage of the total votes received. The winner should be printed first (with the word WINNER on that line), followed by the loser of the race on the next line.
Several test files (named votesimple.txt, votes1.txt and votes2.txt) have been provided on Canvas. Also, Ive included the correct results from sample runs using these files below.
SAMPLE RUNS:
1. For votesimple.txt
Presidential Election Winner:
Cedric Diggory - 3 votes - WINNER (60%)
Harry Potter - 2 votes - (40%)
Vice Presidential Election Winner:
Vincent Crabbe - 4 votes - WINNER (80%)
Hermione Granger - 1 votes - (20%)
Secretary Election Winner:
Luna Lovegood - 3 votes - WINNER (60%)
Susan Bones - 2 votes - (40%)
Treasurer Election Winner:
Draco Malfoy - 4 votes - WINNER (80%)
Neville Longbottom - 1 votes - (20%)
2. For votes1.txt
Presidential Election Winner:
Cedric Diggory - 5784 votes - WINNER (50.2957%)
Harry Potter - 5716 votes (49.7043%)
Vice Presidential Election Winner:
Hermione Granger - 8253 votes - WINNER (71.7652%)
Vincent Crabbe - 3247 votes (28.2348%)
Secretary Election Winner:
Luna Lovegood - 8281 votes - WINNER (72.0087%)
Susan Bones - 3219 votes (27.9913%)
Treasurer Election Winner:
Neville Longbottom - 5770 votes - WINNER (50.1739%)
Draco Malfoy - 5730 votes (49.8261%)
3. For votes2.txt
Presidential Election Winner:
Harry Potter - 7634 votes - WINNER (76.34%)
Cedric Diggory - 2366 votes (23.66%)
Vice Presidential Election Winner:
Hermione Granger - 7739 votes - WINNER (77.39%)
Vincent Crabbe - 2261 votes (22.61%)
Secretary Election Winner:
Luna Lovegood - 7867 votes - WINNER (78.67%)
Susan Bones - 2133 votes (21.33%)
Treasurer Election Winner:
Draco Malfoy - 7732 votes WINNER (77.32%)
Neville Longbottom - 2268 votes (22.68%)
Given Numbers for votesimple.txt sample run:
votesimple.txt
1 4 5 8
2 3 5 7
1 4 6 7
2 4 5 7
1 4 6 7
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