question archive Course: Data Structure and Algorithm Language: C++ Topic: Implementation of Doubly Linked List Write a simple airline ticket reservation system program
Subject:Computer SciencePrice: Bought3
Course: Data Structure and Algorithm
Language: C++
Topic: Implementation of Doubly Linked List
Write a simple airline ticket reservation system program.
The program should display a menu with 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 alphabetized link 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 link list of flights with each node including a pointer to a link list of passengers.
For above Question, Code is given below in Singly Linked List, But I want to convert this code in doubly linked List. Please do this.
NOTE: "It is a complete question. Graph, link or other material etc. are not used and required. I will very Thankful to you if you convert this code in Doubly Linked List."
#include<iostream>
#include<string>
using namespace std;
class Passenger
{
public:
string Pessenger_Name;
string Flight_Name;
Passenger *next_val;
Passenger(const string a, string b, Passenger* p = NULL)
{
this->Pessenger_Name = a;
this->Flight_Name = b;
this->next_val = p;
}
};
class classTicket
{
private:
Passenger *headval, *tailval;
public:
classTicket();
~classTicket();
void Ticket_reservation();
void cancel_Ticket();
void check_Ticket();
void display();
};
classTicket::classTicket()
{
headval = tailval = NULL;
}
classTicket::~classTicket()
{
Passenger* P1 = headval, *q1 = headval;
while (P1 != NULL)
{
q1 = headval->nextval;
delete P1;
P1 = q1;
}
}
void classTicket::Ticket_reservation()
{
string Pessenger_Name, Flight_Name;
cout << "passenger name?" << endl;
cin >> Pessenger_Name;
cout << "flight name?" << endl;
cin >> Flight_Name;
if (headval == NULL)
{
headval = tailval = new Passenger(Pessenger_Name, Flight_Name);
cout << "ticket reserved" << endl;
return;
}
else
{
Passenger *P1 = headval;
while (P1->next_val)
{
if (Pessenger_Name < P1->Pessenger_Name)
break;
else
P1 = P1->next_val;
}
P1->next_val = new Passenger(Pessenger_Name, Flight_Name, P1->next_val);
cout << "" << endl;
return;
}
}
void classTicket::cancel_Ticket()
{
string Pessenger_Name, Flight_Name;
cout << "passenger name?" << endl;
cin >> Pessenger_Name;
cout << "flight name?" << endl;
cin >> Flight_Name;
Passenger *P1 = headval, *q1 = headval;
if ((Pessenger_Name == Pessenger_Name) && (P1->Flight_Name == Flight_Name))
{
headval = headval->next_val;
cout << "ticket cancelled" << endl;
delete P1;
return;
}
P1 = headval->next_val;
while (P1)
{
if ((P1->Pessenger_Name == Pessenger_Name) && (P1->Flight_Name == Flight_Name))
{
q1->next_val = P1->next_val;
delete P1;
cout << "could not cancelled the ticket?" << endl;
return;
}
else
{
q1 = P1;
P1 = P1->next_val;
}
}
cout << "" << endl;
return;
}
void classTicket::check_Ticket()
{
string Pessenger_Name;
cout << "passenger name" << endl;
cin >> Pessenger_Name;
Passenger* P1 = headval;
while (P1 != NULL)
{
if (P1->Pessenger_Name == Pessenger_Name)
{
cout << "passenger name?" << P1->Pessenger_Name << endl;
cout << " flight name" << P1->Flight_Name << endl;
return;
}
else
P1 = P1->next_val;
}
cout << "ticket checked" << endl;
return;
}
void classTicket::display()
{
Passenger* P1 = headval;
while (P1 != NULL)
{
cout << "display the passenger" << P1->Pessenger_Name << endl;
cout << " Flight Name:" << P1->Flight_Name << endl;
P1 = P1->next_val;
}
}
int main()
{
classTicket t1;
while (true)
{
cout << "airline ticket reservation" << endl;
cout << "enter the choice" << endl;
cout << "1.For Ticket_reservation" << endl;
cout << "2.For cancel ticket" << endl;
cout << "3.For check ticket" << endl;
cout << "4.For display ticket" << endl;
cout << "5.For end program" << endl;
cout << endl;
int f;
cin >> f;
switch (f)
{
case 1:
t1.Ticket_reservation();
break;
case 2:
t1.cancel_Ticket();
break;
case 3:
t1.check_Ticket();
break;
case 4:
t1.display();
break;
case 5:
return 0;
default:
cout << "end" << endl;
break;
}
}
return 0;
}
