Implement an expanded version of the HPAir problem. In addition to the “from” and “to” cities, each line of input contains a flight number (an integer) and the cost of the flight (an integer). Modify the HPAir program so that it will produce a complete itinerary for each request, including the flight number of each flight, the cost of each flight, and the total cost of the trip.
For example, the input files could appear as
cityFile: | Albuquerque Chicago San Diego | |||
flightFile: | Chicago, | San Diego | 703 | 325 |
Chicago, | Albuquerque | 111 | 250 | |
Albuquerque, | Chicago | 178 | 250 | |
requestFile: | Albuquerque, | San Diego | ||
Albuquerque, | Paris | |||
San Diego, | Chicago |
For tiiis input, the program should produce the following output:
Request is to fly from Albuquerque to San Diego.
Flight #178 from Albuquerque to Chicago Cost: $250
Flight #703 from Chicago to San Diego Cost: $325
Total Cost ............. $575
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.
When the nonrecursiveisPath method finds a sequence of flights from the origin city to the destination city, its stack contains the corresponding path of cities. The stumbling block to reporting this path is that the cities appear in the stack in reverse order; that is, the destination city is at the top of the stack and the origin city is at the bottom. For example, if you use the program to find a path from cityP to cityZ in Figure 7-10, the final contents of the stack will beP-W-T-Z, withZ on top. You want to display the origin cityP first, but it is at the bottom of the stack. If you restrict yourself to the stack operations, the only way that you can write the path in its correct order is first to reverse the stack by popping it onto a temporary stack and then to write the cities as you pop them off the temporary stack. Note that this approach requires that you process each city on the path twice.
Evidendy a stack is not the appropriate ADT for the problem of writing the path of cities in the correct order; the appropriate ADT is a traversable stack. In addition to the (standard stack operations,isEmpty,push, pop, andpeek, a traversable stack includes the operationtraverse. This operation begins at one end of the stack andvisits each item in the stack until it reaches the odicr end of the stack. For this project, you wanttraverse to begin at the bottom of the stack and move toward the top.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.