-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.cpp
More file actions
155 lines (120 loc) · 5.5 KB
/
array.cpp
File metadata and controls
155 lines (120 loc) · 5.5 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
#include "array.hpp"
#include "passenger.hpp"
// kaemon
void reserveSeatArray(int planeIndex, int rowIndex, int columnIndex, Passenger p){
auto start = high_resolution_clock::now();
plane[planeIndex].info[rowIndex][columnIndex] = p;
plane[planeIndex].seat[rowIndex][columnIndex] = true;
plane[planeIndex].occupiedSeats++;
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "\n>>> [ARRAY IMPLEMENTATION RESULTS] <<<\n";
cout << "Status: SUCCESS\n";
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("array");
};
// hao
void cancelSeatArray(int targetID){
auto start = high_resolution_clock::now();
bool found = false;
Passenger removedInfo;
// Search Logic
for (int p = 0; p < max_planes; p++) {
for (int r = 0; r < max_rows; r++) {
for (int c = 0; c < max_cols; c++) {
if (plane[p].seat[r][c] && plane[p].info[r][c].id == targetID) {
removedInfo = plane[p].info[r][c];
// DELETE
plane[p].seat[r][c] = false;
plane[p].info[r][c] = Passenger();
plane[p].occupiedSeats--;
found = true;
goto end_loop;
}
}
}
}
end_loop:;
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "\n>>> [ARRAY IMPLEMENTATION RESULTS] <<<\n";
if (found) {
cout << "Status: SUCCESS\n";
cout << "Passenger: " << removedInfo.name << " (ID: " << targetID << ")\n";
cout << "Flight Info: Plane " << removedInfo.planeNo << " | Seat " << removedInfo.seatRow << indexToColumn(columnToIndex(removedInfo.seatColumn)) << "\n";
} else {
cout << "Status: FAILED (ID Not Found)\n";
}
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("array");
};
// rijesh
void searchSeatArray(int targetID) {
auto start = high_resolution_clock::now();
bool found = false;
Passenger foundInfo;
for (int p = 0; p < planeCount; p++) {
for (int r = 0; r < max_rows; r++) {
for (int c = 0; c < max_cols; c++) {
if (plane[p].seat[r][c] && plane[p].info[r][c].id == targetID) {
foundInfo = plane[p].info[r][c];
found = true;
goto end_loop;
}
}
}
}
end_loop:;
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "\n>>> [ARRAY IMPLEMENTATION RESULTS] <<<\n";
if (found) {
cout << "Status: SUCCESS\n";
cout << "Passenger: " << foundInfo.name << " (ID: " << foundInfo.id << ")\n";
cout << "Flight Info: Plane " << foundInfo.planeNo
<< " | Seat " << (to_string(foundInfo.seatRow) + foundInfo.seatColumn) << "\n";
cout << "Class: " << foundInfo.flightClass << "\n";
} else {
cout << "Status: FAILED (ID Not Found)\n";
}
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("array");
}
// quan
void seatReporArray(){
auto start = high_resolution_clock::now(); // START TIMER
cout << "\n-------------------- ARRAY REPORT ---------------------\n";
cout << left << setw(10) << "Plane" << setw(12) << "ID" << setw(20) << "Name" << setw(10) << "Seat" << "Class" << endl;
cout << "---------------------------------------------------------\n";
int count = 0;
// Loop through ALL Planes
for (int p = 0; p < planeCount; p++) {
for (int r = 0; r < max_rows; r++) {
for (int c = 0; c < max_cols; c++) {
if (plane[p].seat[r][c]) {
cout << left
<< setw(10) << (p + 1)
<< setw(12) << plane[p].info[r][c].id
<< setw(20) << plane[p].info[r][c].name.substr(0, 19) // Crop long names
<< setw(10) << (to_string(r + 1) + indexToColumn(c))
<< plane[p].info[r][c].flightClass << endl;
count++;
}
}
}
}
if (count == 0) cout << "No passengers found.\n";
auto stop = high_resolution_clock::now();
int totalCapacity = planeCount * max_rows * max_cols;
int emptySeats = totalCapacity - count;
cout << "--------------------------------------------------------------" << endl;
cout << " > Total Seats: " << totalCapacity << " seats" << endl;
cout << " > Occupied Seats: " << count << endl;
cout << " > Empty Seats: " << emptySeats << endl;
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "--------------------------------------------------------------" << endl;
cout << " >>> [Array Seat Report Performance] <<<" << endl;
cout << "--------------------------------------------------------------" << endl;
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("array");
};