Question
C++ Flight Program Code Needs To Be Fixed Below is a description of What Program Does - Bottom of page has my code -------------------------------------------------------------------------------------------------------- I
C++ Flight Program
Code Needs To Be Fixed
Below is a description of What Program Does - Bottom of page has my code
--------------------------------------------------------------------------------------------------------
I MUST USE GRAPHS
For the Graphs, Verticies Weights and Edges are stored in below load.txt file
These vertices, edges and weights are stored in the text file named load.txt file at the bottom. When the program starts, it will use the load.txt file to load the vertices, edges and weights into your program.
--------------------------------------------------------------------------------------------------------
Flight Types (Files at bottom)
Connected Flights:
A direct connection means you can fly from the departure city to the destination city without having to first fly through another city. For this type of connection, you list the departure city, the destination city, and the distance between the two cities.
Through Flights (Listed Below):
A through connection means you can fly from the departure city to the destination city, but you first have to fly to at least one other city. For this type of connection, you list the departure city, the destination city, each city between the departure city and the destination city which is part of the connection, and the total distance between the departure city and the destination city.
--------------------------------------------------------------------------------------------------------
Program Startup
As mentioned above, when the program starts, it will use the load.txt file to load the vertices, edges and weights into the graph. The program then will display a menu, and prompt the user to enter a choice:
1. Choose departure city 2. Exit
You may assume the user enters 1 or 2. No input validation is required.
If the user chooses 2. Exit, then the program ends.
Program lists Departure Cities, and user chooses
If the user choose 1. Choose departure city, then the program lists the cities. The cities don't have to be listed in any particular order. However, an ascending letter or number should be to the left of each city so the user can use that letter or number to choose a city. For example:
1. Los Angeles 2. Beijing 3. San Diego (and so on) Choose city:
or
A. Los Angeles B. Beijing C. San Diego (and so on) Choose city:
You may assume the user enters a valid number or letter; no input validation is required.
--------------------------------------------------------------------------------------------------------
Program lists Destination Cities, and user chooses
Once a user chooses a city, then the program displays "Destination cites" followed by all of the cities except the departure city. Again, the cities don't have to be listed in any particular order, but an ascending letter or number should be to the left of each city so the user can use that letter or number to choose a city.
You again may assume the user enters a valid number or letter; no input validation is required.
--------------------------------------------------------------------------------------------------------
If no connection
Once the user chooses a destination city, if there is no direct or through connection between the departure and destination cities, then the program will output:
No connection between [name of departure city] and [name of destination city] Press any key to return to menu.
After the user presses the any key (we'll assume the user has an any key on their keyboard :-), then the menu which displayed at the program startup (1. Choose departure city 2. Exit) will re-display and the program will continue as stated above.
--------------------------------------------------------------------------------------------------------
If connection, direct connection?
If there is some connection between the departure and destination cities (See load.txt and connected cities notes below) ... the next issue is whether there is a direct connection between the departure and destination cities.
If there is no direct connection between the departure and destination cities (in other words, only a through connection), then the program will output:
No direction connection between [name of departure city] and [name of destination city]
Then the program will output the information in the next section (If connection is a through connection?).
If there is a direct connection between the departure and destination cities (there presumably only would be one), then the program will output:
Direct connection between [name of departure city] and [name of destination city]
Then the program will output the information in the next section (If connection, through connection?).
--------------------------------------------------------------------------------------------------------
If connection, through connection?
If there is no through connection between the departure and destination cities (in other words, only a direct connection), then the program will output:
No through connection between [name of departure city] and [name of destination city] Press any key to return to menu [after which the menu displayed at program startup is re-displayed]
If there is at least one through connection between the departure and destination cities, then the program will output all through connections (there may be more than one) in ascending order of distance, listing the intermediate cities, as follows:
Through connection between [name of departure city] and [name of destination city] via [list name or names of cities in between] - [number of miles] miles
After this listing, the program prompts the user to "Press any key to return to menu", after which the menu displayed at program startup is re-displayed.
NEEDED FILES:
//load.txt file
//Direct Connections Beijing, Los Angeles, 6260 Los Angeles, Maui, 2490 Maui, San Diego, 2540 Los Angeles, San Diego, 200
//Connecting Cities Notes
//Through Connections Maui , Los Angeles, Beijing San Diego, Las Angeles, Beijing
************************************************************
Below is some code i have but its not working. If you could fix it that would work also.
************************************************************
#include
using namespace std;
int main() {
string a[] = { "1.Los Angeles ", "2.Beijing", "3.San Diego", "4.Maui" };
cout << "1. enter filght " << "2. exit "; int ch, i; cin >> ch;
switch (ch) {
case 1:
{ for (i = 0; i<4; i++) {
cout << a[i] << endl; } int s; cout << "choose departure city number "; cin >> s; cout << "your choice is " << a[s - 1] << endl;
for (i = 0; i<4; i++) { if (i == s - 1) continue; cout << a[i] << endl; }
int d; cout << " choose destination city "; cin >> d;
cout << " your destination is " << a[d - 1];
cout << " remaining cities are ";
for (i = 0; i<4; i++) { if (i == s - 1 || i == d - 1) continue; cout << a[i] << endl; }
connection(int s, int d, int w); //check this program by first commenting this line
}
case 2: exit(0);
}
return 0; }
//comment even this function if you are commenting prototype in main void connection(int s, int d, int w) {
ifstream infile; infile.open("load.txt"); while (!infile.eof) // To get you all the lines. { getline(infile, u, v, w);
} int i; for (i = 0; i<4; i++) { while (!infile.eof) // To get you all the lines. { getline(infile, u, v, w);
if (u == s - 1 && v == d - 1) cout << " direct connection from" << a[s - 1] << "to " << a[d - 1] << "exists with" << w << "miles"; else cout << " no connection exists"; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started