Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

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%)

For votesimple.txt use:

1 4 5 8 2 3 5 7 1 4 6 7 2 4 5 7 1 4 6 7

Using this flowchart

clear image of flowchart

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting and Reporting

Authors: Barry Elliott, Jamie Elliott

18th edition

1292162406, 978-1292162409

More Books

Students also viewed these Programming questions