The file /u2/stone/courses/fundamentals/exercises/votes.dat contains a record of the ballots cast by a community, voting on a number of local propositions. Your job is to tally the votes on each proposition and report the total number of valid ballots cast in favor of and against each one.
Each voter's ballot is represented by a single line of the file. Columns 1 to 4 of the line are occupied by a four-digit numeral (in the range from 0000 to 9999) identifying the voter who cast the ballot. Column 5 is always a space. On the rest of the line, there will be zero or more vote indicators, each consisting of a two-digit numeral (in the range from 10 to 99), identifying the proposition, and a plus sign or a minus sign, indicating whether the vote was cast for or against the proposition. Adjacent vote indicators are separated by one or more spaces. Thus a typical ballot line might look like this:
4727 11+ 13+ 14- 15+indicating a vote for propositions 11, 13, and 15, and against proposition 14, or like this:
8607 14+ 72+ 53-indicating a vote for propositions 14 and 72 and against proposition 53.
A ballot line that does not begin with a four-digit numeral is an error and should be discarded. A ballot line that begins with a four-digit numeral, but does not follow the prescribed form, is a spoiled ballot and should not be counted for or against any of the propositions. Finally, if two or more of the ballot lines in the file begin with the same voter identification number, all of them are fraudulent ballots, and none of them should be counted for or against any of the propositions. Even if all but one of a group of ballot lines beginning with the same voter identification number is spoiled, the remaining one is still fraudulent and should not contribute to the vote tally.
The report of the results should begin with a count of the number of ballot lines that were found to be valid, the number that were errors (as defined in the previous paragraph), the number of spoiled ballots, and the number of fraudulent ballots. Note that the last two categories are not mutually exclusive. It should then give the results for each proposition on which valid ballots were cast, in ascending numerical order, listing the number of votes for and against each one and the number of valid ballots that did not indicate any vote on that proposition. If some proposition number does not appear at all on any valid ballot, the report should simply skip over that proposition number.
Here's how the first few lines of such a report should look:
Valid ballots cast: 3177 Errors: 0 Spoiled ballots: 3 Fraudulent ballots: 12 Proposition #10: 1236 for 918 against 1023 not voting Proposition #11: 1448 for 1466 against 263 not votingThis assignment will be due on December 9, 1996.