Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An airline has an algorithm to determine the priority of passengers who are wait

ID: 3571470 • Letter: A

Question

An airline has an algorithm to determine the priority of passengers who are wait-listed for a flight. It calculates a priority key based upon (1) frequent flyer status, (2) price paid for the ticket and (3) arrival time at the gate. The lower the key value, the higher placed the passenger is in the queue. The calculation is as follows:

-          If frequent flyer status is ‘NONE’, add 40 to priority key. If frequent flyer status is ‘SLVR’, add 30 to priority key. If frequent flyer status is ‘GOLD’, add 20 to priority key. If frequent flyer status is ‘PLAT’, do not add anything to priority key.

-          If price paid for the ticket is $500 or more, do not add anything to the priority key.    Otherwise, points are accumulated for every drop in price. Each price range is $49. For every drop between $1 and $49 dollars, add 5 to the priority key. For example, if the ticket price was $310, add 20 points to the priority key.

-          The gate is considered to be open 1 hour prior to the flight. If the passenger is 60 minutes early, no points are added. For each minute closer to the flight time, add 1 point to the priority key.

Example:

                #1 - A GOLD passenger who paid $415 for his ticket arrives 40 minutes prior to departure.

                #2 – A SLVR passenger who paid $525 for his ticket arrives 50 minutes prior to departure.

                                Passenger #1:    The priority key value = 20 +10 + 20 = 50

                                Passenger #2:    The priority key value = 30 + 0 + 10 = 40

                                Passenger #2 has priority ahead of Passenger #1.

In the event 2 passengers are assigned the same key value, they are prioritized in FIFO order.

Create a priority queue using a do-it-yourself doubly linked list (do not use the queue STL). You may treat it as either sorted or unsorted as you choose. However, document your choice at the beginning of the program. Provide for user input of passenger last name, frequent flyer status, price paid and number of minutes prior to departure time arrival.

You may use the following table for the input data or try it with your own data. After all of the passengers have been placed in the queue, remove them in priority sequence and print the associated information used in the determination.

Passenger Last Name

Frequent Flyer Status

Price Paid

Minutes Prior to Departure

Jones

GOLD

$437

30

Smith

PLAT

$385

38

Lee

NONE

$600

58

Harris

SLVR

$486

45

White

GOLD

$451

60

Passenger Last Name

Frequent Flyer Status

Price Paid

Minutes Prior to Departure

Jones

GOLD

$437

30

Smith

PLAT

$385

38

Lee

NONE

$600

58

Harris

SLVR

$486

45

White

GOLD

$451

60

Explanation / Answer


#include <iostream>
#include <string>
using namespace std;

//Declare Passenger Class to store each user attributes
class Passenger {
int priority;
int arrivalTime;
int costOfTicket;
string lName;
string flyStatus;
Passenger* next;
  
//accessor methods
public:
int getTime() { return arrivalTime; }
int getPrice() { return costOfTicket; }
int getPriority(){ return priority; }
Passenger* getNextPassenger() { return next; }
string getLName() { return lName; }
string getStatus() { return flyStatus; }
  
void setTime(int mTime) { arrivalTime = mTime; }
void setPriority(int mPriority) { priority = mPriority; }
void setPrice(int mPrice) { costOfTicket = mPrice; }
void setNext(Passenger* mNext) { next = mNext; }
void setLName(string mLName) { lName = mLName; }
void setStatus(string mStatus) { flyStatus = mStatus; }
};

//Queue
class pQueue {
Passenger* first;
public:
pQueue() { first = NULL; }
void min();
void insert();
void removeMin();
void displayPQ();
void dequeueInOrder();
bool empty() { bool rVal = first == NULL ? true : false; return rVal; }
};

int calculatePriority(int, string, int);

int main() {
pQueue flightList;
cout << "PRIORITY QUEUE TYPE: SORTED ";

while(true){
int answer;
       //prompt the user to enter his/her choice
cout << "OPTIONS: ";
cout << "1) Add New Passenger ('Insert()') ";
cout << "2) Show All Passengers ";
cout << "3) Show Passenger With Top Priority ('min()') ";
cout << "4) Show All Passengers without DELETE ";
cout << "5) Exit Choice:";
cin >> answer;
  
switch (answer) {
case 1: flightList.insert();
break;
case 2: flightList.dequeueInOrder();
break;
case 3: flightList.min();
break;
case 4: flightList.displayPQ();
break;
case 5: exit(EXIT_SUCCESS);
break;
default: cout << "Not an option, sorry. Try again: ";
break;
}
}
}

//Print the first Passenger Details
void pQueue::min(){
Passenger* cPassenger = first;
cout << "Passenger Name: " << cPassenger->getLName() << " ";
cout << "Passenger Priority: " << cPassenger->getPriority() << " STATUS: " << cPassenger->getStatus() << " ";
cout << "Ticket Price: $" << cPassenger->getPrice() << " ";
cout << "Minutes Prior to Departure: " << cPassenger->getTime() << " minutes ";
}


