C++ PROBLEM Complete the solution to the HPAir problem. The input to the program
ID: 671752 • Letter: C
Question
C++ PROBLEM
Complete the solution to the HPAir problem. The input to the program consists of three text fi les, as
follows:
cityFile Each line contains the name of a city that HPAir serves. The names are in
alphabetical order.
flightFile Each line contains a pair of city names that represent the origin and destination
of one of HPAir’s fl ights.
requestFile Each line contains a pair of city names that represent a request to fl y from
some origin to some destination.
You can make the following assumptions:
• Each city name contains at most 15 characters. Pairs of city names are separated by a comma.
• HPAir serves at most 20 cities.
• The input data is correct.
For example, the input fi les could appear as
cityFile: Albuquerque
Chicago
San Diego
flightFile: Chicago, San Diego
Chicago, Albuquerque
Albuquerque, Chicago
requestFile: Albuquerque, San Diego
Albuquerque, Paris
San Diego, Chicago
For this input, the program should produce the following output:
Request is to fly from Albuquerque to San Diego.
HPAir flies from Albuquerque to San Diego.
Request is to fly from Albuquerque to Paris.
Sorry. HPAir does not serve Paris.
Request is to fly from San Diego to Chicago.
Sorry. HPAir does not fly from San Diego to Chicago.
Begin by implementing the ADT fl ight map as the C++ class Map . Use the stack version of isPath . Because
getNextCity is the primary operation that the search algorithm performs on the fl ight map, you should choose
an implementation that will effi ciently determine which cities are adjacent to a given city. If there are n cities
numbered 1, 2, . . ., n , you can use n chains of linked nodes to represent the fl ight map. You place a node on list
i for city j if and only if there is a directed path from city i to city j . Such a data structure is called an adjacency
list; Figure 6-14 illustrates an adjacency list for the fl ight map in Figure 6-6 . Chapter 20 discusses adjacency
lists further when it presents ways to represent graphs. At that time, you will learn why an adjacency list is a
good choice for the present program.
To simplify reading the input text fi les, defi ne a class that includes the following methods:
// Returns a name from the next line in a text file.
+getName(): string
// Returns a pair of two names from the next line in a text file.
+getNamePair(): Pair
Explanation / Answer
1. The figure is missing, so adjacenccy list implementation couldn't be possible.
class FileFunctions
{
public string getName()
{
string line;
ifstream readFile ("cityFile");
if (readFile.is_open())
{
while (! readFile.eof() )
{
getline (readFile,line);
return line;
readFile.close();
}
}
}
public string[] getPair()
{
string line;
string token[];
ifstream readFile ("flightFile");
if (readFile.is_open())
{
while (! readFile.eof() )
{
getline (readFile,line);
token = strtok (str,",");
readFile.close();
return token;
}
}
}
};
class flightMap
{
string flightStack[100]; //declaring a String array of flightNames;
string cityStack[100]; //declaring a String array of cityNames;
public string getNextCity()
{
if(cityStack.top()!=null)
{
return cityStack.top();
}
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.