
The George Washington University
School of Engineering and Applied Science
Department of Computer Science
CSci 131 -- Algorithms and Data Structures I
Project #6 -- Due Date: December 7, 2000
From your work on previous projects, you now have a generic table handler
package Tables_Generic_List that uses linked lists to represent
the tables. In this project you will use this package with a completely
different kind of client.
Requirements
An imaginary nation called the Entangled States of Fredonia (ESF) consists
of three states, Confusion, Glory, and Grace. Each state has five counties,
which are always called County1, County2, County3, County4, and County5.
(The Fredonians are not very creative in naming their counties, are they?)
The ESF has hired you to prepare a program to process the results of
its Presidential election. The main Presidential candidates are Groucho
and Harpo; there are two minor candidates, Chico and Zeppo. The candidate
with the most votes wins. There is no electoral college. (Things are bad
enough as it is, in Fredonia!)
ESF officials want you to develop an external database consisting of
one file for each state, and an internal one consisting of one table for
each state. (Each state table will thus have up to five nodes, one for
each of its counties.) Each day, an external file of voting reports is
processed and the database is updated.
Here is an example voting report from a given county:
Confusion, County3, 20, 300, 0, 5
where the numbers represent the votes for Groucho, Harpo, Chico, and
Zeppo, in that order. The election reporting is a bit disorganized and
recounts are common, so the numbers keep changing and a given county can
thus send many reports.
Furthermore, the ESF officials are afraid of anything related to television
(including computer monitors), so your contract requires a batch program.
Each time this program is run, it does the following steps:
-
Restore the internal database from the external files
-
Read the latest set of voting reports from the file, processing each report
as it is read.
-
If a report is the first one from a given county, it is added to the appropriate
table. If this county is already in the table for that state, the new report
replaces the old one.
-
Write a summary of the results into a file. The results will show the vote
totals for each candidate in each state, and the overall national totals
for each candidate.
-
Save the internal database back into its three files.
Implementation
You will find the packages Fredonia and Fredonia.IO in
the programs131 directory. These will set up the basic voting
report record and the input/output operations. This project requires NO
change to the table package or to the backup child. These packages are
already tested; leave them alone! Your task is just to write the client
program.
-
Suppose your client program contains a table package instance ElectionTables.
In this client program, instead of declaring one table variable, just declare
TYPE ElectionDatabase IS ARRAY(Fredonia.States) OF ElectionTables.TableType;
Election: ElectionDatabase;
Given a category OneState, then Election(OneState)
selects the appropriate table. Naturally you can loop through all the tables
easily: FOR WhichState IN Fredonia.States LOOP, etc.
-
The client program must deal with the multiple tables. For example, your
client will carry out an insertion operation by determining the state of
the new record, then calling ElectionTables.Insert with the appropriate
table parameter.
-
This client will contain no deletions, only insertions and replacements.
We will also provide 4 days' voting report files, tuesday.dat,
wednesday.dat,
thursday.dat,
and friday.dat for you to use. Your program should read the name
of the report file from a 1-line file election.cfg. This scheme
is a realistic portrayal of a real-world batch update of a database system.
Call the 3 state files confusion.dat, glory.dat, and
grace.dat.
You are to run the client program 4 times to simulate 4 days' processing.
After each run, cat the contents of the 3 state files and the results file
into your turnin.