//Remove the first Passenger
void pQueue::removeMin(){
if (empty()){
cout << "Priority Queue empty, nothing to remove... "; return;
} else {
cout << "Removing: " << first->getLName() << " with priority of " << first->getPriority() << "... ";
Passenger* qPassenger = first;
first = first->getNextPassenger();
delete qPassenger;
return;
}
}

//Display All Passengers with details
void pQueue::displayPQ(){
Passenger* cPassenger = first;
  
while(cPassenger != NULL){
cout << " BOARDING: ";
cout << "Passenger Name: " << cPassenger->getLName() << " ";
cout << "Passenger Priority: " << cPassenger->getPriority() << " STATUS: " << cPassenger->getStatus() << " ";
cout << "Ticket Price: $" << cPassenger->getPrice() << " ";
cout << "Minutes Prior to Departure: " << cPassenger->getTime() << " minutes ";
cPassenger = cPassenger->getNextPassenger();
//Passenger* cPassenger = first; || removeMin(); // this is for when were certain that the program runs and we want to board("dequeue") all the passengers in the queue
}
}

//Dequeue
void pQueue::dequeueInOrder(){
Passenger* cPassenger = first;
if( first == NULL){ cout << " Its queue is empty. "; return; }
  
while(cPassenger != NULL){
cout << " BOARDING: ";
cout << "Passenger Name: " << cPassenger->getLName() << " ";
cout << "Passenger Priority: " << cPassenger->getPriority() << " STATUS: " << cPassenger->getStatus() << " ";
cout << "Ticket Price: $" << cPassenger->getPrice() << " ";
cout << "Minutes Prior to Departure: " << cPassenger->getTime() << " minutes ";
cPassenger = cPassenger->getNextPassenger();
removeMin();
}
}

//calculate priority
int calculatePriority(int price, string status, int time){
int priorityTotal = 0;
  
if (status == "NONE") { priorityTotal += 40; cout << "Passenger frequent flyer status is 'NONE'. Adding 40 points to priority. Priority: " << priorityTotal << " "; }
else if(status == "SLVR"){ priorityTotal += 30; cout << "Passenger frequent flyer status is 'SLVR'. Adding 30 points to priority. Priority: " << priorityTotal << " "; }
else if(status == "GOLD"){ priorityTotal += 20; cout << "Passenger frequent flyer status is 'GOLD'. Adding 20 points to priority. Priority: " << priorityTotal << " "; }
else if(status == "PLAT"){ cout << "Passenger frequent flyer status is 'PLAT'. Not adding any 'priority' points. Priority: " << priorityTotal << " "; }
  
if (price < 499){
double ePrice = 500 - price;
while (ePrice >= 0){
cout << ePrice << " - 49 = ";
priorityTotal += 5;
ePrice -= 49;
cout << ePrice << " ";
cout << "New total of " << priorityTotal << " ";
}
cout << " ";
} else { cout << "No priority penalty for ticket price. "; }
  
if (60 > time){
cout << "Adding " << (60 - time) << " a priority point for each minute after gate opens. Total: " << priorityTotal << ". ";
priorityTotal += (60 - time);
} else {
cout << "No penalty for being at least an hour early. Priority Total: " << priorityTotal << " ";
}
return priorityTotal;
}

//Insert new passenger into the queue
void pQueue::insert(){
int minutes, price, nPriority;
Passenger* cPassenger = new Passenger;
string fName, lName, status;
  
//read input details
cout << "Enter Passenger's Last Name: "; cin >> lName;
cout << "Enter Passenger's Frequent Flyer Status: "; cin >> status;
cout << "Enter Passenger's Ticket Price(Enter number without '$'): "; cin >> price;
cout << "Enter how minutes early the passenger is for their flight: "; cin >> minutes;
  
cPassenger->setLName(lName);
cPassenger->setStatus(status);
cPassenger->setPrice(price);
cPassenger->setTime(minutes);
  
//calculate new passenger priority
cout << " Calculating " << fName << " " << lName << "'s flight priority... ";
nPriority = calculatePriority(price, status, minutes);
cout << "Total of " << nPriority << " points. ";
cPassenger->setPriority(nPriority);
  
Passenger* qPassenger = first;
Passenger* prevPassenger = NULL;
  
//insert the new passenger at appropriate position in the queue
if( first == NULL ){
first = cPassenger;
cout << "List is empty. Adding " << fName << " " << lName << " to the top of the list. ";
} else {
if( nPriority < first->getPriority()){
cPassenger->setNext(first);
first = cPassenger;
} else {
while( nPriority >= qPassenger->getPriority() ){
if ( qPassenger->getNextPassenger() != NULL ){
cout << "Passenger " << qPassenger->getLName() << ", with priority "<< qPassenger->getPriority() << ", is higher than " << nPriority << ". ";
prevPassenger = qPassenger;
qPassenger = qPassenger->getNextPassenger();
} else {
break;
}
}
if ( qPassenger->getNextPassenger() == NULL ){
if (nPriority > qPassenger->getPriority()){
qPassenger->setNext(cPassenger);
} else {
prevPassenger->setNext(cPassenger);
cPassenger->setNext(qPassenger);
}
} else if ( qPassenger->getNextPassenger() != NULL ){
if (nPriority > qPassenger->getPriority()){
qPassenger->setNext(cPassenger);
} else {
prevPassenger->setNext(cPassenger);
cPassenger->setNext(qPassenger);
}
}
}
}
}

