Airline Management System with Double link list in c++

Airline Management System with Double link list in c++


 #include<iostream>

#include<string>

#include<ctype.h>

#include<cstring>

using namespace std;

struct Person{

	string name;

	int age;

	string cnic;

	int TicketNo;

	string FlightNo;

};

struct Cust{

	Person obj;

	Cust *next;

	Cust *pre;

};

Cust *firstC = NULL;

Cust *lastC = NULL;

struct Flight{

	Cust *head;

	Flight *next;

	Flight *pre;

	string name;

	void ReserveFromF()

	{

		system("cls");

		Cust *newNode = new Cust;

		cout << "Enter the name of the customer:";

		getline(cin, newNode->obj.name);

		cout << "Enter the CNIC number:";

		getline(cin, newNode->obj.cnic);

		cout << "Enter the flight number:";

		getline(cin, newNode->obj.FlightNo);

		cout << "Enter the Age of the customer(int):";

		cin >> newNode->obj.age;

		cout << "Enter the Ticket Number(int):";

		cin >> newNode->obj.TicketNo;

		cin.ignore();

		if (firstC == NULL)

		{

			newNode->next = newNode->pre = NULL;

			firstC = lastC = newNode;

		}

		else

		{

			newNode->next = firstC;

			newNode->pre = NULL;

			firstC->pre = newNode;

			firstC = newNode;

		}

	}

	void ReserveFromL()

	{

		system("cls");

		Cust *newNode = new Cust;

		cout << "Enter the name of the customer:";

		getline(cin, newNode->obj.name);

		cout << "Enter the CNIC number:";

		getline(cin, newNode->obj.cnic);

		cout << "Enter the flight number:";

		getline(cin, newNode->obj.FlightNo);

		cout << "Enter the Age of the customer(int):";

		cin >> newNode->obj.age;

		cout << "Enter the Ticket Number(int):";

		cin >> newNode->obj.TicketNo;

		cin.ignore();

		if (lastC == NULL)

		{

			newNode->next = newNode->pre = NULL;

			firstC = lastC = newNode;

		}

		else

		{

			newNode->pre = lastC;

			newNode->next = NULL;

			lastC->next = newNode;

			lastC = newNode;

		}

	}

	void Cancel(int Tick)

	{

		if (firstC == NULL)

		{

			cout << "                               There is no Data" << endl;

			system("pause");

			return;

		}

		Cust *temp = firstC;

		Cust *nxt = firstC->next;

		Cust *p = lastC;

		int count = 0;

		if (temp->obj.TicketNo==Tick)

		{



			if (nxt== NULL)

			{

				firstC=lastC = NULL;

				delete(temp);

				cout << "                   Ticket Cancel Sucssesfully" << endl;

				system("pause");

			}

			else

			{

				firstC = nxt;

				nxt->pre = NULL;

				delete(temp);

				cout << "                   Ticket Cancell Sucsessfully" << endl;

				system("pause");

			}

			

		}

		else

		{

			while (nxt->obj.TicketNo != Tick)

			{

				if (nxt->next == NULL)

				{

					nxt = nxt->next;

					break;

				}

				temp = temp->next;

				nxt = nxt->next;

			}

			if (nxt == NULL)

			{

				cout << "                              Element Not found" << endl;

				system("pause");

				return;

			}

			else if (temp->next->next==NULL)

			{

				temp->next = NULL;

				lastC = temp;

				delete(nxt);

				cout << "                           Element Deleted Successfully" << endl;

				system("pause");

			}

			else if (nxt->obj.TicketNo == Tick)

			{

				temp->next = nxt->next;

				nxt->next->pre = temp;

				delete(nxt);

				cout << "                         Element Deleted Successfully" << endl;

				system("pause");

			}

			else

			{

				cout << "                         Element Not Found" << endl;

				system("pause");

			}



		}

	}

	void Check(int T)

	{

		Cust *temp = firstC; int n, count = 0;

		while (temp != NULL)

		{

			if (temp->obj.TicketNo == T)

			{

				cout << "This Ticket is available" << endl << endl;

				system("pause");

				cout << "If you want to to see the data of the ticket than press 1:";

				cin >> n; cin.ignore();

				if (n == 1)

				{

					cout << "Name of the Customer is:" << temp->obj.name << endl;

					cout << "Age of the Customer is:" << temp->obj.age << endl;

					cout << "Ticket No of the customer is:" << temp->obj.TicketNo << endl;

					cout << "CNIC of the customer is:" << temp->obj.cnic << endl;

					cout << "Fligt number of the customer is:" << temp->obj.FlightNo << endl;

					system("pause");

				}

				count++;

			}

			temp = temp->next;

		}

		if (count == 0)

		{

			cout << "                                 Ticket Not found" << endl;

			system("pause");

		}

	}

	void DisplayfromF()

