forked from shlokshah/ROS1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanding.cpp
More file actions
166 lines (155 loc) · 3.37 KB
/
Copy pathLanding.cpp
File metadata and controls
166 lines (155 loc) · 3.37 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
void bubbleSort();
void VIPPlanes();
void midWayRefuel();
void LockRunway();
void UnlockRunway();
void LandPlane(int);
bool runwayfree=true;
int countOfIndex=0;
struct plane
{
string name;
int index;
int fuel;
int passengers;
int staff_present;
int staff_required; //Total requirement for it to be able to fly
bool priority=false;
};
int staff_available=3; //staff available on the ground ready to fly
int n;
struct plane a[10];
int landingList[10];
int refuelingList[10];
int semaphore=0;
void enterdetails()
{
srand (time(0));
cout<<"Enter number of planes arriving at the Airport: ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Enter plane name for plane "<<i+1<<": ";
cin>>a[i].name;
cout<<" Enter number of passengers in plane "<<a[i].name<<": ";
cin>>a[i].passengers;
char priority_choice;
cout<<" Is it a VIP plane?(y/n): ";
cin>>priority_choice;
if(priority_choice=='y'||priority_choice=='Y')
{
a[i].priority=true;
}
else if(priority_choice=='n'||priority_choice=='N')
{
a[i].priority=false;
}
else
{
cout<<"Invalid Input";
}
a[i].fuel=(rand() % 100 + 50)%100;
cout<<" Fuel in Plane "<<a[i].name<<": "<<a[i].fuel;
a[i].staff_present=rand() % 10 + 3;
cout<<endl<<" Staff present in plane "<<a[i].name<<" is: "<<a[i].staff_present<<"\n";
a[i].index=countOfIndex;
countOfIndex++;
}
}
int findSmallestElement()
{
int temp = 0;
for(int i=0; i<n; i++) {
if(a[temp].fuel>a[i].fuel) {
temp=i;
}
}
return temp;
}
int flag=0;
void swaps(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
int main()
{
for(int i=0;i<n;i++)
{
landingList[i]=a[i].index;
}
enterdetails();
bubbleSort();
VIPPlanes();
midWayRefuel();
LandPlane(2);
LockRunway();
LandPlane(0);
UnlockRunway();
LandPlane(1);
}
void bubbleSort()
{
int i,j;
for (i=0;i<n-1;i++)
for (j=0;j<n-i-1;j++)
if (a[j].fuel>a[j+1].fuel)
swaps(&a[j].index, &a[j+1].index);
}
void VIPPlanes()
{
int counter=0;
for(int i=0;i<n;i++)
{
if(a[i].priority==true)
{
swaps(&a[i].index, &a[counter].index);
counter++;
}
}
}
void midWayRefuel()
{
for(int i=0;i<n;i++)
{
if(a[i].fuel<10*i)
{
cout<<"Plane needs mid-air refueling: "<<a[i].name<<endl;
a[i].fuel+=100;
}
}
}
void LockRunway()
{
if(semaphore==0)
{
cout<<"Locking runway."<<endl;
cout<<"Runway Locked."<<endl;
semaphore=1;
}
else
cout<<"Runway already locked."<<endl;
}
void UnlockRunway()
{
if(semaphore==1)
{
cout<<"Unlocking runway."<<endl;
cout<<"Runway unlocked successfully."<<endl;
semaphore=0;
}
else
cout<<"Runway already unlocked."<<endl;
}
void LandPlane(int index)
{
LockRunway();
cout<<"Plane "<<a[index].name<<" has landed successfully!"<<endl;
UnlockRunway();
}