Assignment 6 -- Due July 14, 2004

G22.2110-001 Programming Languages

This assignment is based on part of your previous assignment in ADA, but this time you will be using C++.

Please turn in in both paper and electronic form. I will collect a printout of your (well-commented) source code and a printout of the log that shows that your program works. You should also email a copy of your source code to the TA, Zilin at

This assignment is loosely based on your previous assignment in ADA, in which you developed an electronic voting system. For this assignment you will write an automatic vote server (only the server) which will:

1)      Handle two kinds of elections: Primary Elections, in which the voter may vote only for candidates of his or her own party, and General Elections, in which the voter may vote for any candidate. You should control which kind of election by using a command line parameter for the server to instantiate a specific election class.

2)      Process several types of messages, where each message is in the form of a string. Some of these messages would come from voting machines, and some would come from Election Administrators. Your program should run in a loop, accepting new messages until it receives an EXIT message. Since you do not have the voting machines (yet), write your program to read messages from a file (“election.msg”) for now, but design your program so that other kinds of sources can be added in the future.

3)      Keep a log of all of the messages it has received during an election along with an indication of whether the message was processed successfully or not, and if not, why not. For example, if a voter attempts to vote twice, you should display a message to that effect.



The first 4 characters determine the type of the message: VOTE,  EXIT, etc.

The 5th character is blank and the remainder of the string contains arguments of the form:

<Value> (e.g., -- “VOTE <John Kerry> George Bush>”)

The messages you must handle are:

VOTE <Candidate> <Voter>  

Records a vote for the specified candidate by the specified voter. The same rules apply as before, i.e. – no one can vote twice.

RGST  <Voter> <Party>

Registers a new voter by adding him or her to the rolls

CAND  <Candidate> <Party>

Adds a new candidate to the list of candidates

LIST  <Voter>

Lists the names of the candidates for this voter


Lists the tally of the number of votes for each candidate



RESeTs the tally for all candidates to zero and resets the voted property for each voter



Prints out a record of all of the messages and, if the message was not successful (say because someone tried to vote twice) an indication of why it was not.  



Terminates execution of the server.