CS 230 Fall 20046 Assignment
12 – Parallel Arrays 100
points
Assigned: 11/29/2006
Due: 12/08/2006 at the start of class.
Pre-Lab (Do Before Lab): Bring a new disk. Plan out
tasks, objects, and events needed for program. Plan out major pseudocode
Main Assignment:
E-Vote
Inc is revising their program to cash in on the electronic voting era. Your
program (though still simplified) has a major improvement over your previous
version – you can see a summary of results – with number of votes for each candidate
and displaying the winner. Your program still only deals with voting for one
office. The program should get from a file (voters.txt) a list of voter Ids and
voter names, and display them in a list box. The program should also get from
another file (candidates.txt) a list of candidates and put them in an array of
candidates, as well as a list box or combo box. There should also be a parallel
array with the number of votes received (which should start out as zero!!! J
). When the user selects a voter from the voter list box, their info should be
displayed in read-only text boxes or in labels. When a user then selects the
candidate from the combo box (or list box) AND selects a “Vote” button, acknowledge
the vote, write the vote (voterId, name and candidate selected) to a
comma-delimited text file for later auditing (add it to those already in the
file), update the number of votes received for the appropriate candidate and remove
the voter from the list box of eligible voters. Do NOT allow somebody to vote
if they have not BOTH signed in AND picked a candidate. (DO NOT have the vote
recorded immediately upon selection in the combo box in case of an inadvertent
click). Provide the vote capability, a summary results capability and an exit
capability.
Hand in:
- Floppy disk with an entire folder containing all files
related to the project. Please set the name of the project to
something other than the default name (WindowsApplication1, …). It
is helpful if you use a name that identifies you as well as the assignment
(e.g. yourlastname assignment 12). Use Windows to copy the whole folder,
instead of trying to “Save As”.
- Print out of your code.
Task Details
- You must
use the filenames specified above, so I can easily test a bunch of
different programs in a row. Sample files are provided on the assignments
page of my www site. In the spirit of thorough testing of programs, you
should try other versions of files as well.
- We are still not handling secure access – voters are just
selecting themselves off a list.
- Your program will use parallel arrays of candidates and of
the number of votes they receive. You must do this, it is
what we are exercising in this assignment.
- DO NOT try to do this using classes. We have not
covered them sufficiently yet!!!!!
- In defining the arrays, you can assume that there will be
no more than 10 candidates for a position.
- Display voter name and
ID for selected voter in separate controls. You will need to separate the
info using string capabilities.
- For validation, ensure
when the vote button is selected that the voter and candidate have both
already been selected.
- After the vote button
has been recorded, give the voter some kind of confirmation (e.g. a
msgbox) and automatically clear the voter and candidate choices.
- As in Assignment 9:
- Remove the voter from
the list box using listboxname.Items.Remove(itemtoremove) where
itemtoremove is a string to be removed.
- When you remove the
voter from the voter listbox, that will result automatically in a change
to the item selected property of the list box, triggering an event. Your
event procedure needs to protect against that crashing your program (the
selected item will be set to “nothing” which is a built in value – typing
it in (nothing) you should see it turn blue. To test if a selected item
is nothing you can do a test checking: listboxname.SelectedItem is
Nothing.
- Summary results
capability should provide BOTH: a candidate by candidate list with
candidate name and number of votes received (in a rich text box?) AND an
indication of the winner’s name (in a read only text box or label?).
Miscellaneous:
- You must turn
on Option Strict and Option Explicit
- We have covered
procedures and functions – I recommend that you continue to use them
whenever helpful (e.g. extracting a line of text from the text in a file).
·
MAKE SURE YOUR PROGRAM WORKS!
·
Put YOUR NAME, e-mail
address, date, and purpose of the program in comments at the beginning of the
program.
·
You MUST include comments
that explain your program in order to get full credit.
·
Remember to use meaningful
variable names, and indent to show the structure of the program (VB usually
does this correctly).
·
Put your name on the
form as a Label or as part of the form title.
·
Try to use good user
interface design. Make clear what user needs to do and what the answers mean.