0% found this document useful (0 votes)
22 views

Flight Graph

The document contains C++ code to represent a flight route as a graph and adjacency matrix. It defines a Flight class with methods to get the graph from user input and display the adjacency matrix. The main function uses a menu to allow getting the graph or displaying the matrix repeatedly.

Uploaded by

Vaibhav Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Flight Graph

The document contains C++ code to represent a flight route as a graph and adjacency matrix. It defines a Flight class with methods to get the graph from user input and display the adjacency matrix. The main function uses a menu to allow getting the graph or displaying the matrix repeatedly.

Uploaded by

Vaibhav Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

#include<stdlib.h>
#include<string.h>
using namespace std;

class flight
{ int m[10][10],n,i,j;
char ch; string v[20];

public:
void getgraph();
void displaym();
};
void flight::getgraph()
{
cout<<"\n enter no. of cities(max. 20)";
cin>>n;
cout<<"\n enter name of cities";
for(i=0;i<n;i++)
cin>>v[i];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{ cout<<"\n if path is present between city "<<v[i]<<" and "<<v[j]<<" then press
enter y otherwise n";
cin>>ch;
if(ch=='y')
{
cout<<"\n enter time required to reach city "<<v[j]<<" from "<<v[i]<<" in
minutes";
cin>>m[i][j];
}
else if(ch=='n')
{ m[i][j]=0; }
else
{ cout<<"\n unknown entry"; }
}
}

void flight::displaym()
{ cout<<"\n";
for(j=0;j<n;j++)
{ cout<<"\t"<<v[j]; }

for(i=0;i<n;i++)
{ cout<<"\n "<<v[i];
for(j=0;j<n;j++)
{ cout<<"\t"<<m[i][j];
}
cout<<"\n";
}
}
int main()
{ int m;
flight a;

while(1)
{
cout<<"\n\n enter the choice";
cout<<"\n 1.enter graph";
cout<<"\n 2.display adjacency matrix for cities";
cout<<"\n 3.exit";
cin>>m;

switch(m)
{ case 1: a.getgraph();
break;
case 2: a.displaym();
break;
case 3: exit(0);

default: cout<<"\n unknown choice";


}
}
return 0;
}

You might also like