In: Computer Science
Write a simple airline ticket reservation program. The program
should display
a menu with the following options: reserve a ticket, cancel a
reservation, check whether a ticket is reserved for a particular
person, and display the passengers. The information is maintained
on an alphabetized linked list of names. In a simpler version of
the program, assume that tickets are reserved for only one flight.
In a fuller version, place no limit on the number of flights.
Create a linked list of flights with each node including a pointer
to a linked list of passengers.
PLEASE PROVIDE IN PSEUDOCODE, THANK YOU!
This Program can be compared to Linked List Operations.
Reserve A Ticket --> Insertion In a Sorted Linked List of Strings
Cancel a reservation --> Deletion of a particular node in Linked List.
Check whether a ticket is reserved for a particular person --> Searching in Linked List
Display the passengers --> Display A Linked List
------------------------------------------------------------------------------------------------------------------------------------------------------
Creation of Linked List
DECLARE struct Node
Declare string Name
Declare struct Node *next
END DECLARE
DECLARE struct Node*head
------------------------------------------------------------------------------------------------------------------------------------------------------
Insertion In Sorted Linked List
DECLARE reservation()
//Create a New Node
struct Node* new_node = new_node();
name="Enter Name of passenger"
new_node->name = name
new_node->next = NULL
//Declare a Node for traversal
struct Node* current;
/* Special case for the head end if the name of
passenger is first in ascending order */
if (head == NULL OR (head->name) >=
new_node->name)
new_node->next =
head;
head = new_node;
else
/* Locate the node
before the point of insertion */
current = head;
while (current->next
!= NULL AND current->next->name < new_node->name)
current = current->next;
END WHILE
new_node->next =
current->next;
current->next =
new_node;
END IF
PRINT "THANK YOU, YOUR TICKET HAS BEEN RESERVED"
END DECLARE
------------------------------------------------------------------------------------------------------------------------------------------------------
Deletion of a particular node in Linked List.
DECLARE cancellation()
name="ENTER NAME TO CANCEL RESERVATION"
// Store head node
struct Node* temp = *head_ref, *prev;
// If head node itself holds the name to be
deleted
if (temp != NULL AND temp->name ==
name)
head=
temp->next; // Changed head
delete
temp(); // free old head
return;
END IF
// Search for the Name to be Deleted and keep
track of the
// previous node as we need to change
'prev->next'
while (temp != NULL AND temp->data !=
name)
prev = temp;
temp =
temp->next;
END while
// If key was not present in linked list
if (temp == NULL) return;
END if
// Unlink the node from linked list
prev->next = temp->next;
delete(temp); // Deleting Or Cancel
Reservation
PRINT "YOUR RESERVATION HAS BEEN CANCELLED"
END DECLARE
------------------------------------------------------------------------------------------------------------------------------------------------------
Searching in Linked List
DECLARE check()
name="ENTER NAME OF PASSENGER TO BE
SEARCHED"
struct Node* current = head; // Initialize
current
while (current != NULL)
IF (current->name ==
name)
PRINT "YES,Ticket is Reserved"
END IF
current =
current->next;
END while
PRINT "Sorry, Ticket is Not Reserved"
END DECLARE
-----------------------------------------------------------------------------------------------------------------------------------------------------
Display A Linked List
DECLARE display()
Print "NAME OF PASSENGERs"
while (node != NULL)
PRINT(
node->name)
node =
node->next;
END while
END DECLARE
------------------------------------------------------------------------------------------------------------------------------------------------------
MAIN
DECLARE MAIN()
Print "Hello, WELCOME TO OUR
AIRLINES"
Print "Enter 1 for Ticket
Reservation
Enter 2 for Cancel Reservation
Enter 3 for Check Your Reservation
Enter 4 for Passengers Name List
Initialize choice=-1;
while(choice!=0)
choice="ENTER YOUR CHOICE and 0 to exit"
//Here we can use switch case or if-else
if(choice=1)
CAll Function
reservation()
else if(choice=2)
CAll Function
cancellation()
else if(choice=3)
CAll Function
check()
else if(choice=4)
CAll Function
display()
END if
END while
END DECLARE
------------------------------------------------------------------------------------------------------------------------------------------------------