	{

		Cust *temp = firstC; int count = 0;

		system("cls");

		while (temp != NULL)

		{

			cout << "Name of the Customer is:" << temp->obj.name << endl;

			cout << "Age of the Customer is:" << temp->obj.age << endl;

			cout << "Ticket No of the customer is:" << temp->obj.TicketNo << endl;

			cout << "CNIC of the customer is:" << temp->obj.cnic << endl;

			cout << "Fligt number of the customer is:" << temp->obj.FlightNo << endl;

			system("pause");

			cout << endl << endl;

			count++;

			temp = temp->next;

		}

		if (count == 0)

		{

			cout << "This airplan has no Ticket Reserved" << endl;

			system("pause");

		}

		

	}

	void DisplayfromL()

	{

		Cust *temp = lastC; int count = 0;

		system("cls");

		while (temp != NULL)

		{

			cout << "Name of the Customer is:" << temp->obj.name << endl;

			cout << "Age of the Customer is:" << temp->obj.age << endl;

			cout << "Ticket No of the customer is:" << temp->obj.TicketNo << endl;

			cout << "CNIC of the customer is:" << temp->obj.cnic << endl;

			cout << "Fligt number of the customer is:" << temp->obj.FlightNo << endl;

			system("pause");

			cout << endl << endl;

			count++;

			temp = temp->pre;

		}

		if (count == 0)

		{

			cout << "                      This airplan has no Ticket Reserved" << endl;

			system("pause");

		}

	}

	void Alphabetalized()

	{

		Cust *temp = firstC;

		Cust *nxt = firstC->next;

		int count = 0;

		while (nxt != NULL)

		{

			while (temp != NULL)

			{

				if (toupper(temp->obj.name > nxt->obj.name))

				{

					swap(nxt->obj.name, temp->obj.name);

					swap(nxt->obj.age, temp->obj.age);

					swap(nxt->obj.cnic, temp->obj.cnic);

					swap(nxt->obj.FlightNo, temp->obj.FlightNo);

					swap(nxt->obj.TicketNo, temp->obj.TicketNo);

					count++;

				}

				temp = temp->next;

			}

			temp = firstC;

			nxt = nxt->next;

		}

		if (count == 0)

		{

			cout << endl << endl;

			cout << "Tickets are already Sorted Alphabetically" << endl;

			cout << "Please Display the Data To Check it" << endl;

			system("pause");

		}

		else

		{

			cout << endl << endl;

			cout << "Tickets Sorted Successfully!!!!!" << endl;

			cout << "Please Display the Data to check the alphabetical Order" << endl;

			system("pause");

		}

	}



};

Flight *first=NULL;

Flight *last = NULL;

Flight *ReserveFlight(string n)

{

	Flight *newNode = new Flight;

	newNode->name = n;

	if (first == NULL)

	{

		newNode->next = newNode->pre = NULL;

		first = last = newNode;

	}

	else

	{

		newNode->next = first;

		newNode->pre = NULL;

		first->pre = newNode;

		first = newNode;

	}

	cout << endl << endl;

	cout << "                                Fligt is Reserved Successfully" << endl;

	system("pause");

	return newNode;

}

int main()

{

	string N;

	cout << "Enter the name of flight to Reserve it:";

	getline(cin, N);

	Flight *f1 = new Flight;

	f1=ReserveFlight(N);

	int n=0;

	while (n != 8)

	{

		system("cls");

		cout << endl << endl;

		cout << "Enter 1 to Reserve the Seat(from front Seats)" << endl << endl;

		cout << "Enter 2 to Reserve the Seat(from End Seats)" << endl << endl;

		cout << "Press 3 to Cancel the Ticket" << endl << endl;

		cout << "Press 4 to Display the Data(from front)" << endl << endl;

		cout << "Press 5 to Display the data(from last)" << endl << endl;

		cout << "Press 6 to check the Ticket" << endl << endl;

		cout << "Press 7 to Sort Tickets Alphabetalized" << endl << endl;

		cout << "Press 8 to Close the program" << endl << endl;

		cin >> n; cin.ignore();

		switch (n)

		{

		case 1:

		{

				  f1->ReserveFromF();

				  break;

		}

		case 2:

		{

				  f1->ReserveFromL();

				  break;

		}

		case 3:

		{

				  int TN;

				  cout << "Enter the Ticket number to Cancel the Ticket:";

				  cin >> TN; cin.ignore();

				  f1->Cancel(TN);

				  break;

		}

		case 4:

		{

				  f1->DisplayfromF();

				  break;

		}

		case 5:

		{

				  f1->DisplayfromL();

				  break;

		}

		case 6:

		{

				  int TN;

				  cout << "Enter the Ticket number to check the Ticket:";

				  cin >> TN; cin.ignore();

				  f1->Check(TN);

				  break;

		}

		case 7:

		{

				  f1->Alphabetalized();

				  break;

		}

		case 8:

		{

				  cout << "Thank you so much for our Services" << endl;

				  system("pause");

				  break;

		}

		default:

			cout << "This Option Not found" << endl;

			system("pause");

			break;

		}

	}

	getchar();

	getchar();

	return 0;

}     

          

       
 

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........