GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Dec-2008, 20:24
mxb1145 mxb1145 is offline
New Member
 
Join Date: Oct 2008
Posts: 3
mxb1145 is on a distinguished road

Shortest Path for Airport


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.
CPP / C++ / C Code:
#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;
}
  #2  
Old 16-Dec-2008, 06:28
nostaque nostaque is offline
New Member
 
Join Date: Oct 2008
Posts: 19
nostaque will become famous soon enough

Re: Shortest Path for Airport


Quote:
I know there is a problem with the swap function

To reflect the change, you need to send parameters as reference
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help - Shortest Path Problem mas287 C Programming Language 5 18-Jun-2008 02:59
Shortest Path Program. bomber456 C++ Forum 1 05-Mar-2007 12:32
Input from a file, declare the path of the file feicobain C++ Forum 1 19-Feb-2007 02:00
shortest path algorithm and file saving Pandiani C++ Forum 10 17-Jul-2006 10:46
PATH points to nonexistent dir wavez C Programming Language 5 06-Oct-2004 03:04

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:44.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.