-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassg5_Adj_Matrix.cpp
101 lines (59 loc) · 1.09 KB
/
assg5_Adj_Matrix.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<string>
using namespace std;
class Graph
{
int v,e,fuel[10][10],f;
string city[10];
public:
void create();
void display();
}G;
void Graph::create()
{
cout<<"\nEnter the number of cities : ";
cin>>v;
cout<<"\nEnter city name : ";
for(int i=0;i<v;i++){
cin>>city[i];
}
cout<<"\nEnter fuel of edges : ";
for(int i=0;i<v;i++)
{
for(int j=i;j<v;j++){
if(i==j)
{
fuel[i][j]=0;
continue;
}
else
{
cout<<"\nEnter the fuel of edge "<<city[i]<<" to "<<city[j]<<" : ";
cin>>f;
fuel[i][j] = f;
fuel[j][i] = fuel[i][j];
}
}
}
}
void Graph::display()
{
for(int i=0;i<v;i++){
cout<<"\t"<<city[i];
}
cout<<"\n";
for(int i=0;i<v;i++)
{
cout<<city[i];
for(int j=0;j<v;j++){
cout<<"\t"<<fuel[i][j];
}
cout<<"\n";
}
}
int main()
{
G.create();
G.display();
return 0;
}