-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflight2.cpp
More file actions
99 lines (81 loc) · 2.34 KB
/
flight2.cpp
File metadata and controls
99 lines (81 loc) · 2.34 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
#include<string.h>
using namespace std;
const int maxcity=50;
struct Node{
int time;
char city[50];
Node*next;
};
class flight{
Node*list[maxcity];
char cities[maxcity][50];
int numc;
public:
flight(){
numc=0;
for(int i=0;i<maxcity;i++){
list[i]=NULL;
}
}
void addcity(){
cout<<"enter a number of cities:";
cin>>numc;
cin.ignore();
cout<<"enter a name of cities:";
for(int i=0;i<numc;i++){
cin.getline(cities[i],50);
}
for(int i=0;i<numc;i++){
for(int j=0;j<numc;j++){
if(i==j)continue;
char ch;
cout<<"flight is present between"<<" "<<cities[i]<<" " <<"and"<<" "<<cities[j]<<" "<<"if yes or not(y/n)";
cin>>ch;
if(ch=='y'){
int time;
cout<<"enter a time required for going to:"<<" "<<cities[i]<<" "<<"to"<<" "<<cities[j]<<endl;
cin>>time;
Node *newNode=new Node;
newNode->time=time;
strcpy(newNode->city,cities[j]);
newNode->next=list[i];
list[i]=newNode;
}
}
}
}
void display(){
cout<<"flight from source to destination:";
for(int i=0;i<numc;i++){
cout<<cities[i]<<"->";
Node* temp = list[i];
while (temp) {
cout << temp->city << " (" << temp->time << " min) -> ";
temp = temp->next;
}
}
}
};
int main() {
int choice;
flight flightGraph;
do {
cout << "1. enter flight routes\n";
cout << "2. display flight connections\n";
cout << "enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
flightGraph.addcity();
break;
case 2:
flightGraph.display();
break;
default:
cout << "Invalid choice:";
break;
}
}while(choice!=3);
return 0;
}