AP CS AB: Lists Project

Due: 29 September 2005

Problem Statement

The person responsible for counting the votes in a recent Washington DC primary election needs some help. Given the recent problems with vote counting across the nation, he is concerned that the old system might cause controversy. As an expert programmer, you have been asked to help develop a new system that will correctly count the votes in a recent election, as well as providing some statistics about the election. Unfortunately, the person you are working for is very busy, and has only provided you with some raw data and told you what you are expected to program. It is your job to figure out a way to finish the tasks before the deadline next Thursday.

Raw data

You have access to a voter database containing the following information:

  • Voter Number
  • Voter’s Name
  • Voter’s Birthday
  • Voter’s Address
  • Voter’s Party Affiliation (Democrat, Republican, Green)
  • An indication whether they voted in the last election (“yes” or “no”)

You also have access to the individual ballots from the election, that contain:

  • Voter Number
  • Voter Name
  • The 2 names of the Green Party candidates for Mayor
  • The Vote for one of these two persons (if applicable*)
  • The 2 names of the Republican candidates for Mayor
  • The Vote for one of these two persons (if applicable*)
  • The 2 names of the Democratic candidates for Mayor
  • The Vote for one of these two persons (if applicable*)
  • The 5 names of the candidates for Superior Court Judge
  • The 3 votes the voter can cast among the 5 candidates
  • The Vote “For” or “Against” the recent tax rate increase

* NOTE: Since this is a primary election, the voter is only supposed to vote for the candidate for Mayor in their own party (as indicated in the voter database).

Assignment

Your assignment is to use your programming skills (in Scheme) to help out with the election counting and to perform some analysis about who voted. As you may have already thought, you will want to form lists with the raw data provided and perform list manipulation in Scheme in order to complete the task.

Part I) Data

The first thing you will have to do is to identify how you will want to represent the data in your program. This part of the assignment is for you to identify and “code” all the data definitions, examples of data, and templates that you will need to complete your tasks. Feel free to add to this section as you get further into the problems if needed.

Part II) Generating Statistics

Aside from the vote counting, you are also supposed to help calculate some statistics about the people voting in this election. Please provide the following answers (by making functions and outputting the result). Use helper functions if necessary.

  1. The total number of voters in this election.
  2. The voter turnout (in percentage form) in this election (total votes / registered voters)
  3. How many individuals were registered to vote, but did not vote in this election (Hint: this is not the same as registered voters minus total votes – see next question.)
  4. How many individuals voted in this election who were not registered to vote.
  5. How many people voted both in the current election as well as in the previous election.

Part III) Counting Votes

Now to the main event… Spend some time thinking about the following problems, and make sure that you use enough sample data to be sure that you have the correct answers.

  1. Determine if the proposed tax rate increase passed or failed.
  2. Determine who won the race in the each of the Mayoral primary races. (Recall that a vote only counts in the election of the party the particular voter is a member of.)
  3. Determine which 3 of the 5 candidates for Judge were voted into office. The 3 winners will have received the three highest vote counts.

Part IV) Taking Invalid Ballots into Account

After doing your initial take on things, you have received additional information on the rules of counting ballots. It turns out that votes can be invalid in some cases and shouldn’t be counted.

  1. Adjust your answers (by creating secondary functions) to Part III numbers 1) and 3) to discount invalid ballots. For the purposes of these elections, an invalid ballot is one where the voter name and number do not match the database of registered voters (disallow ballots of voters who are not registered)
  2. Adjust your answers to Part III number 2) to discount invalid ballots. Not only are the rules from the previous question in effect, but you should also disallow ballots completely if the voter has voted in more than one of the 3 mayoral elections (voted for more than one party).