Homework 3
FAQ now available
This assignment will involve writing a more complex program in Perl, requiring the use of user-defined subroutines, references, and multi-dimensional structures. Knowledge gained from previous weeks, such as sorting, will also be required.
Create a voter polling system. This system will be used to poll registered voters in your area for upcoming elections (school, local, state, national, or other).
Your system must contain the following abilities:
- Add New Voter
- Prompt for the new voter's required information: name, date of birth, and address.
Read this information in. Reject the voter if the voter's age is less than 18 years.
*
Then prompt for optional information: party affiliation, in which years the voter actually voted, and for which candidate that voter voted for in that year. This information is optional. The voter may choose not to give a party affiliation, or a voting history. Even if the voter gives the years of voting, he/she is not required to give the candiate for whom he/she voted. - Poll Voter
- Prompt for the voter's name. If that voter is in the system, prompt the user for which candidate for whom the voter intends to vote. The voter may choose not to give this information. The voter may also be "undecided".
- Print Voter info
- Prompt for the voter's name. If that voter is in the system, print all known information about the voter - name, DOB, address, party affiliation, voting history, and voting intent. Keep in mind not every voter will have all pieces of this information available. For voting history, show the history sorted by year, earliest to latest.
- Show Voter Summary
- Prompt if you want the voters sorted by: name, age, party or voting intent. Then print a list of all voters, with just those four pieces of infomation, sorted by the desired criterion. In all cases, fall back to the voters' names if the sort criterion are equal.
- Show poll results
- Display the following polling information:
- Total voters voting for each candidate
- Total voters for each candidate, separated by party affiliation.
- Total voters for each candidate, broken down by number of previous votes
- Save Data
- Prompt for a file name. Save all current collected data to this file.
- Load Data
- Prompt for a file name. Retrieve all data from this file and load it into your system.
Your program should operate in a continuous loop. At the start of each loop, print out a main menu, listing each of the available options. Once the selection as been made, carry out the selected functionality, and return to the main menu. The program should end only when the user selects a menu option for "exit"
If at any point the user makes an incorrect selection (ex, menu choice that doesn't exist, invalid voter name, invaild voter age, etc) print out an appropriate warning message and return to the main menu.
* Yes, I know that in the real world, you can register to vote if you'll be 18 by the next election, not necessarily at the time of registration. This isn't the real world.Notes
- You may assume no two voters have the same name.
- The required format for date of birth and address is entirely up to you.
- The required format for the datafile is up to you. Only your program will ever read or write this file. It need not be human-readable.
- You should, in fact, look into the Storable module (
perldoc Storable) for assistance with saving and loading.
Structural Requirements
While, in general, I dislike making requirements about the structure or the format of your programs, the realities of the academic environment occasionally force me to do just that. In this case, I do need to make sure you have learned how to properly use subroutines and multi-dimensional structures. Therefore, I impose two requirements:
- Your code must make "good use" of at least one multi-dimensional structure. "Good use" means that the structure must be an integral part of your program. You may not simply declare a 2d array and then never use it. Your structure may be an array of arrays, array of hashes, hash of arrays, hash of hashes, array of objects, or hash of objects. It may also be more than 2 dimensions.
- All of the required abilities must have their own subroutines in your code. You may prompt for required information and pass it to the subroutines, or you may have the subroutines do the prompting, but the main body of work of each of your program's abilities must be in a subroutine. You may choose to have more subroutines (ie, helper functions).
Grading Criteria
| New Voter | 15 |
|---|---|
| Poll Voter | 10 |
| Print Voter Info | 10 |
| Show Voter Summary | 15 |
| Show Poll Results | 20 |
| Save Data | 5 |
| Load Data | 5 |
| No Warnings | 5 |
| Error Checking/Handling | 5 |
| Code Style | 5 |
| output Style | 5 |
Penalties
| Late (up to 14 hours) | 20 points |
|---|---|
| Late (more than 14 hours) | 100 points |
| Compilation errors | 50% |
| No Multi-dimensional structure | 20 points |
| Failure to use subroutines | 20 points |
No Warnings
There should be no Perl-generated warnings displayed when your program runs. You should, of course, display an appropriate warning to the user when he/she does something wrong.
Error Checking/Handling
Your program should never crash due to bad input from the user. The ONLY way for your program to end is by the user's selection of "Exit" from the main menu. All bad input - including but not limited to duplicate voter name, invalid voter name, invalid voter age, invalid date of birth format - should result in an appropriate warning message and send the user back to the main menu.
Code Style
Your code must be readable to a human being. Most important are: Explanatory
(but not overabundant) comments, meaningful variable names, and consistent indentation.
See perldoc perlstyle for tips to writing well-styled code.
Output Style
The output written to the screen must be readable by a human being. Output should be labeled and separated by appropriate white space.
Keep in mind your datafile does NOT need to be human-readable. The format is of your choosing.
Submission Instructions
To submit, log on to solaris.remote.cs.rpi.edu and run the program
~lallip/public/submit.pl and follow the prompts. If you choose to
write a class module, make sure you submit both your .pl and your .pm file(s) in
each submission. You may submit infinite times, only the last submission will
be graded.
Your final submission is due by 11:59:59pm Wednesday, March 24, 2010. It will be accepted up to 14 hours later at a deduction of 20 points.
