PROGRAM #5
Fall 2009
Due: December 4, 2009, 5pm on eLearning
General Guidelines:
There are two problems in this assignment. You have to pick and choose the best suited data structure(s) to implement the respective problems. I expect that you will primarily end up using hash tables and/or union-find. You are also free to use other data structures covered so far in this class. Obviously, the idea is to come up with the implementation that can guarantee the best performance, and the grading will factor that in.
PROBLEM#1 Group Cities By Country
(50 points)
Given a set of n <city, country> pairs, your task is to group & list them by their respective countries. The input will be provided in the form of a comma-delimited text file, in which each line has the format: City name, Country name
Here is an input file for testing purposes.
Your output needs to list all the cities belonging to each country together, as follows:
…
Note: The order in which the cities are listed within a country group is irrelevant. So is the order in which countries are printed.
The program’s API should look like the following.
Class CityGrouper { public: // this function should
allow the user to load an input text file // this function should perform grouping and
print the output }
CityGrouper(string
InputFileName);
void GroupCitiesByCountry();
// other member functions and private data stores
…
Testing: Test your code with the input file provided above. For this you will have to write a main() function.
“Problem1.zip”: should contain the source code and the output of testing in a separate text file.
PROBLEM #2 Group Cities Connected by Air Routes:
(50 points)
You are given a database of flight connections, where an entry <A,B> means there are direct flights from both A to B and B to A.. Two cities are said to be “connected” if there is either a direct connection or a series of connections between them. A typical passenger is interested in answering the following two questions:
Q1) List out all equivalence sets of
cities, such that each set contains all and only those cities that are
connected to one another.
Q2) Given any two arbitrary cities, X
and Y, is there a flight connection between them?
Implement a program that will allow users to answer both queries efficiently. You can assume that the flight database is input in the form of a comma-delimited text file, in which every line lists two cities that have a direct flight between them.
Here is an example input file.
Equivalence Class #1 All
cities connected in this class… Equivalence Class #2 All
cities connected in this class.. …
The output for Q1 should look something like:
The output to Q2 is a YES or NO.
Class CityConnector { public: // this function should allow the user to load
an input text file // this function should compute the eq. classes
and output // this function checks whether two cities are
connected // other member functions and private data
stores … }
The program’s API should look like the following:
CityConnector(string InputFileName);
void ReportConnectedCities();
boolean CheckConnection(string city_1, string city_2);
}
Testing: Test your code with the input file provided above. For this you will have to write a main() function. In this function, call ReportConnectedCities() once and print its output. After that, make a few calls to CheckConnection() doing arbitrary checks to test out if your code is working.
“Problem2.zip”: should contain the source code and the output of testing in a separate text file.
Combined Report for Problems 1 &
2:
In a separate 1-page document (Word or PDF), compile the following two sections:
· Problem 1. Briefly explain your choice for the data structure.
· Problem 2. Briefly explain your choice for the data structure.
FINAL CHECKLIST FOR SUBMISSION:
___ Cover sheet
___ Problem1.zip
___ Problem2.zip
___ Report.doc or Report.pdf
___ All the above zipped into another folder archive called Program4<YourLastName>.zip for submission on eLearning.