-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prac7-C14.cpp
51 lines (46 loc) · 1.27 KB
/
Prac7-C14.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Experiment 14 : 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 take 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 the airport name or name of the city. Use adjacency list representation of the graph or use adjacency matrix representation of the graph.
*/
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter No. of cities";
cin>>n;
string cities[n];
int adj[n][n] = {0,0};
for(int i = 0; i<n; i++)
{
cout<<"Enter City Name "<<i<<endl;
cin>>cities[i];
}
for(int i = 0; i<n; i++)
{
for(int j = i+1; j<n; j++)
{
cout<<"Enter Distance Between "<<cities[i]<<" and "<<cities[j]<<endl;
cin>>adj[i][j];
adj[j][i] = adj[i][j];
}
}
//display
cout<<endl;
for(auto i : cities)
{
cout<<"\t"<<i<<"\t";
}
cout<<endl;
for (int i = 0; i < n; i++)
{
cout<<cities[i]<<"\t";
for (int j = 0; j < n; j++)
{
cout<<"\t"<<adj[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}