I'm working on a program that finds the shortest path for a file of flights. I'm having a hard time figuring out how to store the information so I can build an adjency table. The file I'm reading gives me the source airport(3 letter char), destination airport(3 letter char), mileage, and cost. This is what I have so far, I created a struct class of Airports and I'm storing all the info in an array of Airports. But it's giving me problems when I try to compile. I know there is a problem with the swap function but I'm not sure how to fix it. Help would be appreciated.
#include <iostream>
#include <fstream>
const int INFINITY = 10000000;
void swap(Airports , Airports);
using namespace std;
struct Airports{
char Name[4];
char Connection[4];
int Mileage;
int Cost;
};
int main ( )
{
cout << "-------------------------------" << endl;
// Variables
string name;
ifstream file;
char source[4], destination[4];
int mileage, cost;
Airports flights[15];
cout << "Please enter the file that contains the flight5tf5 information: ";
cin >> name;
file.open(name.c_str());
if(!file.good( ))
{
cout << "File is not what was expected. Enter a new file, or check file name";
}
else
{
int sum = 0;
while(!file.eof())
{
for( int i = 0; i < 15; i++)
{
file >> source >> destination >> mileage >> cost;
flights [i] = new Airports(source, destination, mileage, cost);
count++;
}
while(sum < count)
{
sum++;
for (int i = 0; i < count; i++)
{
if (flights[i].Name > flights[i+1].Name)
{
swap(flights[i], flights[i+1]);
}
}
}
}
cout << "Direct Flights" << endl;
cout << "Source" << "\t" << "Dest" << "\t" << "Mileage" << "\t" << " Cost" << endl;
for (int j= 0; j < count; j++)
{
cout << flights[j].Name << "\t" << flights[j].Connection << "\t " << flights[j].Mileage << "\t $" << flights[j].Cost << endl;
}
}
system("PAUSE");
return 0;
}
void swap(Airports x, Airports y)
{
Airports temp;
temp = x;
x = y;
y = temp;
}