--------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:

PRIORITY QUEUE TYPE: SORTED
OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:1
Enter Passenger's Last Name: Jones
Enter Passenger's Frequent Flyer Status: GOLD
Enter Passenger's Ticket Price(Enter number without '$'): 437
Enter how minutes early the passenger is for their flight: 30


Calculating Jones's flight priority...
Passenger frequent flyer status is 'GOLD'.
Adding 20 points to priority.
Priority: 20

63 - 49 = 14
New total of 25
14 - 49 = -35
New total of 30

Adding 30 a priority point for each minute after gate opens. Total: 30.
Total of 60 points.

List is empty.
Adding Jones to the top of the list.

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:1
Enter Passenger's Last Name: Smith
Enter Passenger's Frequent Flyer Status: PLAT
Enter Passenger's Ticket Price(Enter number without '$'): 385
Enter how minutes early the passenger is for their flight: 38


Calculating Smith's flight priority...
Passenger frequent flyer status is 'PLAT'.
Not adding any 'priority' points.
Priority: 0

115 - 49 = 66
New total of 5
66 - 49 = 17
New total of 10
17 - 49 = -32
New total of 15

Adding 22 a priority point for each minute after gate opens. Total: 15.
Total of 37 points.

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:1
Enter Passenger's Last Name: Lee
Enter Passenger's Frequent Flyer Status: NONE

Enter Passenger's Ticket Price(Enter number without '$'): 600
Enter how minutes early the passenger is for their flight: 58


Calculating Lee's flight priority...
Passenger frequent flyer status is 'NONE'.
Adding 40 points to priority.
Priority: 40

No priority penalty for ticket price.

Adding 2 a priority point for each minute after gate opens. Total: 40.
Total of 42 points.

Passenger Smith, with priority 37, is higher than 42.

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:1
Enter Passenger's Last Name: Harris
Enter Passenger's Frequent Flyer Status: SLVR
Enter Passenger's Ticket Price(Enter number without '$'): 486
Enter how minutes early the passenger is for their flight: 45


Calculating Harris's flight priority...
Passenger frequent flyer status is 'SLVR'.
Adding 30 points to priority.
Priority: 30

14 - 49 = -35
New total of 35

Adding 15 a priority point for each minute after gate opens. Total: 35.
Total of 50 points.

Passenger Smith, with priority 37, is higher than 50.

Passenger Lee, with priority 42, is higher than 50.

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:1
Enter Passenger's Last Name: White
Enter Passenger's Frequent Flyer Status: GOLD
Enter Passenger's Ticket Price(Enter number without '$'): 451
Enter how minutes early the passenger is for their flight: 60


Calculating White's flight priority...
Passenger frequent flyer status is 'GOLD'.
Adding 20 points to priority.
Priority: 20

49 - 49 = 0
New total of 25
0 - 49 = -49
New total of 30

No penalty for being at least an hour early.
Priority Total: 30
Total of 30 points.

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:2

BOARDING:
Passenger Name: White
Passenger Priority: 30 STATUS: GOLD
Ticket Price: $451
Minutes Prior to Departure: 60 minutes

Removing: White with priority of 30...


BOARDING:
Passenger Name: Smith
Passenger Priority: 37 STATUS: PLAT
Ticket Price: $385
Minutes Prior to Departure: 38 minutes

Removing: Smith with priority of 37...


BOARDING:
Passenger Name: Lee
Passenger Priority: 42 STATUS: NONE
Ticket Price: $600
Minutes Prior to Departure: 58 minutes

Removing: Lee with priority of 42...


BOARDING:
Passenger Name: Harris
Passenger Priority: 50 STATUS: SLVR
Ticket Price: $486
Minutes Prior to Departure: 45 minutes

Removing: Harris with priority of 50...


BOARDING:
Passenger Name: Jones
Passenger Priority: 60 STATUS: GOLD
Ticket Price: $437
Minutes Prior to Departure: 30 minutes

Removing: Jones with priority of 60...

OPTIONS:
1) Add New Passenger ('Insert()')
2) Show All Passengers
3) Show Passenger With Top Priority ('min()')
4) Show All Passengers without DELETE
5) Exit
Choice:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote