Problem Statement:-
There are flight paths between cities. If there is a flight between city A and city B then there is an edge between the cities. The cost of the edge can be the time that flight takes to reach city B from A, or the amount of fuel used for the journey. Represent this as a graph. The node can be represented by airport name or name of the city. Use adjacency list representation of the graph or use adjacency matrix representation of the graph. Justify the storage representation used.

Code :-

```//============================================================================
// Name        : FlightGraph.cpp
// Author      : VNKDJ5
// Version     : 2.0
// Description : There are flight paths between cities. If there is a flight between
//    city A and city B then there is an edge between the cities. The cost of the edge can
//    be the time that flight takes to reach city B from A, or the amount of fuel used for
//    the journey. Represent this as a graph. The node can be represented by airport name
//    or name of the city. Use adjacency list representation of the graph or use adjacency
//    matrix representation of the graph. Justify the storage representation used.

//============================================================================

#include <iostream>
#include<iomanip>
using namespace std;
const int MAX=30;
class node
{
node *next;
string city;
int timeCost;
public:
friend class graph;
node()
{
next=NULL;
city="";
timeCost=-1;
}
node(string city,int weight)
{
next=NULL;
this->city=city;
timeCost=weight;
}
};
class graph
{
int n;
public:
graph(int num)
{
n=num;
for(int i=0;i<n;i++)
}
void insert(string city1,string city2,int time);
void insertUndirected(string city1,string city2,int time);
int getindex(string s1);
void outFlights();
void inFlights();

};
void graph::inFlights()
{
int count[n];
for(int i=0;i<n;i++)
count[i]=0;
cout<<"====== In degree =========\n";
for(int i=0;i<n;i++)
{
cout<<"\n"<<setw(8)<<"Source"<<setw(8)<<"Destin."<<setw(8)<<"Time";
for(int j=0;j<n;j++)
{
while(p!=NULL)
{
{
count[i]=count[i]+1;
}

p=p->next;
}
}
cout<<"-------------------------------------\n";
}

}
void graph::outFlights()
{
int count;
for(int i=0;i<n;i++)
{
count=0;
cout<<"\n"<<setw(8)<<"Source"<<setw(8)<<"Destin."<<setw(8)<<"Time";
if(p==NULL)
{
}
else
{
while(p!=NULL)

{
count++;
p=p->next;
}
}
cout<<"\nNo. of flights: "<<count<<endl;;
cout<<"-------------------------------------\n";
}
}
int graph::getindex(string s1)
{
for(int i=0;i<n;i++)
{
return i;
}
return -1;
}
void graph::insert(string city1,string city2,int time)
{
node *source;
node *dest=new node(city2,time);

int ind=getindex(city1); //for getting head nodes index in array
else
{
while(source->next!=NULL)
source=source->next;
source->next=dest;
}
}
void graph::insertUndirected(string city1,string city2,int time)
{
node *source;
node *dest=new node(city2,time);
node *dest2=new node(city1,time); //for second flight insertion

int ind=getindex(city1); //for getting head nodes index in array
int ind2=getindex(city2);
{
}
else if(head[ind]==NULL && head[ind2]!=NULL) //no flight in first list but flight in second list
{
while(source->next!=NULL)
source=source->next;
source->next=dest2;
}
{
while(source->next!=NULL)
source=source->next;
source->next=dest;
}
else
{
while(source->next!=NULL)
source=source->next;
source->next=dest;

while(source->next!=NULL)
source=source->next;
source->next=dest2;

}
}
{
string city1,city2,tmpcity;
int fcost;
int flight;
cout<<"\nENter City Details:\n ";
for(int i=0;i<n;i++)
{
cout<<"Enter City "<<i+1<<" ";
cin>>tmpcity;
}
cout<<"\nEnter Number of Flights to insert: ";
cin>>flight;
if(gType==1)
{
for(int i=0;i<flight;i++)
{
cout<<"\nEnter Source:";
cin>>city1;
cout<<"Enter Destination:";
cin>>city2;
cout<<"Enter Time:";
cin>>fcost;
insert(city1,city2,fcost);
}
}
else
{
for(int i=0;i<flight;i++)
{
cout<<"\nEnter Source:";
cin>>city1;
cout<<"Enter Destination:";
cin>>city2;
cout<<"Enter Time:";
cin>>fcost;
insertUndirected(city1,city2,fcost);
//cout<<"\ninserted"<<i+1;
}
}
}
int main() {
int number,choice;
int graphype;
cout<<"0. Undirected\n1.Directed\nEnter Flight data Insertion Type:";
cin>>graphype;
cout<<"\nENter Number of Airport Stations:";
cin>>number;
graph g1(number);
do
{
<<"\n1.Incoming Flights(In degree)"
<<"\n2.Outgoing Flights(Out degree)"
<<"\n3.Exit"
cin>>choice;
switch(choice)
{
case 1:
cout <<"" << endl;
g1.inFlights();
break;
case 2:
g1.outFlights();
break;
default:
cout<<"\nWrong Choice";
}
}while(choice!=3);

// prints

return 0;
}
```
Output :-

```0. Undirected
1.Directed
Enter Flight data Insertion Type:0

ENter Number of Airport Stations:3

ENter City Details:
Enter City 1 pune
Enter City 2 mumbai
Enter City 3 baramati

Enter Number of Flights to insert: 3

Enter Source:pune
Enter Destination:mumbai
Enter Time:100

Enter Source:pune
Enter Destination:baramati
Enter Time:50

Enter Source:mumbai
Enter Destination:baramati
Enter Time:130
1.Incoming Flights(In degree)
2.Outgoing Flights(Out degree)
3.Exit

====== In degree =========

Source Destin.    Time
mumbai    pune     100
baramati    pune      50
Flights to pune = 2
-------------------------------------

Source Destin.    Time
pune  mumbai     100
baramati  mumbai     130
Flights to mumbai = 2
-------------------------------------

Source Destin.    Time
punebaramati      50
mumbaibaramati     130
Flights to baramati = 2
-------------------------------------
1.Incoming Flights(In degree)
2.Outgoing Flights(Out degree)
3.Exit

Source Destin.    Time
pune  mumbai     100
punebaramati      50
No. of flights: 2
-------------------------------------

Source Destin.    Time
mumbai    pune     100
mumbaibaramati     130
No. of flights: 2
-------------------------------------

Source Destin.    Time
baramati    pune      50
baramati  mumbai     130
No. of flights: 2
-------------------------------------
```