G22.2110-001  Programming Languages

Homework 7 -- Due July 21

 

For this homework you will write – you guessed it – another electronic voting system.

 
You will be using Ada again, and you can modify the system you wrote for assignment 2. This time, the system will be multitasking and will use exceptions to handle problems.

  1. Create 1 server task, which maintains a count of all of the votes and enforces the rules against voting twice, etc. The server should accept votes from a client, and create a separate task to handle each vote. You must ensure that the tasks cannot interfere with each other when updating shared data, such as vote counts.
  2. Create at least 3 client processes each of which sends a stream of votes to the server. You can read the vote data from files, or embed it in the program (each client should use different data.)
  3. Your program should handle problems such as a candidate index out of range by throwing an exception and handling it appropriately.
  4. Your server should generate a trace or log showing what it is doing, e.g., “recording a vote for candidate X by voter Y from client task N”. Be sure to record messages indicating problems.
  5. Your main program should wait until all of the tasks have finished, and then print the total number of votes from each client, the total number of votes for each candidate, and the total number of votes rejected. (The server totals should match the client totals, if they don't you probably have a race condition). 

 
You don’t have to worry about displaying a list of candidates for this assignment, since the voting will be done automatically by your client tasks.

 
You must turn in the following:

  1. A listing of your source code
  2. A trace of running your program that shows
    1. Successful votes
    2. Handling of a candidate index out of range
    3. Handling of a voter attempting to vote twice from different clients.
  3. An email, to Zilin,  containing your source code, any data files you used, and a compiled executable